Migration
This commit is contained in:
1 parent
92df202075
commit
23230d6479
5 files changed
+21
-198
No files matched your search
+1
-1
@@ -54,7 +54,7 @@ ENV LANG en_US.utf8
|
||||
#RUN cd /opt \
|
||||
# && pip3 install -r requirements.txt
|
||||
#USER webdriver
|
||||
RUN pip3 install git+https://github.com/ForgQi/bilibiliupload.git@setup
|
||||
RUN pip3 install git+https://github.com/ForgQi/bilibiliupload.git
|
||||
|
||||
#COPY common /opt/common
|
||||
#COPY engine /opt/engine
|
||||
|
||||
@@ -11,30 +11,24 @@
|
||||
相关设置在config.yaml文件中,如直播间地址,b站账号密码
|
||||
|
||||
演示视频:[BV1ip4y1x7Gi](https://www.bilibili.com/video/BV1ip4y1x7Gi)
|
||||
## 使用准备
|
||||
## 1.安装使用
|
||||
1. 创建配置文件**config.yaml**,内容参照**config(demo).yaml**(或可调整配置后直接修改文件名)
|
||||
2. 下载 __FFmpeg__
|
||||
|
||||
## 1. 使用方法:
|
||||
### 方式一
|
||||
1. 安装pip
|
||||
2. 安装biliup:`pip3 install git+https://github.com/ForgQi/bilibiliupload.git@setup`
|
||||
3. 启动:`biliup start`
|
||||
### 方式二
|
||||
依赖安装`pip3 install -r requirements.txt`
|
||||
2. 安装 __FFmpeg__
|
||||
3. 安装 __pip__
|
||||
4. 安装 __biliup__:
|
||||
`pip3 install git+https://github.com/ForgQi/bilibiliupload.git`
|
||||
#### Linux:
|
||||
> 启动: ./Bilibili.py start
|
||||
> 启动: biliup start
|
||||
>
|
||||
> 退出: ./Bilibili.py stop
|
||||
> 退出: biliup stop
|
||||
>
|
||||
> 重启: ./Bilibili.py restart
|
||||
> 重启: biliup restart
|
||||
>
|
||||
> `ps -A | grep .py` 查看进程是否启动成功
|
||||
>
|
||||
> `ps -A | grep biliup` 查看进程是否启动成功
|
||||
#### Windows:
|
||||
~~图形界面版在release中下载AutoTool.msi进行安装~~
|
||||
> 命令行版
|
||||
> 启动: python Bilibili.py
|
||||
> 启动: biliup
|
||||
> QQ群:837362626
|
||||
## 2. Docker使用 🔨
|
||||
### 方式一
|
||||
@@ -53,6 +47,11 @@ sudo docker run -d sc2
|
||||
sudo docker ps (找到你的imageId)
|
||||
sudo docker exec -it imageId /bin/bash
|
||||
```
|
||||
|
||||
## 3.源码使用
|
||||
* 下载源码
|
||||
* 安装: `pip3 install -e .`
|
||||
* 启动: `biliup`
|
||||
## 使用建议
|
||||
关于B站为什么不能多p上传\
|
||||
目前bilibili网页端是根据用户权重来限制分p数量的,权重不够的用户自动切换到客户端的提交接口。
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from threading import Event
|
||||
|
||||
import streamlink
|
||||
import youtube_dl
|
||||
|
||||
from .. import config
|
||||
from ..plugins import logger
|
||||
|
||||
fake_headers = {
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.2.1'
|
||||
}
|
||||
|
||||
|
||||
class DownloadBase:
|
||||
def __init__(self, fname, url, suffix=None):
|
||||
self.fname = fname
|
||||
self.url = url
|
||||
self.suffix = suffix
|
||||
|
||||
def check_stream(self):
|
||||
logger.debug(self.fname)
|
||||
raise NotImplementedError()
|
||||
|
||||
def download(self, filename):
|
||||
raise NotImplementedError()
|
||||
|
||||
def run(self):
|
||||
if not self.check_stream():
|
||||
return False
|
||||
file_name = f'{self.file_name}.{self.suffix}'
|
||||
retval = self.download(file_name)
|
||||
logger.info(f'{retval}part: {file_name}')
|
||||
self.rename(file_name)
|
||||
return retval
|
||||
|
||||
def start(self):
|
||||
i = 0
|
||||
try:
|
||||
logger.info('开始下载%s:%s' % (self.__class__.__name__, self.fname))
|
||||
while i < 30:
|
||||
ret = self.run()
|
||||
if ret is False:
|
||||
return
|
||||
elif ret == 1:
|
||||
time.sleep(45)
|
||||
i += 1
|
||||
except:
|
||||
logger.exception("Uncaught exception:")
|
||||
finally:
|
||||
logger.info(f'退出下载{i}: {self.fname}')
|
||||
|
||||
@staticmethod
|
||||
def rename(file_name):
|
||||
try:
|
||||
os.rename(file_name + '.part', file_name)
|
||||
logger.debug('更名{0}为{1}'.format(file_name + '.part', file_name))
|
||||
except FileNotFoundError:
|
||||
logger.info('FileNotFoundError:' + file_name)
|
||||
except FileExistsError:
|
||||
os.rename(file_name + '.part', file_name)
|
||||
logger.info('FileExistsError:更名{0}为{1}'.format(file_name + '.part', file_name))
|
||||
|
||||
@property
|
||||
def file_name(self):
|
||||
file_name = '%s%s' % (self.fname, str(time.time())[:10])
|
||||
return file_name
|
||||
|
||||
|
||||
class YDownload(DownloadBase):
|
||||
def __init__(self, fname, url, suffix='flv'):
|
||||
super().__init__(fname, url, suffix)
|
||||
self.ydl_opts = {}
|
||||
|
||||
def check_stream(self):
|
||||
try:
|
||||
self.get_sinfo()
|
||||
return True
|
||||
except youtube_dl.utils.DownloadError:
|
||||
logger.debug('%s未开播或读取下载信息失败' % self.fname)
|
||||
return False
|
||||
|
||||
def get_sinfo(self):
|
||||
info_list = []
|
||||
with youtube_dl.YoutubeDL() as ydl:
|
||||
if self.url:
|
||||
info = ydl.extract_info(self.url, download=False)
|
||||
else:
|
||||
logger.debug('%s不存在' % self.__class__.__name__)
|
||||
return
|
||||
for i in info['formats']:
|
||||
info_list.append(i['format_id'])
|
||||
logger.debug(info_list)
|
||||
return info_list
|
||||
|
||||
def download(self, filename):
|
||||
try:
|
||||
self.ydl_opts = {'outtmpl': filename}
|
||||
self.dl()
|
||||
except youtube_dl.utils.DownloadError:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def dl(self):
|
||||
with youtube_dl.YoutubeDL(self.ydl_opts) as ydl:
|
||||
ydl.download([self.url])
|
||||
|
||||
|
||||
class SDownload(DownloadBase):
|
||||
def __init__(self, fname, url, suffix='mp4'):
|
||||
super().__init__(fname, url, suffix)
|
||||
self.stream = None
|
||||
self.flag = Event()
|
||||
|
||||
def check_stream(self):
|
||||
logger.debug(self.fname)
|
||||
try:
|
||||
streams = streamlink.streams(self.url)
|
||||
if streams:
|
||||
self.stream = streams["best"]
|
||||
fd = self.stream.open()
|
||||
fd.close()
|
||||
# streams.close()
|
||||
return True
|
||||
except streamlink.StreamlinkError:
|
||||
return
|
||||
|
||||
def download(self, filename):
|
||||
|
||||
# fd = stream.open()
|
||||
try:
|
||||
with self.stream.open() as fd:
|
||||
with open(filename + '.part', 'wb') as file:
|
||||
for f in fd:
|
||||
file.write(f)
|
||||
if self.flag.is_set():
|
||||
# self.flag.clear()
|
||||
return 1
|
||||
return 0
|
||||
except OSError:
|
||||
self.rename(filename)
|
||||
raise
|
||||
|
||||
|
||||
# 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
|
||||
class FFmpegdl(DownloadBase):
|
||||
def __init__(self, fname, url, suffix=None):
|
||||
super().__init__(fname, url, suffix)
|
||||
self.raw_stream_url = None
|
||||
self.opt_args = []
|
||||
self.default_output_args = [
|
||||
'-bsf:a', 'aac_adtstoasc',
|
||||
'-fs', f"{config.get('file_size') if config.get('file_size') else '2621440000'}"
|
||||
]
|
||||
self.default_input_args = ['-headers', ''.join('%s: %s\r\n' % x for x in fake_headers.items()),
|
||||
'-reconnect_streamed', '1', '-reconnect_delay_max', '20', '-rw_timeout', '20000000']
|
||||
|
||||
def download(self, filename):
|
||||
args = ['ffmpeg', '-y', *self.default_input_args,
|
||||
'-i', self.raw_stream_url, *self.default_output_args, *self.opt_args,
|
||||
'-c', 'copy', '-f', self.suffix, f'{filename}.part']
|
||||
proc = subprocess.Popen(args, stdin=subprocess.PIPE)
|
||||
try:
|
||||
retval = proc.wait()
|
||||
except KeyboardInterrupt:
|
||||
if sys.platform != 'win32':
|
||||
proc.communicate(b'q')
|
||||
raise
|
||||
return retval
|
||||
@@ -3,9 +3,9 @@ import re
|
||||
|
||||
import requests
|
||||
|
||||
from common.decorators import Plugin
|
||||
from engine.plugins import logger, fake_headers
|
||||
from engine.plugins.general import DownloadBase
|
||||
from ...common.decorators import Plugin
|
||||
from . import logger, fake_headers
|
||||
from .general import DownloadBase
|
||||
|
||||
|
||||
@Plugin.download(regexp=r'(?:https?://)?cc\.163\.com')
|
||||
|
||||
@@ -8,7 +8,7 @@ import streamlink
|
||||
import youtube_dl
|
||||
from ykdl.common import url_to_module
|
||||
|
||||
import engine
|
||||
from .. import config
|
||||
from ..plugins import logger, fake_headers
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class DownloadBase:
|
||||
self.opt_args = []
|
||||
self.default_output_args = [
|
||||
'-bsf:a', 'aac_adtstoasc',
|
||||
'-fs', f"{engine.config.get('file_size') if engine.config.get('file_size') else '2621440000'}"
|
||||
'-fs', f"{config.get('file_size') if config.get('file_size') else '2621440000'}"
|
||||
]
|
||||
self.default_input_args = ['-headers', ''.join('%s: %s\r\n' % x for x in fake_headers.items()),
|
||||
'-reconnect_streamed', '1', '-reconnect_delay_max', '20', '-rw_timeout', '20000000']
|
||||
|
||||
Reference in new issue
Block a user