Add postprocessor

This commit is contained in:
ForgQi committed 2021-08-27 08:55:03 +08:00
1 parent e23d1698c7
commit 4e6067f181
5 files changed
+38 -13

No files matched your search

+5 -6
View File
@@ -51,7 +51,7 @@ sudo docker ps (找到你的imageId)
sudo docker exec -it imageId /bin/bash
```
## 源码使用
## 调试源码
* 下载源码: git clone https://github.com/ForgQi/bilibiliupload.git
* 安装: `pip3 install -e .` 或者 `pip3 install -r requirements.txt`
* 启动: `python3 -m biliup`
@@ -84,11 +84,7 @@ from biliup.downloader import download
download('文件名', 'https://www.panda.tv/1150595', suffix='flv')
```
## 使用建议
关于B站为什么不能多p上传\
目前bilibili网页端是根据用户权重来限制分p数量的,权重不够的用户自动切换到客户端的提交接口。
>用户等级大于3,且粉丝数>100,web端投稿不限制分p数量
国内VPS网络费用较高,建议使用国外VPS,根据机器的硬盘等资源设置合理并发量。
国内VPS网络费用较高,建议使用国外VPS,根据机器的硬盘等资源设置合理并发量, 选择kodo线路较容易跑满带宽。
b站上传目前有两种模式,分别为bup和bupfetch模式。
>* bup:国内常用模式,视频直接上传到b站投稿系统。
@@ -138,6 +134,9 @@ def transcoding(data):
* ~~selenium操作浏览器上传两种方式~~(详见bili_chromeup.py)
* ~~Windows图形界面版在release中下载AutoTool.msi进行安装~~[AutoTool.msi](https://github.com/ForgQi/bilibiliupload/releases/tag/v0.1.0)
QQ群:837362626
>关于B站为什么不能多p上传\
目前bilibili网页端是根据用户权重来限制分p数量的,权重不够的用户切换到客户端的提交接口即可解除这一限制。
>用户等级大于3,且粉丝数>100,web端投稿不限制分p数量
## Credits
* Thanks `ykdl, youtube-dl, streamlink` provides downloader.
+1 -1
View File
@@ -6,7 +6,7 @@ from .common.timer import Timer
from .engine.event import Event
from .engine import config
__version__ = "0.1.3"
__version__ = "0.1.4"
async def main():
+25 -4
View File
@@ -1,14 +1,17 @@
import logging
import os
import subprocess
from pathlib import Path
logger = logging.getLogger('biliup')
class UploadBase:
def __init__(self, principal, data, persistence_path=None):
def __init__(self, principal, data, persistence_path=None, postprocessor=None):
self.principal = principal
self.persistence_path = persistence_path
self.data = data
self.post_processor = postprocessor
# @property
@staticmethod
@@ -53,9 +56,27 @@ class UploadBase:
if self.filter_file(self.principal):
logger.info('准备上传' + self.data["format_title"])
needed2process = self.upload(UploadBase.file_list(self.principal))
self.postprocessor(needed2process)
if needed2process:
self.postprocessor(needed2process)
def postprocessor(self, data):
# data = file_list
if data:
self.remove_filelist(data)
if self.post_processor is None:
return self.remove_filelist(data)
for post_processor in self.post_processor:
if post_processor == 'rm':
self.remove_filelist(data)
continue
if post_processor.get('mv'):
for file in data:
path = Path(file)
dest = Path(post_processor['mv'])
if not dest.is_dir():
dest.mkdir(parents=True, exist_ok=True)
path.rename(dest / path.name)
logger.info(f"move to {(dest / path.name).absolute()}")
if post_processor.get('run'):
process = subprocess.run(
post_processor['run'], shell=True, input=str(Path('\n'.join(data)).absolute()),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
logger.info(process.stdout.rstrip())
+2 -2
View File
@@ -25,9 +25,9 @@ from ..engine.upload import UploadBase, logger
@Plugin.upload(platform="bili_web")
class BiliWeb(UploadBase):
def __init__(self, principal, data, user, submit_api=None, copyright=2,
def __init__(self, principal, data, user, submit_api=None, copyright=2, postprocessor=None,
lines='AUTO', threads=3, tid=174, tags=None, cover_path=None, description=''):
super().__init__(principal, data, persistence_path='bili.cookie')
super().__init__(principal, data, persistence_path='bili.cookie', postprocessor=postprocessor)
if tags is None:
tags = ['星际争霸2', '电子竞技']
self.user = user
+5
View File
@@ -2,6 +2,7 @@ user: # 在填了cookies的情况下优先使用cookies上传,如需使用用
# cookies:
# SESSDATA: your SESSDATA
# bili_jct: your bili_jct
# DedeUserID__ckMd5: your ckMd5
# DedeUserID: your DedeUserID
# access_token: your access_key
account:
@@ -32,6 +33,10 @@ streamers:
copyright: 2 # 1为自制
cover_path: /cover/up.jpg
description: 视频简介
postprocessor: # 上传完成后,将按自定义顺序执行自定义操作
- run: echo hello! # 执行任意命令,等同于在shell中运行,视频文件路径作为标准输入传入
- mv: backup/ # 移动文件到backup目录下
# - rm # 删除文件,为默认操作
tags:
- 星际争霸2
- 电子竞技