Spaces:
Running
Running
File size: 6,911 Bytes
f176037 03e9c58 f176037 03e9c58 f176037 03e9c58 f176037 03e9c58 f176037 03e9c58 a3f1b3e f176037 03e9c58 f176037 03e9c58 f176037 03e9c58 f176037 03e9c58 f176037 a3f1b3e f176037 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
docker build -t douyin_to_youtube:v20250819_2052 .
docker stop douyin_to_youtube_7870 && docker rm douyin_to_youtube_7870
docker run -itd \
--name douyin_to_youtube_7870 \
--restart=always \
--network host \
-e server_port=7870 \
douyin_to_youtube:v20250819_2052 /bin/bash
docker run -itd \
--name douyin_to_youtube_7870 \
--restart=always \
--network host \
-e server_port=7870 \
-v /data/tianxing/PycharmProjects/douyin_to_youtube:/data/tianxing/PycharmProjects/douyin_to_youtube \
python:3.12 /bin/bash
nohup python3 main.py --server_port 7870 &
"""
import argparse
import asyncio
import logging
import platform
import time
import threading
import gradio as gr
import log
from project_settings import environment, project_path, log_directory, time_zone_info
log.setup_size_rotating(log_directory=log_directory, tz_info=time_zone_info)
from toolbox.os.command import Command
from toolbox.live_info_collect.manager import LiveInfoCollectManager
from toolbox.live_recorder.manager import LiveRecorderManager
from toolbox.video_downloader.manager import VideoDownloaderManager
from toolbox.video_upload.youtube_manager import YoutubeVideoUploadManager
from toolbox.video_upload.bilibili_manager import BilibiliVideoUploadManager
from tabs.fs_tab import get_fs_tab
from tabs.shell_tab import get_shell_tab
from tabs.youtube_player_tab import get_youtube_player_tab
logger = logging.getLogger("main")
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--live_info_collect_tasks_file",
default=(project_path / "data/live_info_collect_tasks.json").as_posix(),
type=str
)
parser.add_argument(
"--live_recorder_tasks_file",
default=(project_path / "data/live_recorder_tasks.json").as_posix(),
type=str
)
parser.add_argument(
"--video_download_tasks_file",
default=(project_path / "data/video_download_tasks.json").as_posix(),
type=str
)
parser.add_argument(
"--youtube_video_upload_tasks_file",
default=(project_path / "data/youtube_video_upload_tasks.json").as_posix(),
type=str
)
parser.add_argument(
"--bilibili_video_upload_tasks_file",
default=(project_path / "data/bilibili_video_upload_tasks.json").as_posix(),
type=str
)
parser.add_argument(
"--live_records_dir",
default=(project_path / "data/live_records").as_posix(),
type=str
)
parser.add_argument(
"--server_port",
default=environment.get("server_port", 7860),
type=int
)
args = parser.parse_args()
return args
def shell(cmd: str):
return Command.popen(cmd)
def async_thread_wrapper(coro_task):
logger.info("background_task start")
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(coro_task)
return
def main():
args = get_args()
# task info
run_video_download_tasks = environment.get(key="run_video_download_tasks", default=False, dtype=bool)
run_live_info_collect_tasks = environment.get(key="run_live_info_collect_tasks", default=False, dtype=bool)
run_live_recorder_tasks = environment.get(key="run_live_recorder_tasks", default=True, dtype=bool)
run_youtube_video_upload_tasks = environment.get(key="run_youtube_video_upload_tasks", default=False, dtype=bool)
run_bilibili_video_upload_tasks = environment.get(key="run_bilibili_video_upload_tasks", default=False, dtype=bool)
logger.info(f"run_video_download_tasks: {run_video_download_tasks}, "
f"run_live_info_collect_tasks: {run_live_info_collect_tasks}, "
f"run_live_recorder_tasks: {run_live_recorder_tasks}, "
f"run_youtube_video_upload_tasks: {run_youtube_video_upload_tasks}, "
f"run_bilibili_video_upload_tasks: {run_bilibili_video_upload_tasks}"
)
# video download
if run_video_download_tasks is True:
video_download_manager = VideoDownloaderManager(args.video_download_tasks_file)
video_download_thread = threading.Thread(target=async_thread_wrapper,
args=(video_download_manager.run(),),
daemon=True)
video_download_thread.start()
time.sleep(5)
# live info collect
if run_live_info_collect_tasks is True:
live_info_collect_manager = LiveInfoCollectManager(args.live_info_collect_tasks_file)
live_info_collect_thread = threading.Thread(target=async_thread_wrapper,
args=(live_info_collect_manager.run(),),
daemon=True)
live_info_collect_thread.start()
time.sleep(5)
# live recording
if run_live_recorder_tasks is True:
live_recording_manager = LiveRecorderManager(args.live_recorder_tasks_file)
live_recording_thread = threading.Thread(target=async_thread_wrapper,
args=(live_recording_manager.run(),),
daemon=True)
live_recording_thread.start()
time.sleep(5)
# youtube video upload
if run_youtube_video_upload_tasks is True:
time.sleep(10)
youtube_video_upload_manager = YoutubeVideoUploadManager(args.youtube_video_upload_tasks_file)
youtube_video_upload_thread = threading.Thread(target=async_thread_wrapper,
args=(youtube_video_upload_manager.run(),),
daemon=True)
youtube_video_upload_thread.start()
time.sleep(5)
# bilibili video upload
if run_bilibili_video_upload_tasks is True:
time.sleep(10)
bilibili_video_upload_manager = BilibiliVideoUploadManager(args.bilibili_video_upload_tasks_file)
bilibili_video_upload_thread = threading.Thread(target=async_thread_wrapper,
args=(bilibili_video_upload_manager.run(),),
daemon=True)
bilibili_video_upload_thread.start()
time.sleep(5)
# ui
with gr.Blocks() as blocks:
gr.Markdown(value="live recording.")
with gr.Tabs():
_ = get_fs_tab()
_ = get_shell_tab()
_ = get_youtube_player_tab()
# http://127.0.0.1:7870/
# http://10.75.27.247:7870/
blocks.queue().launch(
# share=True,
share=False if platform.system() == "Windows" else False,
server_name="127.0.0.1" if platform.system() == "Windows" else "0.0.0.0",
server_port=args.server_port
)
return
if __name__ == "__main__":
main()
|