diff --git a/facefusion/download.py b/facefusion/download.py index 0812c732..3b3988aa 100644 --- a/facefusion/download.py +++ b/facefusion/download.py @@ -44,14 +44,13 @@ def conditional_download(download_directory_path : str, urls : List[str]) -> Non def get_static_download_size(url : str) -> int: commands = [ '-I', url ] process = open_curl(commands) - process.wait() + lines = reversed(process.stdout.readlines()) - while line := process.stdout.readline().decode().lower(): + for line in lines: + line = line.decode().lower() if 'content-length:' in line: _, content_length = line.split('content-length:') - - if int(content_length) > 0: - return int(content_length) + return int(content_length) return 0 diff --git a/facefusion/ffmpeg.py b/facefusion/ffmpeg.py index a723f620..9eb2ba0f 100644 --- a/facefusion/ffmpeg.py +++ b/facefusion/ffmpeg.py @@ -22,13 +22,13 @@ def run_ffmpeg_with_progress(args: List[str], update_progress : UpdateProgress) while process_manager.is_processing(): try: + lines = process.stdout.readlines() - while line := process.stdout.readline().decode().lower(): + for line in lines: + line = line.decode().lower() if 'frame=' in line: _, frame_number = line.split('frame=') - - if int(frame_number) > 0: - update_progress(int(frame_number)) + update_progress(int(frame_number)) if log_level == 'debug': log_debug(process) diff --git a/tests/test_download.py b/tests/test_download.py index 8cab9a7e..49865a6d 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -1,23 +1,13 @@ -import pytest - -from facefusion.download import conditional_download, get_static_download_size, ping_static_url -from .helper import get_test_examples_directory - - -@pytest.fixture(scope = 'module', autouse = True) -def before_all() -> None: - conditional_download(get_test_examples_directory(), - [ - 'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4' - ]) +from facefusion.download import get_static_download_size, ping_static_url def test_get_static_download_size() -> None: - assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4') == 191675 - assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-360p.mp4') == 370732 + assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.onnx') == 85170772 + assert get_static_download_size('https://huggingface.co/facefusion/models-3.0.0/resolve/main/fairface.onnx') == 85170772 assert get_static_download_size('invalid') == 0 def test_static_ping_url() -> None: assert ping_static_url('https://github.com') is True + assert ping_static_url('https://huggingface.co') is True assert ping_static_url('invalid') is False