mirror of
https://github.com/ihmily/DouyinLiveRecorder.git
synced 2025-12-26 05:48:32 +08:00
Add YY live record
This commit is contained in:
parent
1b11ceeb30
commit
afa6e9c120
50
main.py
50
main.py
@ -4,7 +4,7 @@
|
||||
Author: Hmily
|
||||
Github: https://github.com/ihmily
|
||||
Date: 2023-07-17 23:52:05
|
||||
Update: 2023-08-08 16:28:00
|
||||
Update: 2023-08-12 02:42:52
|
||||
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
||||
Function: Record live stream video.
|
||||
"""
|
||||
@ -25,8 +25,8 @@ from spider import *
|
||||
from web_rid import *
|
||||
|
||||
# 版本号
|
||||
version = "v1.0.2"
|
||||
platforms = "抖音|Tiktok|快手|虎牙|斗鱼"
|
||||
version = "v1.0.3"
|
||||
platforms = "抖音|Tiktok|快手|虎牙|斗鱼|YY"
|
||||
|
||||
# --------------------------log日志-------------------------------------
|
||||
# 创建一个logger
|
||||
@ -233,13 +233,12 @@ def change_max_connect():
|
||||
|
||||
|
||||
def get_douyin_stream_url(json_data):
|
||||
# TODO: 获取直播源地址
|
||||
# TODO: 获取抖音直播源地址
|
||||
data = [] # 定义一个返回数据列表
|
||||
|
||||
room_store = json_data['app']['initialState']['roomStore']
|
||||
room_info = room_store['roomInfo']
|
||||
anchor_name = room_info['anchor']['nickname']
|
||||
data.append(anchor_name)
|
||||
status = 4
|
||||
# 获取直播间状态
|
||||
if 'room' in room_info:
|
||||
@ -274,11 +273,10 @@ def get_douyin_stream_url(json_data):
|
||||
|
||||
def get_tiktok_stream_url(json_data):
|
||||
# TODO: 获取Tiktok直播源地址
|
||||
data = [] # 定义一个返回数据列表
|
||||
data = []
|
||||
|
||||
live_room = json_data['LiveRoom']['liveRoomUserInfo']
|
||||
anchor_name = live_room['user']['nickname']
|
||||
data.append(anchor_name)
|
||||
status = live_room['user']["status"]
|
||||
# 直播状态2是正在直播.4是未开播
|
||||
if status == 4:
|
||||
@ -310,11 +308,10 @@ def get_tiktok_stream_url(json_data):
|
||||
|
||||
def get_kuaishou_stream_url(json_data):
|
||||
# TODO: 获取快手直播源地址
|
||||
data = [] # 定义一个返回数据列表
|
||||
data = []
|
||||
|
||||
live_room = json_data['liveroom']
|
||||
anchor_name = live_room['author']['name']
|
||||
data.append(anchor_name)
|
||||
# 获取直播间状态
|
||||
status = live_room['isLiving']
|
||||
# 直播状态True是正在直播.False是未开播
|
||||
@ -338,12 +335,11 @@ def get_kuaishou_stream_url(json_data):
|
||||
|
||||
def get_huya_stream_url(json_data):
|
||||
# TODO: 获取虎牙直播源地址
|
||||
data = [] # 定义一个返回数据列表
|
||||
data = []
|
||||
|
||||
game_live_info = json_data['data'][0]['gameLiveInfo']
|
||||
stream_info_list = json_data['data'][0]['gameStreamInfoList']
|
||||
anchor_name = game_live_info['nick']
|
||||
data.append(anchor_name)
|
||||
# 如果stream_info_list 值为空,则未开直播
|
||||
if len(stream_info_list) == 0:
|
||||
data = [anchor_name, False, '', '']
|
||||
@ -388,7 +384,6 @@ def get_douyu_stream_url(json_data):
|
||||
|
||||
room_info = json_data['pageContext']['pageProps']['room']['roomInfo']['roomInfo']
|
||||
anchor_name = room_info['nickname']
|
||||
data.append(anchor_name)
|
||||
status = room_info['isLive']
|
||||
|
||||
# 如果status值为1,则正在直播
|
||||
@ -411,6 +406,23 @@ def get_douyu_stream_url(json_data):
|
||||
return data
|
||||
|
||||
|
||||
def get_yy_stream_url(json_data):
|
||||
# TODO: 获取YY直播源地址
|
||||
data = []
|
||||
|
||||
anchor_name = json_data['anchor_name']
|
||||
if 'avp_info_res' not in json_data:
|
||||
data = [anchor_name, False, '', '']
|
||||
else:
|
||||
stream_line_addr = json_data['avp_info_res']['stream_line_addr']
|
||||
# 获取最后一个键的值
|
||||
cdn_info = list(stream_line_addr.values())[0]
|
||||
stream_url = cdn_info['cdn_info']['url'] # 清晰度暂时默认高清
|
||||
data = [anchor_name, True, stream_url, stream_url] # 斗鱼目前只能使用flv视频流录制
|
||||
return data
|
||||
|
||||
|
||||
|
||||
def start_record(line, count_variable=-1):
|
||||
global warning_count
|
||||
global video_save_path
|
||||
@ -472,6 +484,12 @@ def start_record(line, count_variable=-1):
|
||||
json_data = get_douyu_info_data(record_url)
|
||||
port_info = get_douyu_stream_url(json_data)
|
||||
|
||||
elif record_url.find("https://www.yy.com/") > -1:
|
||||
with semaphore:
|
||||
json_data = get_yy_stream_data(record_url)
|
||||
port_info = get_yy_stream_url(json_data)
|
||||
|
||||
|
||||
# print("端口信息:" + str(port_info))
|
||||
# port_info=['主播名','状态码','m3u8地址','flv地址']
|
||||
if len(port_info) != 4:
|
||||
@ -1079,7 +1097,8 @@ while True:
|
||||
'www.tiktok.com',
|
||||
'live.kuaishou.com',
|
||||
'www.huya.com',
|
||||
'www.douyu.com'
|
||||
'www.douyu.com',
|
||||
'www.yy.com'
|
||||
]
|
||||
if url_host in host_list:
|
||||
new_line = (url, split_line[1])
|
||||
@ -1128,4 +1147,7 @@ while True:
|
||||
firstRunOtherLine = False
|
||||
|
||||
# 总体循环3s
|
||||
time.sleep(3)
|
||||
time.sleep(3)
|
||||
|
||||
|
||||
|
||||
|
||||
36
spider.py
36
spider.py
@ -4,7 +4,7 @@
|
||||
Author: Hmily
|
||||
Github:https://github.com/ihmily
|
||||
Date: 2023-07-15 23:15:00
|
||||
Update: 2023-08-07 06:41:09
|
||||
Update: 2023-08-12 02:30:52
|
||||
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
||||
Function: Get live stream data.
|
||||
"""
|
||||
@ -176,6 +176,30 @@ def get_douyu_stream_data(rid,rate='-1'):
|
||||
return json_data
|
||||
|
||||
|
||||
def get_yy_stream_data(url):
|
||||
cid=re.search('yy.com/(.*?)/',url).group(1)
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.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://www.yy.com/',
|
||||
}
|
||||
request = urllib.request.Request(url, headers=headers)
|
||||
response = urllib.request.urlopen(request, timeout=10)
|
||||
html_str = response.read().decode('utf-8')
|
||||
live_info = re.search('<div class="w-liveplayer-head__content">(.*)<i class="follow-i">', html_str, re.S).group(1)
|
||||
anchor_name = re.search('<h2>(.*?)</h2>', live_info).group(1)
|
||||
|
||||
data = '{"head":{"seq":1691766627723,"appidstr":"0","bidstr":"121","cidstr":"'+cid+'","sidstr":"'+cid+'","uid64":0,"client_type":108,"client_ver":"5.14.13","stream_sys_ver":1,"app":"yylive_web","playersdk_ver":"5.14.13","thundersdk_ver":"0","streamsdk_ver":"5.14.13"},"client_attribute":{"client":"web","model":"","cpu":"","graphics_card":"","os":"chrome","osversion":"0","vsdk_version":"","app_identify":"","app_version":"","business":"","width":"1536","height":"864","scale":"","client_type":8,"h265":0},"avp_parameter":{"version":1,"client_type":8,"service_type":0,"imsi":0,"send_time":1691766627,"line_seq":-1,"gear":4,"ssl":1,"stream_format":0}}'
|
||||
data_bytes = data.encode('utf-8')
|
||||
url2=f'https://stream-manager.yy.com/v3/channel/streams?uid=0&cid={cid}&sid={cid}&appid=0&sequence=1691766112069&encode=json'
|
||||
request = urllib.request.Request(url2,data=data_bytes, headers=headers)
|
||||
response = urllib.request.urlopen(request, timeout=10)
|
||||
json_str = response.read().decode('utf-8')
|
||||
json_data = json.loads(json_str)
|
||||
json_data['anchor_name']=anchor_name
|
||||
return json_data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 抖音直播间页面的cookie
|
||||
Cookie = 'ttwid=1%7CB1qls3GdnZhUov9o2NxOMxxYS2ff6OSvEWbv0ytbES4%7C1680522049%7C280d802d6d478e3e78d0c807f7c487e7ffec0ae4e5fdd6a0fe74c3c6af149511; my_rd=1; passport_csrf_token=3ab34460fa656183fccfb904b16ff742; passport_csrf_token_default=3ab34460fa656183fccfb904b16ff742; d_ticket=9f562383ac0547d0b561904513229d76c9c21; n_mh=hvnJEQ4Q5eiH74-84kTFUyv4VK8xtSrpRZG1AhCeFNI; store-region=cn-fj; store-region-src=uid; LOGIN_STATUS=1; __security_server_data_status=1; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; pwa2=%223%7C0%7C3%7C0%22; download_guide=%223%2F20230729%2F0%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.6%7D; strategyABtestKey=%221690824679.923%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A150%7D%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1691443863751%2C%22type%22%3Anull%7D; home_can_add_dy_2_desktop=%221%22; __live_version__=%221.1.1.2169%22; device_web_cpu_core=8; device_web_memory_size=8; xgplayer_user_id=346045893336; csrf_session_id=2e00356b5cd8544d17a0e66484946f28; odin_tt=724eb4dd23bc6ffaed9a1571ac4c757ef597768a70c75fef695b95845b7ffcd8b1524278c2ac31c2587996d058e03414595f0a4e856c53bd0d5e5f56dc6d82e24004dc77773e6b83ced6f80f1bb70627; __ac_nonce=064caded4009deafd8b89; __ac_signature=_02B4Z6wo00f01HLUuwwAAIDBh6tRkVLvBQBy9L-AAHiHf7; ttcid=2e9619ebbb8449eaa3d5a42d8ce88ec835; webcast_leading_last_show_time=1691016922379; webcast_leading_total_show_times=1; webcast_local_quality=sd; live_can_add_dy_2_desktop=%221%22; msToken=1JDHnVPw_9yTvzIrwb7cQj8dCMNOoesXbA_IooV8cezcOdpe4pzusZE7NB7tZn9TBXPr0ylxmv-KMs5rqbNUBHP4P7VBFUu0ZAht_BEylqrLpzgt3y5ne_38hXDOX8o=; msToken=jV_yeN1IQKUd9PlNtpL7k5vthGKcHo0dEh_QPUQhr8G3cuYv-Jbb4NnIxGDmhVOkZOCSihNpA2kvYtHiTW25XNNX_yrsv5FN8O6zm3qmCIXcEe0LywLn7oBO2gITEeg=; tt_scid=mYfqpfbDjqXrIGJuQ7q-DlQJfUSG51qG.KUdzztuGP83OjuVLXnQHjsz-BRHRJu4e986'
|
||||
@ -183,12 +207,14 @@ if __name__ == '__main__':
|
||||
# url = "https://www.tiktok.com/@pearlgaga88/live" # Tiktok直播
|
||||
# url = "https://live.kuaishou.com/u/yall1102" # 快手直播
|
||||
# url = 'https://www.huya.com/116' # 虎牙直播
|
||||
url = 'https://www.douyu.com/topic/wzDBLS6?rid=4921614&dyshid=' # 斗鱼直播
|
||||
url = 'https://www.douyu.com/3637778?dyshid='
|
||||
# url = 'https://www.douyu.com/topic/wzDBLS6?rid=4921614&dyshid=' # 斗鱼直播
|
||||
# url = 'https://www.douyu.com/3637778?dyshid='
|
||||
url = 'https://www.yy.com/22490906/22490906'
|
||||
|
||||
# print(get_douyin_stream_data(url,Cookie))
|
||||
# print(get_tiktok_stream_data(url,''))
|
||||
# print(get_kuaishou_stream_data(url))
|
||||
# print(get_huya_stream_data(url))
|
||||
print(get_douyu_info_data(url))
|
||||
print(get_douyu_stream_data("4921614",rate='-1'))
|
||||
# print(get_douyu_info_data(url))
|
||||
# print(get_douyu_stream_data("4921614",rate='-1'))
|
||||
print(get_yy_stream_data(url))
|
||||
Loading…
x
Reference in New Issue
Block a user