1 parent
ed418402a3
commit
7b06d66766
3 files changed
+60
-31
No files matched your search
+43
-26
@@ -1,4 +1,5 @@
|
||||
import requests
|
||||
import re
|
||||
|
||||
from . import match1, logger
|
||||
from biliup.config import config
|
||||
@@ -12,35 +13,51 @@ class Bilibili(DownloadBase):
|
||||
super().__init__(fname, url, suffix)
|
||||
|
||||
def check_stream(self):
|
||||
rid = match1(self.url, r'/(\d+)')
|
||||
room_info = requests.get(f"https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id={rid}").json()
|
||||
if room_info['code'] == 0:
|
||||
vid = room_info['data']['room_info']['room_id']
|
||||
else:
|
||||
logger.debug(room_info['message'])
|
||||
return False
|
||||
if room_info['data']['room_info']['live_status'] != 1:
|
||||
return False
|
||||
self.room_title = room_info['data']['room_info']['title']
|
||||
biliplatform = config.get('biliplatform') if config.get('biliplatform') else 'web'
|
||||
# 预读配置
|
||||
params = {
|
||||
'room_id': vid,
|
||||
'qn': '10000',
|
||||
'platform': biliplatform,
|
||||
'codec': '0,1',
|
||||
'room_id': match1(self.url, r'/(\d+)'),
|
||||
'protocol': '0,1',
|
||||
'format': '0,1,2',
|
||||
'ptype': '8',
|
||||
'dolby': '5'
|
||||
'codec': '0,1',
|
||||
'qn': '10000',
|
||||
'platform': config.get('biliplatform') if config.get('biliplatform') else "web",
|
||||
# 'ptype': '8',
|
||||
'dolby': '5',
|
||||
'panorama': '1'
|
||||
}
|
||||
data = requests.get("https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo", params=params).json()
|
||||
if data['code'] != 0:
|
||||
logger.debug(data['msg'])
|
||||
return False
|
||||
data = data['data']['playurl_info']['playurl']['stream'][0]['format'][0]['codec'][0]
|
||||
stream_number = 0
|
||||
if "mcdn" in data['url_info'][0]['host']:
|
||||
stream_number += 1
|
||||
self.raw_stream_url = data['url_info'][stream_number]['host'] + data['base_url'] + data['url_info'][stream_number]['extra']
|
||||
protocol = config.get('bili_protocol') if config.get('bili_protocol') else "stream"
|
||||
perfCDN = config.get('bili_perfCDN') if config.get('bili_perfCDN') else ""
|
||||
forceScoure = config.get('bili_forceScoure') if config.get('bili_forceScoure') else False
|
||||
liveapi = config.get('bili_liveapi').rstrip('/') if config.get('bili_liveapi') else 'https://api.live.bilibili.com'
|
||||
self.fake_headers['Referer'] = 'https://live.bilibili.com'
|
||||
|
||||
# 获取直播状态与房间标题
|
||||
roomInfo = requests.get(f"https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id={params['room_id']}").json()
|
||||
if roomInfo['code'] == 0:
|
||||
if roomInfo['data']['room_info']['live_status'] != 1:
|
||||
return False
|
||||
params['room_id'] = roomInfo['data']['room_info']['room_id']
|
||||
self.room_title = roomInfo['data']['room_info']['title']
|
||||
else:
|
||||
logger.debug(roomInfo['message'])
|
||||
return False
|
||||
|
||||
|
||||
playInfo = requests.get(f"{liveapi}/xlive/web-room/v2/index/getRoomPlayInfo", params=params).json()
|
||||
if playInfo['code'] != 0:
|
||||
logger.debug(playInfo['message'])
|
||||
return False
|
||||
streams = playInfo['data']['playurl_info']['playurl']['stream']
|
||||
stream = streams[1] if "hls" in protocol else streams[0]
|
||||
stream_info = stream['format'][0]['codec'][0]
|
||||
for url_info in stream_info['url_info']:
|
||||
if 'mcdn' in url_info['host']:
|
||||
continue
|
||||
if perfCDN in url_info['extra']:
|
||||
if forceScoure and "cn-gotcha01" in perfCDN:
|
||||
stream_info['base_url'] = re.sub(r'\_bluray(?=.*m3u8)', "", stream_info['base_url'])
|
||||
self.raw_stream_url = url_info['host']+stream_info['base_url']+url_info['extra']
|
||||
return True
|
||||
stream_number = len(stream_info['url_info']) - 1
|
||||
self.raw_stream_url = stream_info['url_info'][stream_number]['host']+stream_info['base_url']+stream_info['url_info'][stream_number]['extra']
|
||||
return True
|
||||
+8
-2
@@ -14,8 +14,14 @@ filtering_threshold = 20 # 小于此大小的视频文件将会被过滤删除
|
||||
#douyucdn = "tct-h5"
|
||||
# 如遇到虎牙录制卡顿可以尝试切换线路,AL, HW, TX, WS
|
||||
#huyacdn = "AL"
|
||||
# 如遇到哔哩哔哩录制跳帧可以尝试修改platform值,web(flv),h5(m3u8)
|
||||
#biliplatform = "web"
|
||||
# 哔哩哔哩直播流协议.可选 stream(Flv)、hls
|
||||
#bili_protocol = "stream"
|
||||
# 哔哩哔哩直播优选CDN
|
||||
#bili_perfCDN = "cn-gotcha01"
|
||||
# 哔哩哔哩直播强制原画(仅限HLS流的 cn-gotcha01 CDN)
|
||||
#bili_forceScoure = False
|
||||
# 自定义哔哩哔哩直播api
|
||||
#bili_liveapi = "https://api.live.bilibili.com"
|
||||
# 如需要录制抖音请在此填入cookie需要__ac_nonce与__ac_signature的值
|
||||
#douyin_cookie = '__ac_nonce=123456; __ac_signature=123456;'
|
||||
# 如录制Twitch时遇见视频流中广告过多的情况,可尝试在此填入cookie,可以大幅减少视频流中的twitch广告(经测试需要在该Cookie所属账号开了TwitchTurbo会员才有用),该cookie有过期风险,cookie过期后会导致无法获取到直播流
|
||||
|
||||
+9
-3
@@ -22,7 +22,7 @@ streamers:
|
||||
- https://www.twitch.tv/innovation_s2
|
||||
- https://www.panda.tv/1160340
|
||||
title: "{title}第一视角%Y-%m-%d" # 自定义标题的时间格式, {title}代表直播间标题
|
||||
tid: 171 # 投稿分区码,171为电子竞技分区
|
||||
tid: 171 # 投稿分区码,171为电子竞技分区
|
||||
copyright: 2 # 1为自制
|
||||
cover_path: /cover/up.jpg
|
||||
description: |- # 支持strftime, {title}占位符。 希望你可以保留软件出处
|
||||
@@ -54,8 +54,14 @@ streamers:
|
||||
#douyucdn: tct-h5
|
||||
# 如遇到虎牙录制卡顿可以尝试切换线路,AL, HW, TX, WS
|
||||
#huyacdn: AL
|
||||
# 如遇到哔哩哔哩录制跳帧可以尝试修改platform值,web(flv),h5(m3u8)
|
||||
#biliplatform: web
|
||||
# 哔哩哔哩直播流协议.可选 stream(Flv)、hls
|
||||
#bili_protocol: stream
|
||||
# 哔哩哔哩直播优选CDN
|
||||
#bili_perfCDN: cn-gotcha01
|
||||
# 哔哩哔哩直播强制原画(仅限HLS流的 cn-gotcha01 CDN)
|
||||
#bili_forceScoure: False
|
||||
# 自定义哔哩哔哩直播api
|
||||
#bili_liveapi: 'https://api.live.bilibili.com'
|
||||
# 如需要录制抖音请在此填入cookie需要__ac_nonce与__ac_signature的值
|
||||
#douyin_cookie: '__ac_nonce=123456; __ac_signature=123456;'
|
||||
# 如录制Twitch时遇见视频流中广告过多的情况,可尝试在此填入cookie,可以大幅减少视频流中的twitch广告(经测试需要在该Cookie所属账号开了TwitchTurbo会员才有用),该cookie有过期风险,cookie过期后会导致无法获取到直播流
|
||||
|
||||
Reference in new issue
Block a user