Spaces:
Paused
Paused
update
Browse files
data/porter_tasks/porter_task_chenjieshen_douyin_live_record_to_hf_netdisk.json
CHANGED
|
@@ -218,19 +218,69 @@
|
|
| 218 |
{
|
| 219 |
"enable": true,
|
| 220 |
"type": "video_format_convert",
|
| 221 |
-
"task_name": "
|
| 222 |
"video_info_file": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森/file_info.json",
|
| 223 |
-
"target_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record
|
| 224 |
"check_interval": 10,
|
| 225 |
"remove_after_upload": true,
|
| 226 |
-
"
|
|
|
|
|
|
|
| 227 |
},
|
| 228 |
{
|
| 229 |
"enable": true,
|
| 230 |
"type": "file_to_hf_netdisk",
|
| 231 |
-
"task_name": "
|
| 232 |
-
"src_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record
|
| 233 |
-
"tgt_dir": "xianyu/customers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
"repo_id": "tianxing1994/hf_netdisk",
|
| 235 |
"check_interval": 10,
|
| 236 |
"key_of_credentials": "hf_miyuki_write_token",
|
|
|
|
| 218 |
{
|
| 219 |
"enable": true,
|
| 220 |
"type": "video_format_convert",
|
| 221 |
+
"task_name": "陈杰森-primary",
|
| 222 |
"video_info_file": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森/file_info.json",
|
| 223 |
+
"target_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森-primary/ready_to_hf_netdisk",
|
| 224 |
"check_interval": 10,
|
| 225 |
"remove_after_upload": true,
|
| 226 |
+
"remove_after_upload_delay": 3600,
|
| 227 |
+
"format_pairs": [["flv", "mp4"]],
|
| 228 |
+
"cmd_plan": "primary"
|
| 229 |
},
|
| 230 |
{
|
| 231 |
"enable": true,
|
| 232 |
"type": "file_to_hf_netdisk",
|
| 233 |
+
"task_name": "陈杰森-primary",
|
| 234 |
+
"src_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森-primary/ready_to_hf_netdisk",
|
| 235 |
+
"tgt_dir": "xianyu/customers/陈杰森-primary/{date_str}",
|
| 236 |
+
"repo_id": "tianxing1994/hf_netdisk",
|
| 237 |
+
"check_interval": 10,
|
| 238 |
+
"key_of_credentials": "hf_miyuki_write_token",
|
| 239 |
+
"remove_after_upload": true,
|
| 240 |
+
"exclude_files": ["file_info.json"]
|
| 241 |
+
},
|
| 242 |
+
{
|
| 243 |
+
"enable": true,
|
| 244 |
+
"type": "video_format_convert",
|
| 245 |
+
"task_name": "陈杰森-secondary",
|
| 246 |
+
"video_info_file": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森/file_info.json",
|
| 247 |
+
"target_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森-secondary/ready_to_hf_netdisk",
|
| 248 |
+
"check_interval": 10,
|
| 249 |
+
"remove_after_upload": false,
|
| 250 |
+
"remove_after_upload_delay": 1,
|
| 251 |
+
"format_pairs": [["flv", "mp4"]],
|
| 252 |
+
"cmd_plan": "secondary"
|
| 253 |
+
},
|
| 254 |
+
{
|
| 255 |
+
"enable": true,
|
| 256 |
+
"type": "file_to_hf_netdisk",
|
| 257 |
+
"task_name": "陈杰森-secondary",
|
| 258 |
+
"src_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森-secondary/ready_to_hf_netdisk",
|
| 259 |
+
"tgt_dir": "xianyu/customers/陈杰森-secondary/{date_str}",
|
| 260 |
+
"repo_id": "tianxing1994/hf_netdisk",
|
| 261 |
+
"check_interval": 10,
|
| 262 |
+
"key_of_credentials": "hf_miyuki_write_token",
|
| 263 |
+
"remove_after_upload": true,
|
| 264 |
+
"exclude_files": ["file_info.json"]
|
| 265 |
+
},
|
| 266 |
+
{
|
| 267 |
+
"enable": true,
|
| 268 |
+
"type": "video_format_convert",
|
| 269 |
+
"task_name": "陈杰森-tertiary",
|
| 270 |
+
"video_info_file": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森/file_info.json",
|
| 271 |
+
"target_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森-tertiary/ready_to_hf_netdisk",
|
| 272 |
+
"check_interval": 10,
|
| 273 |
+
"remove_after_upload": false,
|
| 274 |
+
"remove_after_upload_delay": 1,
|
| 275 |
+
"format_pairs": [["flv", "mp4"]],
|
| 276 |
+
"cmd_plan": "tertiary"
|
| 277 |
+
},
|
| 278 |
+
{
|
| 279 |
+
"enable": true,
|
| 280 |
+
"type": "file_to_hf_netdisk",
|
| 281 |
+
"task_name": "陈杰森-tertiary",
|
| 282 |
+
"src_dir": "data/tasks/chenjieshen_douyin_live_record_to_hf_netdisk/live_record/陈杰森-tertiary/ready_to_hf_netdisk",
|
| 283 |
+
"tgt_dir": "xianyu/customers/陈杰森-tertiary/{date_str}",
|
| 284 |
"repo_id": "tianxing1994/hf_netdisk",
|
| 285 |
"check_interval": 10,
|
| 286 |
"key_of_credentials": "hf_miyuki_write_token",
|
toolbox/porter/tasks/video_format_convert_task.py
CHANGED
|
@@ -20,6 +20,24 @@ from toolbox.porter.tasks.base_task import BaseTask
|
|
| 20 |
from project_settings import environment, project_path, time_zone_info
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
@BaseTask.register("video_format_convert")
|
| 24 |
class VideoFormatConvertTask(BaseTask):
|
| 25 |
def __init__(self,
|
|
@@ -29,6 +47,8 @@ class VideoFormatConvertTask(BaseTask):
|
|
| 29 |
check_interval: int,
|
| 30 |
format_pairs: List[Tuple[str, str]],
|
| 31 |
remove_after_upload: bool = False,
|
|
|
|
|
|
|
| 32 |
**kwargs
|
| 33 |
):
|
| 34 |
super().__init__(
|
|
@@ -39,6 +59,8 @@ class VideoFormatConvertTask(BaseTask):
|
|
| 39 |
self.target_dir: Path = Path(target_dir)
|
| 40 |
self.format_pairs = format_pairs
|
| 41 |
self.remove_after_upload = remove_after_upload
|
|
|
|
|
|
|
| 42 |
|
| 43 |
if not os.path.isabs(video_info_file):
|
| 44 |
self.video_info_file = project_path / video_info_file
|
|
@@ -73,15 +95,21 @@ class VideoFormatConvertTask(BaseTask):
|
|
| 73 |
# desc = v["desc"]
|
| 74 |
# tags = v["tags"]
|
| 75 |
|
| 76 |
-
format_convert_output_file = v.get(
|
| 77 |
if format_convert_output_file is None:
|
| 78 |
logger.info(f"{self.flag}视频格式转换开始:{filename}")
|
| 79 |
output_file = self.convert_fmt(filename)
|
| 80 |
if self.remove_after_upload:
|
| 81 |
-
logger.info(f"{self.flag}
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
logger.info(f"{self.flag}视频格式转换成功:{filename}")
|
| 84 |
-
v[
|
| 85 |
new_video_info[k] = v
|
| 86 |
await self.save_video_info(new_video_info)
|
| 87 |
|
|
@@ -107,15 +135,46 @@ class VideoFormatConvertTask(BaseTask):
|
|
| 107 |
output_file_ = input_file.parent / f"{uuid.uuid4()}{output_file.suffix}"
|
| 108 |
os.rename(input_file.as_posix(), input_file_.as_posix())
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
try:
|
| 121 |
subprocess.run(command, check=True)
|
|
|
|
| 20 |
from project_settings import environment, project_path, time_zone_info
|
| 21 |
|
| 22 |
|
| 23 |
+
class AsyncDelayTask(object):
|
| 24 |
+
def __init__(self, delay: float, coro_or_future: Union[Coroutine, asyncio.Future]):
|
| 25 |
+
self.delay = delay
|
| 26 |
+
self.coro_or_future = coro_or_future
|
| 27 |
+
|
| 28 |
+
async def run(self):
|
| 29 |
+
await asyncio.sleep(self.delay)
|
| 30 |
+
return await self.coro_or_future
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
async def remove_file(filename: str):
|
| 34 |
+
try:
|
| 35 |
+
logger.info(f"删除文件:{filename}")
|
| 36 |
+
os.remove(filename)
|
| 37 |
+
except FileNotFoundError:
|
| 38 |
+
logger.info(f"文件不存在,跳过删除:{filename}")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
@BaseTask.register("video_format_convert")
|
| 42 |
class VideoFormatConvertTask(BaseTask):
|
| 43 |
def __init__(self,
|
|
|
|
| 47 |
check_interval: int,
|
| 48 |
format_pairs: List[Tuple[str, str]],
|
| 49 |
remove_after_upload: bool = False,
|
| 50 |
+
remove_after_upload_delay: float = 0.1,
|
| 51 |
+
cmd_plan: str = "primary",
|
| 52 |
**kwargs
|
| 53 |
):
|
| 54 |
super().__init__(
|
|
|
|
| 59 |
self.target_dir: Path = Path(target_dir)
|
| 60 |
self.format_pairs = format_pairs
|
| 61 |
self.remove_after_upload = remove_after_upload
|
| 62 |
+
self.remove_after_upload_delay = remove_after_upload_delay
|
| 63 |
+
self.cmd_plan = cmd_plan
|
| 64 |
|
| 65 |
if not os.path.isabs(video_info_file):
|
| 66 |
self.video_info_file = project_path / video_info_file
|
|
|
|
| 95 |
# desc = v["desc"]
|
| 96 |
# tags = v["tags"]
|
| 97 |
|
| 98 |
+
format_convert_output_file = v.get(self.flag)
|
| 99 |
if format_convert_output_file is None:
|
| 100 |
logger.info(f"{self.flag}视频格式转换开始:{filename}")
|
| 101 |
output_file = self.convert_fmt(filename)
|
| 102 |
if self.remove_after_upload:
|
| 103 |
+
logger.info(f"{self.flag}创建文件删除任务:{filename}")
|
| 104 |
+
task = asyncio.ensure_future(
|
| 105 |
+
AsyncDelayTask(
|
| 106 |
+
delay=self.remove_after_upload_delay,
|
| 107 |
+
coro_or_future=remove_file(filename)
|
| 108 |
+
).run()
|
| 109 |
+
)
|
| 110 |
+
# await task
|
| 111 |
logger.info(f"{self.flag}视频格式转换成功:{filename}")
|
| 112 |
+
v[self.flag] = output_file
|
| 113 |
new_video_info[k] = v
|
| 114 |
await self.save_video_info(new_video_info)
|
| 115 |
|
|
|
|
| 135 |
output_file_ = input_file.parent / f"{uuid.uuid4()}{output_file.suffix}"
|
| 136 |
os.rename(input_file.as_posix(), input_file_.as_posix())
|
| 137 |
|
| 138 |
+
if self.cmd_plan == "primary":
|
| 139 |
+
command = [
|
| 140 |
+
"ffmpeg",
|
| 141 |
+
"-i", input_file_.as_posix(),
|
| 142 |
+
"-c:v", "copy", # 视频流不重新编码,速度快
|
| 143 |
+
"-c:a", "aac", # 音频流转换为 AAC(mp4 通用)
|
| 144 |
+
"-strict", "experimental", # 某些 ffmpeg 版本需要
|
| 145 |
+
"-y",
|
| 146 |
+
output_file_.as_posix()
|
| 147 |
+
]
|
| 148 |
+
elif self.cmd_plan == "secondary":
|
| 149 |
+
command = [
|
| 150 |
+
"ffmpeg",
|
| 151 |
+
"-i", input_file_.as_posix(),
|
| 152 |
+
"-crf", "23", # 视频质量(18-28,数值越小质量越高,文件越大)
|
| 153 |
+
"-c:a", "aac",
|
| 154 |
+
"-b:a", "128k", # 音频比特率
|
| 155 |
+
output_file_.as_posix(),
|
| 156 |
+
]
|
| 157 |
+
elif self.cmd_plan == "tertiary":
|
| 158 |
+
command = [
|
| 159 |
+
"ffmpeg",
|
| 160 |
+
"-i", input_file_.as_posix(),
|
| 161 |
+
"-c:v", "libx264",
|
| 162 |
+
"-crf", "28",
|
| 163 |
+
"-preset", "slow",
|
| 164 |
+
"-c:a", "aac",
|
| 165 |
+
"-b:a", "96k",
|
| 166 |
+
output_file_.as_posix(),
|
| 167 |
+
]
|
| 168 |
+
else:
|
| 169 |
+
command = [
|
| 170 |
+
"ffmpeg",
|
| 171 |
+
"-i", input_file_.as_posix(),
|
| 172 |
+
"-c:v", "copy", # 视频流不重新编码,速度快
|
| 173 |
+
"-c:a", "aac", # 音频流转换为 AAC(mp4 通用)
|
| 174 |
+
"-strict", "experimental", # 某些 ffmpeg 版本需要
|
| 175 |
+
"-y",
|
| 176 |
+
output_file_.as_posix()
|
| 177 |
+
]
|
| 178 |
|
| 179 |
try:
|
| 180 |
subprocess.run(command, check=True)
|