Engine and downloader refactoring (#50)

* Make downloaders subclass of base_downloader.py

* Link engines and downloaders together for all engines

* Replace / merge worker_factory.py with engine_manager.py
This commit is contained in:
2023-10-29 20:57:26 -05:00
committed by GitHub
parent 22aaa82da7
commit dcc0504d3c
11 changed files with 328 additions and 291 deletions

View File

@@ -4,14 +4,16 @@ import re
import requests
from src.engines.core.downloader_core import download_and_extract_app
from src.engines.core.base_downloader import EngineDownloader
from src.engines.ffmpeg.ffmpeg_engine import FFMPEG
from src.utilities.misc_helper import current_system_cpu, current_system_os
logger = logging.getLogger()
supported_formats = ['.zip', '.tar.xz', '.dmg']
class FFMPEGDownloader:
class FFMPEGDownloader(EngineDownloader):
engine = FFMPEG
# macOS FFMPEG mirror maintained by Evermeet - https://evermeet.cx/ffmpeg/
macos_url = "https://evermeet.cx/pub/ffmpeg/"
@@ -88,17 +90,7 @@ class FFMPEGDownloader:
return releases
@classmethod
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
try:
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
return cls.all_versions(system_os, cpu)[0]
except TypeError:
pass
return None
@classmethod
def all_versions(cls, system_os=None, cpu=None):
def __all_versions(cls, system_os=None, cpu=None):
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
versions_per_os = {'linux': cls.__get_linux_versions, 'macos': cls.__get_macos_versions,
@@ -115,13 +107,6 @@ class FFMPEGDownloader:
'version': version})
return results
@classmethod
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
for ver in cls.all_versions(system_os, cpu):
if ver['version'] == version:
return ver
return None
@classmethod
def __get_remote_url_for_version(cls, version, system_os, cpu):
# Platform specific naming cleanup
@@ -141,13 +126,30 @@ class FFMPEGDownloader:
logger.error("Unknown system os")
return remote_url
@classmethod
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
try:
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
return cls.__all_versions(system_os, cpu)[0]
except (IndexError, requests.exceptions.RequestException):
logger.error(f"Cannot get most recent version of ffmpeg")
return {}
@classmethod
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
for ver in cls.__all_versions(system_os, cpu):
if ver['version'] == version:
return ver
return None
@classmethod
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120):
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
# Verify requested version is available
found_version = [item for item in cls.all_versions(system_os, cpu) if item['version'] == version]
found_version = [item for item in cls.__all_versions(system_os, cpu) if item['version'] == version]
if not found_version:
logger.error(f"Cannot find FFMPEG version {version} for {system_os} and {cpu}")
return
@@ -160,7 +162,7 @@ class FFMPEGDownloader:
# Download and extract
try:
logger.info(f"Requesting download of ffmpeg-{version}-{system_os}-{cpu}")
download_and_extract_app(remote_url=remote_url, download_location=download_location, timeout=timeout)
cls.__download_and_extract_app(remote_url=remote_url, download_location=download_location, timeout=timeout)
# naming cleanup to match existing naming convention
output_path = os.path.join(download_location, f'ffmpeg-{version}-{system_os}-{cpu}')