refactor: add soop live record

This commit is contained in:
ihmily 2024-10-16 18:24:17 +08:00
parent d3143108c1
commit 23e4eb23e4
4 changed files with 44 additions and 32 deletions

View File

@ -67,15 +67,16 @@
├── utils.py -> (contains utility functions)
├── logger.py -> (logger handdle)
├── room.py -> (get room info)
├── msg_push.py -> (send live status update message)
├── x-bogus.js -> (get douyin xbogus token)
├── /javascript -> (some decrypt code)
├── main.py -> (main file)
├── demo.py -> (call package test demo)
├── msg_push.py -> (send live status update message)
├── ffmpeg.exe -> (record video)
├── index.html -> (play m3u8 and flv video)
├── requirements.txt -> (library dependencies)
├── docker-compose.yaml -> (Container Orchestration File)
├── Dockerfile -> (Application Build Recipe)
├── StopRecording.vbs -> (stop recording script on Windows)
...
```
@ -139,7 +140,8 @@ https://www.bigo.tv/cn/716418802
buled直播
https://app.blued.cn/live?id=Mp6G2R
AfreecaTV
SOOP[AfreecaTV]
https://play.sooplive.co.kr/sw7love
https://play.afreecatv.com/sw7love
网易cc
@ -338,6 +340,8 @@ docker-compose stop
[![justdoiting](https://github.com/justdoiting.png?size=50)](https://github.com/justdoiting)
[![dhbxs](https://github.com/dhbxs.png?size=50)](https://github.com/dhbxs)
[![wujiyu115](https://github.com/wujiyu115.png?size=50)](https://github.com/wujiyu115)
[![zhanghao333](https://github.com/zhanghao333.png?size=50)](https://github.com/zhanghao333)
<a href="https://github.com/gyc0123" target="_blank"><img src="https://github.com/gyc0123.png?size=50" alt="gyc0123" style="width:53px; height:51px;" /></a>
&emsp;
## ⏳提交日志

View File

@ -48,6 +48,10 @@ LIVE_STREAM_CONFIG = {
"url": "https://play.afreecatv.com/sw7love",
"func": spider.get_afreecatv_stream_data,
},
"soop": {
"url": "https://play.sooplive.co.kr/sw7love",
"func": spider.get_afreecatv_stream_data,
},
"netease": {
"url": "https://cc.163.com/583946984",
"func": spider.get_netease_stream_data,

View File

@ -845,13 +845,13 @@ def get_blued_stream_url(url: str, proxy_addr: Union[str, None] = None, cookies:
@trace_error_decorator
def login_afreecatv(username: str, password: str, proxy_addr: Union[str, None] = None) -> Union[str, None]:
if len(username) < 6 or len(password) < 10:
raise RuntimeError('AfreecaTV登录失败请在config.ini配置文件中填写正确的AfreecaTV平台的账号和密码')
raise RuntimeError('SOOP[AfreecaTV]登录失败请在config.ini配置文件中填写正确的SOOP[AfreecaTV]平台的账号和密码')
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Referer': 'https://login.afreecatv.com/afreeca/login.php?szFrom=full&request_uri=https%3A%2F%2Fwww.afreecatv.com%2F',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://play.sooplive.co.kr',
'Referer': 'https://play.sooplive.co.kr/superbsw123/277837074',
}
data = {
@ -860,12 +860,12 @@ def login_afreecatv(username: str, password: str, proxy_addr: Union[str, None] =
'szUid': username,
'szPassword': password,
'isSaveId': 'true',
'szScriptVar': 'oLoginRet',
'szAction': '',
'isSavePw': 'true',
'isSaveJoin': 'true',
'isLoginRetain': 'Y',
}
url = 'https://login.afreecatv.com/app/LoginAction.php?callback=jQuery17208926278503069585_1707311376418'
url = 'https://login.sooplive.co.kr/app/LoginAction.php'
try:
if proxy_addr:
proxies = {
@ -887,7 +887,7 @@ def login_afreecatv(username: str, password: str, proxy_addr: Union[str, None] =
cookie = dict_to_cookie_str(cookie_dict)
return cookie
except Exception:
raise Exception('AfreecaTV登录失败,请检查配置文件中的账号密码是否正确')
raise Exception('SOOP[AfreecaTV]登录失败,请检查配置文件中的账号密码是否正确')
@trace_error_decorator
@ -896,7 +896,8 @@ def get_afreecatv_cdn_url(broad_no: str, proxy_addr: Union[str, None] = None, co
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Referer': 'https://play.afreecatv.com/oul282/249469582',
'Origin': 'https://play.sooplive.co.kr',
'Referer': 'https://play.sooplive.co.kr/oul282/249469582',
'Content-Type': 'application/x-www-form-urlencoded',
}
if cookies:
@ -905,12 +906,12 @@ def get_afreecatv_cdn_url(broad_no: str, proxy_addr: Union[str, None] = None, co
params = {
'return_type': 'gcp_cdn',
'use_cors': 'false',
'cors_origin_url': 'play.afreecatv.com',
'cors_origin_url': 'play.sooplive.co.kr',
'broad_key': f'{broad_no}-common-master-hls',
'time': '8361.086329376785',
}
url2 = 'http://livestream-manager.afreecatv.com/broad_stream_assign.html?' + urllib.parse.urlencode(params)
url2 = 'http://livestream-manager.sooplive.co.kr/broad_stream_assign.html?' + urllib.parse.urlencode(params)
json_str = get_req(url=url2, proxy_addr=proxy_addr, headers=headers, abroad=True)
json_data = json.loads(json_str)
@ -922,8 +923,8 @@ def get_afreecatv_tk(url: str, rtype: str, proxy_addr: Union[str, None] = None,
Union[str, tuple, None]:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Referer': 'https://play.afreecatv.com/secretx/250989857',
'Origin': 'https://play.sooplive.co.kr',
'Referer': 'https://play.sooplive.co.kr/secretx/250989857',
'Content-Type': 'application/x-www-form-urlencoded',
}
@ -945,9 +946,10 @@ def get_afreecatv_tk(url: str, rtype: str, proxy_addr: Union[str, None] = None,
'quality': 'master',
'mode': 'landing',
'from_api': '0',
'is_revive': 'false',
}
url2 = f'https://live.afreecatv.com/afreeca/player_live_api.php?bjid={bj_id}'
url2 = f'https://live.sooplive.co.kr/afreeca/player_live_api.php?bjid={bj_id}'
json_str = get_req(url=url2, proxy_addr=proxy_addr, headers=headers, data=data, abroad=True)
json_data = json.loads(json_str)
@ -968,7 +970,7 @@ def get_afreecatv_stream_data(
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Referer': 'https://m.afreecatv.com/',
'Referer': 'https://m.sooplive.co.kr/',
'Content-Type': 'application/x-www-form-urlencoded',
}
if cookies:
@ -986,7 +988,7 @@ def get_afreecatv_stream_data(
'mode': 'live',
}
url2 = 'http://api.m.afreecatv.com/broad/a/watch'
url2 = 'http://api.m.sooplive.co.kr/broad/a/watch'
json_str = get_req(url=url2, proxy_addr=proxy_addr, headers=headers, data=data, abroad=True)
json_data = json.loads(json_str)
@ -1019,7 +1021,7 @@ def get_afreecatv_stream_data(
def handle_login():
cookie = login_afreecatv(username, password, proxy_addr=proxy_addr)
if 'PdboxBbs=' in cookie:
print('AfreecaTV平台登录成功开始获取直播数据...')
print('SOOP[AfreecaTV]平台登录成功!开始获取直播数据...')
return cookie
def fetch_data(cookie):
@ -1035,25 +1037,25 @@ def get_afreecatv_stream_data(
return result
if json_data['data']['code'] == -3001:
print("AfreecaTV直播获取失败[直播刚结束]:", json_data['data']['message'])
print("SOOP[AfreecaTV]直播获取失败[直播刚结束]:", json_data['data']['message'])
return result
elif json_data['data']['code'] == -3002:
print("AfreecaTV直播获取失败[未登录]: 19+", json_data['data']['message'])
print("正在尝试使用您的账号和密码登录AfreecaTV直播平台请确保已配置")
print("SOOP[AfreecaTV]直播获取失败[未登录]: 19+", json_data['data']['message'])
print("正在尝试使用您的账号和密码登录SOOP[AfreecaTV]直播平台,请确保已配置")
new_cookie = handle_login()
if new_cookie and len(new_cookie) > 0:
return fetch_data(new_cookie)
raise RuntimeError('AfreecaTV登录失败请检查账号和密码是否正确')
raise RuntimeError('SOOP[AfreecaTV]登录失败,请检查账号和密码是否正确')
elif json_data['data']['code'] == -3004:
# print("AfreecaTV直播获取失败[未认证]:", json_data['data']['message'])
if cookies and len(cookies) > 0:
return fetch_data(cookies)
else:
raise RuntimeError('AfreecaTV登录失败请检查账号和密码是否正确')
raise RuntimeError('SOOP[AfreecaTV]登录失败,请检查账号和密码是否正确')
elif json_data['data']['code'] == -6001:
print(f"错误信息:{json_data['data']['message']}请检查输入的直播间地址是否正确")
print(f"错误信息:{json_data['data']['message']}请检查输入的SOOP[AfreecaTV]直播间地址是否正确")
return result
if json_data['result'] == 1 and anchor_name:
broad_no = json_data['data']['broad_no']

16
main.py
View File

@ -38,7 +38,7 @@ from msg_push import (
version = "v3.0.9"
platforms = ("\n国内站点:抖音|快手|虎牙|斗鱼|YY|B站|小红书|bigo|blued|网易CC|千度热播|猫耳FM|Look|TwitCasting|百度|微博|"
"酷狗|花椒|流星|Acfun|时光|映客|音播|知乎|嗨秀|VV星球"
"\n海外站点TikTok|AfreecaTV|PandaTV|WinkTV|FlexTV|PopkonTV|TwitchTV|LiveMe|ShowRoom|CHZZK")
"\n海外站点TikTok|SOOP[AfreecaTV]|PandaTV|WinkTV|FlexTV|PopkonTV|TwitchTV|LiveMe|ShowRoom|CHZZK")
recording = set()
error_count = 0
@ -476,8 +476,8 @@ def start_record(url_data: tuple, count_variable: int = -1):
port_info = spider.get_blued_stream_url(
record_url, proxy_addr=proxy_address, cookies=blued_cookie)
elif record_url.find("afreecatv.com/") > -1:
platform = 'AfreecaTV'
elif record_url.find("afreecatv.com/") > -1 or record_url.find("sooplive.co.kr/") > -1:
platform = 'SOOP[AfreecaTV]'
with semaphore:
if global_proxy or proxy_address:
json_data = spider.get_afreecatv_stream_data(
@ -490,7 +490,7 @@ def start_record(url_data: tuple, count_variable: int = -1):
update_config(config_file, 'Cookie', 'afreecatv_cookie', json_data['new_cookies'])
port_info = stream.get_stream_url(json_data, record_quality, spec=True)
else:
logger.error("错误信息: 网络异常,请检查本网络是否能正常访问AfreecaTV平台")
logger.error("错误信息: 网络异常,请检查本网络是否能正常访问SOOP[AfreecaTV]平台")
elif record_url.find("cc.163.com/") > -1:
platform = '网易CC直播'
@ -828,7 +828,7 @@ def start_record(url_data: tuple, count_variable: int = -1):
"-loglevel", "error",
"-hide_banner",
"-user_agent", user_agent,
"-protocol_whitelist", "rtmp,crypto,file,http,https,tcp,tls,udp,rtp",
"-protocol_whitelist", "rtmp,crypto,file,http,https,tcp,tls,udp,rtp,httpproxy",
"-thread_queue_size", "1024",
"-analyzeduration", analyzeduration,
"-probesize", probesize,
@ -1366,7 +1366,7 @@ while True:
bash_path = read_config_value(config, '录制设置', 'bash脚本路径', "") if is_run_bash else None
enable_proxy_platform = read_config_value(
config, '录制设置', '使用代理录制的平台(逗号分隔)',
'tiktok, afreecatv, pandalive, winktv, flextv, popkontv, twitch, liveme, showroom, chzzk')
'tiktok, afreecatv, soop, pandalive, winktv, flextv, popkontv, twitch, liveme, showroom, chzzk')
enable_proxy_platform_list = enable_proxy_platform.replace('', ',').split(',') if enable_proxy_platform else None
extra_enable_proxy = read_config_value(config, '录制设置', '额外使用代理录制的平台(逗号分隔)', '')
extra_enable_proxy_platform_list = extra_enable_proxy.replace('', ',').split(',') if extra_enable_proxy else None
@ -1531,6 +1531,8 @@ while True:
'www.tiktok.com',
'play.afreecatv.com',
'm.afreecatv.com',
'play.sooplive.co.kr',
'm.sooplive.co.kr',
'www.pandalive.co.kr',
'www.winktv.co.kr',
'www.flextv.co.kr',
@ -1565,8 +1567,8 @@ while True:
new_line = (quality, url, name)
url_tuples_list.append(new_line)
else:
print(f"\r{origin_line} 本行包含未知链接.此条跳过")
if not origin_line.startswith('#'):
print(f"\r{origin_line} 本行包含未知链接.此条跳过")
update_file(url_config_file, url, url, start_str='#')
while len(need_update_line_list):