diff --git a/CHANGELOG.md b/CHANGELOG.md index 722c475..f1bb826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,23 @@ - 💡新添加的功能 - 🔧已修复的问题 - ⚠️需要手动操作的更新信息 -- + +## 0.4.4 ⚠️⚠️本次修改了config内部分参数的名称,请需要使用的用户参考最新的config示例修改 +- 更新时间:2023.02.20 +- 💡统一了Config中关键词替换的关键词。 [@haha114514](https://github.com/haha114514) +- ⚠️⚠️请注意修改file_name与title和Description中关键词替换的部分。目前全部统一为streamer,title和url了。 +- 💡新增cn-gotcha01和ov-gotcha05自选ip/节点的设置。 [@haha114514](https://github.com/haha114514) +- ⚠️上一条由于为Config新增了一些设置,如需使用相关功能请参考最新的config示例添加缺失的部分。 +- 🔧修复上一版本由于新增的哔哩哔哩直播自定义下载CDN导致报错的问题。 [@haha114514](https://github.com/haha114514) +- 🔧修复过多请求开播API导致IP被限制访问的问题。[@ForgQi](https://github.com/ForgQi) + ## 0.4.3 - 更新时间:2023.02.15 - 💡为YouTube视频下载增加指定音视频编码的设置。 [@haha114514](https://github.com/haha114514) - ⚠️上一条由于为Config新增了一些设置,如需使用相关功能请参考最新的config示例添加缺失的部分。 - 🔧修复上一版本由于新增的哔哩哔哩直播自定义下载CDN导致报错的问题。 [@haha114514](https://github.com/haha114514) -## 0.4.2⚠️⚠️此版本存在重大BUG,导致很多情况下无法录制B站直播,请勿使用。 +## 0.4.2 ⚠️⚠️此版本存在重大BUG,导致很多情况下无法录制B站直播,请勿使用。 - 更新时间:2023.02.15 - 💡为YouTube视频下载增加指定封装格式,最大纵向分辨率,最大单视频大小的设置。 [@haha114514](https://github.com/haha114514) - ⚠️上一条由于为Config新增了一些设置,如需使用相关功能请参考最新的config示例添加缺失的部分。 diff --git a/biliup/__init__.py b/biliup/__init__.py index db45bae..5218ff3 100644 --- a/biliup/__init__.py +++ b/biliup/__init__.py @@ -1,7 +1,7 @@ import logging import sys -__version__ = "0.4.3" +__version__ = "0.4.4" LOG_CONF = { 'version': 1, diff --git a/biliup/engine/download.py b/biliup/engine/download.py index 81ff4c5..a74a400 100644 --- a/biliup/engine/download.py +++ b/biliup/engine/download.py @@ -53,7 +53,7 @@ class DownloadBase: def download(self, filename): if self.filename_prefix: # 判断是否存在自定义录播命名设置 - filename = (self.filename_prefix.format(streamer=self.fname, room_title=self.room_title).encode('unicode-escape').decode()).encode().decode("unicode-escape") + filename = (self.filename_prefix.format(streamer=self.fname, title=self.room_title).encode('unicode-escape').decode()).encode().decode("unicode-escape") else: filename = f'{self.fname}%Y-%m-%dT%H_%M_%S' filename = get_valid_filename(filename) @@ -142,11 +142,11 @@ class DownloadBase: @property def file_name(self): if self.filename_prefix: # 判断是否存在自定义录播命名设置 - filename = (self.filename_prefix.format(streamer=self.fname, room_title=self.room_title).encode('unicode-escape').decode()).encode().decode("unicode-escape") + filename = (self.filename_prefix.format(streamer=self.fname, title=self.room_title).encode('unicode-escape').decode()).encode().decode("unicode-escape") else: filename = f'{self.fname}%Y-%m-%dT%H_%M_%S' filename = get_valid_filename(filename) - return time.strftime(filename.encode("unicode-escape").decode()).encode().decode("unicode-escape") + return f'{(time.strftime(filename).encode("unicode-escape").decode()).encode().decode("unicode-escape")}' def close(self): pass diff --git a/biliup/plugins/bilibili.py b/biliup/plugins/bilibili.py index a03174f..6b75fd6 100644 --- a/biliup/plugins/bilibili.py +++ b/biliup/plugins/bilibili.py @@ -1,6 +1,6 @@ import requests import re - +import random from . import match1, logger from biliup.config import config from ..engine.decorators import Plugin @@ -32,7 +32,11 @@ class Bilibili(DownloadBase): } protocol = config.get('bili_protocol', 'stream') perf_cdn = config.get('bili_perfCDN') - force_source = config.get('bili_force_source') + force_source = config.get('bili_force_source', False) + force_ov05 = config.get('bili_force_ov05', False) + force_ov05_ip = config.get('bili_force_ov05_ip') + force_cn01 = config.get('bili_force_cn01', False) + force_cn01_domain = config.get('bili_force_cn01_domains') official_api_host = "https://api.live.bilibili.com" with requests.Session() as s: @@ -51,7 +55,7 @@ class Bilibili(DownloadBase): self.room_title = room_info['data']['room_info']['title'] custom_api = config.get('bili_liveapi') is not None # 当 Cookie 存在,并且自定义APi使用Cookie开关关闭时,仅使用官方 Api - if config.get('user', {}).get('bili_cookie') and self.customAPI_use_cookie is not True: + if config.get('user', {}).get('bili_cookie') and self.customAPI_use_cookie is not True: custom_api = False play_info = get_play_info(s, custom_api, official_api_host, params) if play_info['code'] != 0: @@ -69,8 +73,33 @@ class Bilibili(DownloadBase): continue # 匹配PerfCDN if perf_cdn and perf_cdn in url_info['extra']: - if force_source is True and "cn-gotcha01" in perf_cdn: + # 哔哩哔哩直播强制原画(仅限HLS流的 cn-gotcha01 CDN). 并且仅当主播有二压的时候才自动去掉m3u8的_bluray前缀,避免stream-gears的疯狂分段bug + if force_source is True and "cn-gotcha01" in perf_cdn and "_bluray" in stream_info['base_url'] : stream_info['base_url'] = re.sub(r'_bluray(?=.*m3u8)', "", stream_info['base_url']) + # 强制替换hls流的cn-gotcha01的节点为指定节点 注意:只有大陆ip才能获取到cn-gotcha01的节点。 + if force_cn01 is True and force_cn01_domain is not None and "cn-gotcha01" in perf_cdn and protocol == "hls": + i = 0 + while i < 6: #测试随机到的节点是否可用 + random_choice = random.choice(force_cn01_domain.split(",")) + if i == 5: + logger.error(f"强制替换hls流的cn-gotcha01的节点为指定节点失败啦") + return False + i += 1 + try: # 发起 HEAD 请求,并获取响应状态码 + status_code = s.head(f"https://{random_choice}{stream_info['base_url']}{url_info['extra']}", stream=True).status_code + if status_code == 200: # 如果响应状态码是 200,跳出循环 + break + except requests.exceptions.ConnectionError: # 如果发生连接异常,继续下一次循环 + logger.debug(f"随机到的域名 {random_choice} 无法访问,尝试重新发起随机。") + continue + logger.debug(f"随机到的域名 {random_choice} 返回了 200 状态码。") + url_info['host'] = "https://" + random_choice + # 强制替换ov05 302redirect之后的真实地址为指定的域名或ip达到自选ov05节点的目的 + if force_ov05 is True and force_ov05_ip is not None and "ov-gotcha05" in url_info['host']: + response = requests.get(url_info['host']+stream_info['base_url']+url_info['extra'] ) + self.raw_stream_url = re.sub(r"https://([a-z0-9]+)\.ourdvsss\.com", f"http://{ov05_ip}", response.url) + logger.debug(f"将ov-gotcha05的节点ip替换为了{ov05_ip}") + break self.raw_stream_url = url_info['host'] + stream_info['base_url'] + url_info['extra'] logger.debug(f"获取到{url_info['host']}节点,找到了prefCDN") break diff --git a/biliup/uploader.py b/biliup/uploader.py index 2f00a52..1047ed3 100644 --- a/biliup/uploader.py +++ b/biliup/uploader.py @@ -22,12 +22,13 @@ def upload(data): cls = Plugin.upload_plugins.get(platform) if cls is None: return logger.error(f"No such uploader: {platform}") - streamers = data.get('streamers', index) + streamer = data.get('streamer', index) date = data.get("date", time.localtime()) - room_title = data.get('title', index) - data["format_title"] = custom_fmtstr(context.get('title', f'%Y.%m.%d{index}'), date, room_title, streamers) + title = data.get('title', index) + url = data.get('url') + data["format_title"] = custom_fmtstr(context.get('title', f'%Y.%m.%d{index}'), date, title, streamer, url) if context.get('description'): - context['description'] = custom_fmtstr(context.get('description'), date, room_title, streamers) + context['description'] = custom_fmtstr(context.get('description'), date, title, streamer, url) threshold = config.get('filtering_threshold') if threshold: data['threshold'] = threshold @@ -43,5 +44,5 @@ def upload(data): logger.exception("Uncaught exception:") -def custom_fmtstr(string, date, title, streamers): - return time.strftime(string.encode('unicode-escape').decode(), date).encode().decode("unicode-escape").format(title=title, streamers=streamers) +def custom_fmtstr(string, date, title, streamer, url): + return time.strftime(string.encode('unicode-escape').decode(), date).encode().decode("unicode-escape").format(title=title, streamer=streamer, url=url) diff --git a/public/config.toml b/public/config.toml index 9239561..56e205e 100644 --- a/public/config.toml +++ b/public/config.toml @@ -15,19 +15,34 @@ filtering_threshold = 20 # 小于此大小的视频文件将会被过滤删除 #douyucdn = "tct-h5" # 如遇到虎牙录制卡顿可以尝试切换线路,AL, HW, TX, WS #huyacdn = "AL" -# 自定义录播文件名模板, 支持变量 {streamer}:你在配置里设置的直播间名 %Y-%m-%d %H_%M_%S:创建文件的时间, {room_title}:当场直播间标题 +# 自定义录播文件名模板, 支持变量 {streamer}:你在配置里设置的直播间名 %Y-%m-%d %H_%M_%S:创建文件的时间, {title}:当场直播间标题 # 如果上传文件,文件名必须包含设定的模板名。其次,如果没有定义时间,文件分片可能会互相覆盖,所以推荐设置时间来避免分段文件名重复。 -#filename_prefix = '{streamer}%Y-%m-%d %H_%M_%S{room_title}' -# 哔哩哔哩直播流协议.可选 stream(Flv)、hls -#bili_protocol = "stream" -# 哔哩哔哩直播优选CDN -#bili_perfCDN = "cn-gotcha01" -# 哔哩哔哩直播强制原画(仅限HLS流的 cn-gotcha01 CDN) +#filename_prefix = '{streamer}%Y-%m-%d %H_%M_%S{title}' +#------哔哩哔哩------# +### 哔哩哔哩直播流协议.可选 stream(Flv)、hls,默认为stream +#bili_protocol = stream +### 哔哩哔哩直播优选CDN,默认无 +#bili_perfCDN = cn-gotcha01 +### 哔哩哔哩直播强制原画(仅限HLS流的 cn-gotcha01 CDN),默认为关闭 #bili_forceScoure = false -# 自定义哔哩哔哩直播api -#bili_liveapi = "https://api.live.bilibili.com" -# CDN自动Fallback开关,默认为开启 +### 自定义哔哩哔哩直播api,默认无 +#bili_liveapi = 'https://api.live.bilibili.com' +### CDN自动Fallback开关,默认为开启 #bili_cdn_fallback = true +### 强制替换ov-gotcha05的下载地址为指定的自选IP +#bili_force_ov05 = true +#bili_force_ov05_ip = '163.171.197.234' +### 强制替换cn-gotcha01(叔叔自建,理论上最稳定)为指定的自选域名组(可多个域名,请用逗号分隔) +### 完整CDN列表请参考 https://rec.danmuji.org/dev/bilibili-cdn/ 中"B站视频云"的部分 +### 此功能需要设置bili_perfCDN为cn-gotcha01,并且设置bili_protocol为hls。 +### 此功能目前会和stream-gears冲突导致很多分段,请考虑使用ffmpeg录制 +### 如果海外机器需要使用此功能,需要在bili_liveapi中指定国内的反代API来获取cn-gotcha01的节点信息。 +### 海外机的玩法:配合一个国内的机器(例如便宜的腾讯云,阿里云等等)自建反代api.live.bilibili.com +### 如果海外机到联通或者移动网络线路还不错,就可以参考https://rec.danmuji.org/dev/bilibili-cdn/ 选取一些联通或者移动的节点并填入下面 +### 每次会随机返回填入的其中一个线路,并且会自动判断所填入的节点是否可用 +#bili_force_cn01 = true +#bili_force_cn01_domains = 'cn-gdst-cm-01-15.bilivideo.com,cn-gdst-cm-01-06.bilivideo.com,cn-fjqz-cm-01-06.bilivideo.com,cn-jssz-cm-01-02.bilivideo.com,cn-jxnc-cm-01-02.bilivideo.com' + # 检测到主播下播后延迟再次检测,单位:秒,避免特殊情况提早启动上传导致漏录 delay = 10 # 检测间隔时间,单位:秒 @@ -77,20 +92,20 @@ url = [ "https://www.twitch.tv/innovation_s2", "https://www.panda.tv/1160340" ] -title = "{title}第一视角%Y-%m-%d{streamers}" # 自定义标题的时间格式, {title}代表当场直播间标题 {streamers}代表在本config里面设置的主播名称 +title = "{title}第一视角%Y-%m-%d{streamer}{url}" # 自定义标题的时间格式, {title}代表当场直播间标题 {streamer}代表在本config里面设置的主播名称 {url}代表设置的该主播的第一条直播间链接 tid = 171 # 投稿分区码,171为电子竞技分区 copyright = 2 # 1为自制 # cover_path = "/cover/up.jpg" -# 支持strftime, {title},{streamers}占位符。 +# 支持strftime, {title}, {streamer}, {url}占位符。 description = """ -视频简介: {title} %Y-%m-%d %H:%M:%S{streamers} - +视频简介: {title} %Y-%m-%d %H:%M:%S +{streamers}主播直播间地址:{url} --- Powered By biliup - Github: https://github.com/ForgQi/biliup""" dynamic = "#空间动态#" # dtime = 14_400 # 设置延时发布时间,距离提交大于2小时,格式为时间戳 uploader = "biliup-rs" # 覆盖全局默认上传插件,Noop为不上传,但会执行后处理 -#filename_prefix = '{streamer}%Y-%m-%d %H_%M_%S{room_title}' # 覆盖全局自定义录播文件命名规则 +#filename_prefix = '{streamer}%Y-%m-%d %H_%M_%S{title}' # 覆盖全局自定义录播文件命名规则 user_cookie = "cookies.json" # 使用指定的账号上传 tags = [ "biliup", "视频标签" ] # 上传完成后,将按自定义顺序执行自定义操作 diff --git a/public/config.yaml b/public/config.yaml index ebad034..993f212 100644 --- a/public/config.yaml +++ b/public/config.yaml @@ -10,9 +10,9 @@ file_size: 2621440000 ### 小于此大小的视频文件将会被过滤删除,单位MB filtering_threshold: 20 -### 自定义录播文件名模板, 支持变量 {streamer}:你在配置里设置的直播间名 %Y-%m-%d %H_%M_%S:创建文件的时间, {room_title}:当场直播间标题 +### 自定义录播文件名模板, 支持变量 {streamer}:你在配置里设置的直播间名 %Y-%m-%d %H_%M_%S:创建文件的时间, {title}:当场直播间标题 ### 如果上传文件,文件名必须包含设定的模板名。其次,如果没有定义时间,文件分片可能会互相覆盖,所以推荐设置时间来避免分段文件名重复。 -#filename_prefix: '{streamer}%Y-%m-%d %H_%M_%S{room_title}' +#filename_prefix: '{streamer}%Y-%m-%d %H_%M_%S{title}' #------上传------# ### 选择全局默认上传插件,Noop为不上传,但会执行后处理,可选bili_web,biliup-rs @@ -59,6 +59,19 @@ check_sourcecode: 15 #bili_liveapi: 'https://api.live.bilibili.com' ### CDN自动Fallback开关,默认为开启 #bili_cdn_fallback: true +### 强制替换ov-gotcha05的下载地址为指定的自选IP +#bili_force_ov05: true +#bili_force_ov05_ip: '163.171.197.234' +### 强制替换cn-gotcha01(叔叔自建,理论上最稳定)为指定的自选域名组(可多个域名,请用逗号分隔) +### 完整CDN列表请参考 https://rec.danmuji.org/dev/bilibili-cdn/ 中"B站视频云"的部分 +### 此功能需要设置bili_perfCDN为cn-gotcha01,并且设置bili_protocol为hls。 +### 此功能目前会和stream-gears冲突导致很多分段,请考虑使用ffmpeg录制 +### 如果海外机器需要使用此功能,需要在bili_liveapi中指定国内的反代API来获取cn-gotcha01的节点信息。 +### 海外机的玩法:配合一个国内的机器(例如便宜的腾讯云,阿里云等等)自建反代api.live.bilibili.com +### 如果海外机到联通或者移动网络线路还不错,就可以参考https://rec.danmuji.org/dev/bilibili-cdn/ 选取一些联通或者移动的节点并填入下面 +### 每次会随机返回填入的其中一个线路,并且会自动判断所填入的节点是否可用 +#bili_force_cn01: true +#bili_force_cn01_domains: 'cn-gdst-cm-01-15.bilivideo.com,cn-gdst-cm-01-06.bilivideo.com,cn-fjqz-cm-01-06.bilivideo.com,cn-jssz-cm-01-02.bilivideo.com,cn-jxnc-cm-01-02.bilivideo.com' #------YouTube------# ### 设置偏好的YouTube下载封装格式 @@ -89,19 +102,19 @@ streamers: url: - https://www.twitch.tv/innovation_s2 - https://www.panda.tv/1160340 - title: "{title}第一视角%Y-%m-%d{streamer}" ### 自定义标题的时间格式, {title}代表当场直播间标题 {streamers}代表在本config里面设置的主播名称 + title: "{title}第一视角%Y-%m-%d{streamer}{url}" ### 自定义标题的时间格式, {title}代表当场直播间标题 {streamer}代表在本config里面设置的主播名称 {url}代表设置的该主播的第一条直播间链接 tid: 171 ### 投稿分区码,171为电子竞技分区 copyright: 2 ### 1为自制 cover_path: /cover/up.jpg ###封面 - description: |- ### 支持strftime, {title}, {streamers}占位符。注:此处请注意缩进,确保所有文字的缩进都与"视频简介"相同或者更多。 - 视频简介: {title} %Y-%m-%d %H:%M:%S {streamers} - 喜欢就点个关注吧。 + description: |- ### 支持strftime, {title}, {streamer}, {url}占位符。注:此处请注意缩进,确保所有文字的缩进都与"视频简介"相同或者更多。 + 视频简介: {title} %Y-%m-%d %H:%M:%S + {streamers}主播直播间地址:{url} --- Powered By biliup - Github: https://github.com/ForgQi/biliup dynamic: '#空间动态#' dtime: 14400 ### 设置延时发布时间,距离提交大于2小时,格式为时间戳 uploader: biliup-rs ### 覆盖全局默认上传插件,Noop为不上传,但会执行后处理 - #filename_prefix: '{streamer}%Y-%m-%d %H_%M_%S{room_title}' ### 覆盖全局自定义录播文件命名规则 + #filename_prefix: '{streamer}%Y-%m-%d %H_%M_%S{title}' ### 覆盖全局自定义录播文件命名规则 user_cookie: cookies.json ### 使用指定的账号上传 preprocessor: ### 开始下载直播时,将按自定义顺序执行自定义操作 注:preprocessor仅支持shell指令 #- run: sh ./run.sh