mirror of
https://github.com/RetroZelda/beacon-snatch.git
synced 2026-06-15 04:46:55 +00:00
downloading can use tqdm
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
|||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from tqdm import tqdm
|
||||||
import progressbar
|
import progressbar
|
||||||
|
|
||||||
LOG_VERBOSE = 15
|
LOG_VERBOSE = 15
|
||||||
@@ -86,3 +87,37 @@ def run_ffmpeg_with_progress(command, progress_header: str = "Processing"):
|
|||||||
progress_bar.finish()
|
progress_bar.finish()
|
||||||
|
|
||||||
logging.log(helpers.LOG_VERBOSE, f"Completed in {format_duration(time.time() - start_time)}")
|
logging.log(helpers.LOG_VERBOSE, f"Completed in {format_duration(time.time() - start_time)}")
|
||||||
|
|
||||||
|
def run_ffmpeg_with_tqdm(command, progress_header: str = "Processing"):
|
||||||
|
logging.log(helpers.LOG_VERBOSE, f"Executing ffmpeg")
|
||||||
|
logging.debug(f'{" ".join(command)}')
|
||||||
|
|
||||||
|
try:
|
||||||
|
process = subprocess.Popen(command, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Failed to start ffmpeg: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
duration = None
|
||||||
|
progress_bar = None
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
|
for line in process.stderr:
|
||||||
|
if duration is None:
|
||||||
|
duration = parse_ffmpeg_duration(line)
|
||||||
|
if duration:
|
||||||
|
progress_bar = tqdm(desc=progress_header, total=duration, unit='s', unit_scale=True)
|
||||||
|
|
||||||
|
if progress_bar and duration:
|
||||||
|
current_time = parse_ffmpeg_time(line)
|
||||||
|
if current_time:
|
||||||
|
if current_time > duration:
|
||||||
|
current_time = duration
|
||||||
|
progress_bar.update(current_time)
|
||||||
|
|
||||||
|
process.wait()
|
||||||
|
|
||||||
|
if progress_bar:
|
||||||
|
progress_bar = None
|
||||||
|
|
||||||
|
logging.log(helpers.LOG_VERBOSE, f"Completed in {format_duration(time.time() - start_time)}")
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ requests==2.32.3
|
|||||||
progressbar2==4.4.2
|
progressbar2==4.4.2
|
||||||
m3u8==6.0.0
|
m3u8==6.0.0
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
|
tqdm==4.67.1
|
||||||
Reference in New Issue
Block a user