新增获取BILIBILI直播间封面并作为投稿封面的功能与设置。 (#346)

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Update uploader.py

* Update biliuprs.py

* Update config.yaml

* Update config.toml

* Update bilibili.py

* Update uploader.py
This commit is contained in:
haha114514 authored and GitHub committed 2023-02-28 02:17:02 +00:00
1 parent 0e4e6b529f
commit 7ea0cba5d0
8 files changed
+51 -13

No files matched your search

+3 -2
View File
@@ -5,8 +5,9 @@
- 🔧已修复的问题
- ⚠️需要手动操作的更新信息
## 0.4.5 (待发布)
- 更新时间:未发行
=======
## 0.4.5
- 更新时间:2023.02.28
- 💡新增斗鱼,虎牙,B站的弹幕录制功能,默认关闭,需要在config文件中开启,只支持FFMPEG(目前)[@KNaiFen](https://github.com/KNaiFen) (感谢:[THMonster/danmaku](https://github.com/THMonster/danmaku) )
- 🔧修复了BILIBILI录制中OV05节点的BUG[@haha114514](https://github.com/haha114514)
- ⚠️由于为Config新增了弹幕录制的设置,如需使用相关功能请参考最新的config示例添加缺失的部分。
+1 -1
View File
@@ -1,7 +1,7 @@
import logging
import sys
__version__ = "0.4.4"
__version__ = "0.4.5"
LOG_CONF = {
'version': 1,
+3 -1
View File
@@ -27,12 +27,13 @@ class DownloadBase:
self.url = url
self.suffix = suffix
self.title = None
self.live_cover_path = None
self.downloader = config.get('downloader', 'stream-gears')
# ffmpeg.exe -i http://vfile1.grtn.cn/2018/1542/0254/3368/154202543368.ssm/154202543368.m3u8
# -c copy -bsf:a aac_adtstoasc -movflags +faststart output.mp4
self.raw_stream_url = None
self.filename_prefix = config.get('filename_prefix')
self.use_live_cover = config.get('use_live_cover')
self.opt_args = opt_args
self.fake_headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
@@ -146,6 +147,7 @@ class DownloadBase:
'url': self.url,
'title': self.room_title,
'date': date,
'live_cover_path': self.live_cover_path,
}
@staticmethod
+27 -1
View File
@@ -1,6 +1,7 @@
import asyncio
import requests
import os
import re
import random
from . import match1, logger
@@ -19,6 +20,7 @@ class Bilibili(DownloadBase):
self.fake_headers['cookie'] = config.get('user', {}).get('bili_cookie')
self.customAPI_use_cookie = config.get('user', {}).get('customAPI_use_cookie')
self.bili_cdn_fallback = config.get('bili_cdn_fallback', True)
self.use_live_cover = config.get('use_live_cover', False)
self.bilibili_danmaku = config.get('bilibili_danmaku', False)
def check_stream(self):
@@ -40,7 +42,6 @@ class Bilibili(DownloadBase):
force_ov05_ip = config.get('bili_force_ov05_ip')
force_cn01_domain = config.get('bili_force_cn01_domains')
official_api_host = "https://api.live.bilibili.com"
with requests.Session() as s:
s.headers = self.fake_headers.copy()
# 获取直播状态与房间标题
@@ -53,6 +54,14 @@ class Bilibili(DownloadBase):
if room_info['code'] != 0 or room_info['data']['room_info']['live_status'] != 1:
logger.debug(room_info['message'])
return False
if self.use_live_cover is True: # 获取直播封面并保存到cover目录下
try:
room_id = room_info['data']['room_info']['room_id']
cover_url = room_info['data']['room_info']['cover']
live_start_time = room_info['data']['room_info']['live_start_time']
self.live_cover_path = get_live_cover(room_id, live_start_time, cover_url)
except:
logger.error(f"获取直播封面失败")
params['room_id'] = room_info['data']['room_info']['room_id']
self.room_title = room_info['data']['room_info']['title']
custom_api = config.get('bili_liveapi') is not None
@@ -146,3 +155,20 @@ def get_play_info(s, custom_api, official_api_host, params):
except requests.exceptions.ConnectionError:
logger.error(f"{custom_api_host}连接失败,尝试回退至官方Api")
return s.get(official_api_host + '/xlive/web-room/v2/index/getRoomPlayInfo', params=params, timeout=5).json()
def get_live_cover(room_id, live_start_time, cover_url):
headers = {
"origin": "https://www.bilibili.com",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41"
}
response = requests.get(cover_url, headers=headers, timeout=5)
save_dir = f'cover/'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
live_cover_path = f'{save_dir}{room_id}_{live_start_time}.png'
if os.path.exists(live_cover_path):
return live_cover_path
else:
with open(live_cover_path, 'wb') as f:
f.write(response.content)
return live_cover_path
+3 -1
View File
@@ -21,7 +21,9 @@ class BiliWeb(UploadBase):
self.threads = threads
self.tid = tid
self.tags = tags
self.cover_path = cover_path
if "live_cover_path" in self.data:
self.cover_path = self.data["live_cover_path"]
self.cover_path = cover_path #自定义封面的优先级比直播封面高
self.desc = description
self.dynamic = dynamic
self.copyright = copyright
+1
View File
@@ -26,6 +26,7 @@ def upload(data):
date = data.get("date", time.localtime())
title = data.get('title', index)
url = data.get('url')
live_cover_path = data.get('live_cover_path')
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, title, streamer, url)
+6 -3
View File
@@ -49,13 +49,15 @@ check_sourcecode = 15
#douyu_danmaku = false
#------虎牙------#
# 如遇到虎牙录制卡顿可以尝试切换线路,AL, HW, TX, WS
### 如遇到虎牙录制卡顿可以尝试切换线路,AL, HW, TX, WS
#huyacdn = "AL"
# 录制虎牙弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
### 录制虎牙弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
#huya_danmaku = false
#------哔哩哔哩------#
# 录制BILIBILI弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
### 获取BILIBILI直播间封面并作为投稿封面。此封面优先级低于单个主播指定的自定义封面。(直播封面将会保存于bili_cover_cache下,请自行定期删除)
#use_live_cover = true
### 录制BILIBILI弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
# bilibili_danmaku = false
### 哔哩哔哩直播流协议.可选 stream(Flv)、hls,默认为stream
#bili_protocol = stream
@@ -125,6 +127,7 @@ dynamic = "#空间动态#"
uploader = "biliup-rs" # 覆盖全局默认上传插件,Noop为不上传,但会执行后处理
#filename_prefix = '{streamer}%Y-%m-%d %H_%M_%S{title}' # 覆盖全局自定义录播文件命名规则
user_cookie = "cookies.json" # 使用指定的账号上传
#use_live_cover = true # 获取BILIBILI直播间封面并作为投稿封面。此封面优先级低于单个主播指定的自定义封面。
tags = [ "biliup", "视频标签" ]
# 上传完成后,将按自定义顺序执行自定义操作
#postprocessor = [
+7 -4
View File
@@ -49,11 +49,13 @@ check_sourcecode: 15
#------虎牙------#
### 如遇到虎牙录制卡顿可以尝试切换线路,AL, HW, TX, WS
#huyacdn: AL
# 录制虎牙弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
### 录制虎牙弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
#huya_danmaku: false
#------哔哩哔哩------#\
# 录制BILIBILI弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
#------哔哩哔哩------#
### 获取BILIBILI直播间封面并作为投稿封面。此封面优先级低于单个主播指定的自定义封面。(直播封面将会保存于bili_cover_cache下,请自行定期删除)
#use_live_cover: true
### 录制BILIBILI弹幕,只有使用FFMPEG作为下载器才支持,默认关闭
# bilibili_danmaku: false
### 哔哩哔哩直播流协议.可选 stream(Flv)、hls,默认为stream
#bili_protocol: stream
@@ -120,6 +122,7 @@ streamers:
uploader: biliup-rs ### 覆盖全局默认上传插件,Noop为不上传,但会执行后处理
#filename_prefix: '{streamer}%Y-%m-%d %H_%M_%S{title}' ### 覆盖全局自定义录播文件命名规则
user_cookie: cookies.json ### 使用指定的账号上传
#use_live_cover: true ### 获取BILIBILI直播间封面并作为投稿封面。此封面优先级低于单个主播指定的自定义封面。
preprocessor: ### 开始下载直播时,将按自定义顺序执行自定义操作 注:preprocessor仅支持shell指令
#- run: sh ./run.sh
postprocessor: ### 上传完成后,将按自定义顺序执行自定义操作
@@ -147,7 +150,7 @@ streamers:
###在开启了自定义Cookie(bili_cookie)又同时设置了第三方API(bili_liveapi)的情况下,如果打开了允许第三方API使用Cookie,那么就使用第三方API,如果没有允许(默认),那么设置的第三方API就不生效
#customAPI_use_cookie : False
#------已过时,无视我------#
#------bili-web用(已过时,无视我)------#
# cookies:
# SESSDATA: your SESSDATA
# bili_jct: your bili_jct