33import subprocess
44import os
55import sys
6- from src .config import SRC_DIR , BILIVE_DIR , RESERVE_FOR_FIXING , UPLOAD_LINE
6+ from src .config import SRC_DIR , BILIVE_DIR , RESERVE_FOR_FIXING , UPLOAD_LINE , GENERATE_COVER
77from datetime import datetime
88from src .upload .generate_upload_data import generate_video_data , generate_slice_data
99from src .upload .extract_video_info import generate_title
10- from src .log .logger import upload_log
10+ from src .log .logger import upload_log , scan_log
1111import time
1212from concurrent .futures import ThreadPoolExecutor , as_completed
1313from db .conn import get_single_upload_queue , delete_upload_queue , update_upload_queue_lock , get_single_lock_queue
1414from .bilitool .bilitool import UploadController , FeedController , LoginController
1515from src .log .retry import Retry
16+ from src .cover .cover_generator import generate_cover
1617
1718@Retry (max_retry = 3 , interval = 5 ).decorator
1819def upload_video (upload_path ):
1920 try :
2021 if upload_path .endswith ('.flv' ):
2122 copyright , title , tid , tag = generate_slice_data (upload_path )
22- yaml , desc , source , cover , dynamic = ("" ,) * 5
23+ if GENERATE_COVER :
24+ cover = generate_cover (upload_path )
25+ else :
26+ cover = ""
27+ yaml , desc , source , dynamic = ("" ,) * 4
2328 if title is None :
24- upload_log .error ("Fail to upload slice video, the files will be reserved ." )
25- update_upload_queue_lock (upload_path , 0 )
29+ upload_log .error ("Fail to upload slice video, the files will be locked ." )
30+ update_upload_queue_lock (upload_path , 1 )
2631 return False
2732 else :
2833 copyright , title , desc , tid , tag , source , cover , dynamic = generate_video_data (upload_path )
@@ -31,16 +36,17 @@ def upload_video(upload_path):
3136 if result == True :
3237 upload_log .info ("Upload successfully, then delete the video" )
3338 os .remove (upload_path )
39+ if cover :
40+ os .remove (cover )
3441 delete_upload_queue (upload_path )
3542 return True
3643 else :
37- upload_log .error ("Fail to upload, the files will be reserved ." )
38- update_upload_queue_lock (upload_path , 0 )
44+ upload_log .error ("Fail to upload, the files will be locked ." )
45+ update_upload_queue_lock (upload_path , 1 )
3946 return False
40-
41- except subprocess .CalledProcessError as e :
42- upload_log .error (f"The upload_video called failed, the files will be reserved. error: { e } " )
43- update_upload_queue_lock (upload_path , 0 )
47+ except Exception as e :
48+ upload_log .error (f"The upload_video called failed, the files will be converted to locked. error: { e } " )
49+ update_upload_queue_lock (upload_path , 1 )
4450 return False
4551
4652@Retry (max_retry = 3 , interval = 5 ).decorator
@@ -54,13 +60,13 @@ def append_upload(upload_path, bv_result):
5460 delete_upload_queue (upload_path )
5561 return True
5662 else :
57- upload_log .error ("Fail to append, the files will be reserved ." )
58- update_upload_queue_lock (upload_path , 0 )
63+ upload_log .error ("Fail to append, the files will be locked ." )
64+ update_upload_queue_lock (upload_path , 1 )
5965 return False
6066
61- except subprocess . CalledProcessError as e :
62- upload_log .error (f"The append_upload called failed, the files will be reserved . error: { e } " )
63- update_upload_queue_lock (upload_path , 0 )
67+ except Exception as e :
68+ upload_log .error (f"The append_upload called failed, the files will be locked . error: { e } " )
69+ update_upload_queue_lock (upload_path , 1 )
6470 return False
6571
6672def video_gate (video_path ):
0 commit comments