feat: Refactor download queue UI with real-time updates, add queue management buttons, and streamline socket event handling.

This commit is contained in:
2026-01-01 00:32:59 +09:00
parent 681fc0790c
commit 9e25f1f02e
13 changed files with 1431 additions and 845 deletions

View File

@@ -199,15 +199,20 @@ class FfmpegQueue(object):
# except:
# logger.debug('program path make fail!!')
# 파일 존재여부 체크
print("here...................")
P.logger.info(entity.info)
filepath = entity.get_video_filepath()
P.logger.debug(f"filepath:: {filepath}")
if os.path.exists(filepath):
# 다운로드 방법 확인
download_method = P.ModelSetting.get(f"{self.name}_download_method")
# .ytdl 파일이 있거나, ytdlp/aria2c 모드인 경우 '파일 있음'으로 건너뛰지 않음 (이어받기 허용)
is_ytdlp = download_method in ['ytdlp', 'aria2c']
has_ytdl_file = os.path.exists(filepath + ".ytdl")
if os.path.exists(filepath) and not (is_ytdlp or has_ytdl_file):
entity.ffmpeg_status_kor = "파일 있음"
entity.ffmpeg_percent = 100
entity.refresh_status()
# plugin.socketio_list_refresh()
continue
dirname = os.path.dirname(filepath)
filename = os.path.basename(filepath)

View File

@@ -325,16 +325,30 @@ class YtdlpDownloader:
match = prog_re.search(line)
if match:
try:
self.percent = float(match.group('percent'))
new_percent = float(match.group('percent'))
speed_group = match.groupdict().get('speed')
# 속도가 표시되지 않는 경우 (aria2c 등)를 위해 정규식 보완
if not speed_group:
# "[download] 10.5% of ~100.00MiB at 2.45MiB/s" 형태 재확인
at_match = re.search(r'at\s+([\d\.]+\s*\w+/s)', line)
if at_match:
speed_group = at_match.group(1)
if speed_group:
self.current_speed = speed_group.strip()
if self.start_time:
elapsed = time.time() - self.start_time
self.elapsed_time = self.format_time(elapsed)
if self.callback:
logger.info(f"[yt-dlp progress] Calling callback: {int(self.percent)}% speed={self.current_speed}")
# [최적화] 진행률이 1% 이상 차이나거나, 100%인 경우에만 콜백 호출 (로그 부하 감소)
if self.callback and (int(new_percent) > int(self.percent) or new_percent >= 100):
self.percent = new_percent
logger.info(f"[yt-dlp progress] {int(self.percent)}% speed={self.current_speed}")
self.callback(percent=int(self.percent), current=int(self.percent), total=100, speed=self.current_speed, elapsed=self.elapsed_time)
else:
self.percent = new_percent
except Exception as cb_err:
logger.warning(f"Callback error: {cb_err}")
break # 한 패턴이 매칭되면 중단
@@ -371,3 +385,16 @@ class YtdlpDownloader:
def cancel(self):
"""다운로드 취소"""
self.cancelled = True
try:
if self.process:
# subprocess 종류에 따라 종료 방식 결정
if platform.system() == 'Windows':
subprocess.run(['taskkill', '/F', '/T', '/PID', str(self.process.pid)], capture_output=True)
else:
self.process.terminate()
# 강제 종료 필요 시
# import signal
# os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
logger.info(f"Ytdlp process {self.process.pid} terminated by cancel()")
except Exception as e:
logger.error(f"Error terminating ytdlp process: {e}")