diff --git a/main.py b/main.py index 7d34348d..29e51b52 100755 --- a/main.py +++ b/main.py @@ -238,7 +238,7 @@ async def start_single_tasks(app: Sanic): init_inventory() if get_wrolpi_config().download_on_startup: - download_manager.enable() + await download_manager.enable() from modules.zim.lib import flag_outdated_zim_files try: diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index 5ed75a5c..e5cab907 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -249,11 +249,14 @@ class VideoDownloader(Downloader, ABC): download.info_json = download.info_json or extract_info(url) except yt_dlp.utils.DownloadError as e: # Video may be private. - return DownloadResult( - success=False, - location=location, - error='\n'.join(traceback.format_exception(e)), - ) + try: + raise RuntimeError('Failed to extract_info') from e + except Exception as e: + return DownloadResult( + success=False, + location=location, + error='\n'.join(traceback.format_exception(e)), + ) if not download.info_json: raise ValueError(f'Cannot download video with no info_json.') @@ -503,14 +506,14 @@ class VideoDownloader(Downloader, ABC): entry = extract_info(url, ydl=ydl, process=True) final_filename = pathlib.Path(prepare_filename(entry, ydl=ydl)).absolute() except DownloadError as e: - if ' Cannot write ' not in str(e): - raise - - # yt-dlp does not handle long file names well, get the name from the error (lol) - last_line = str(e).splitlines()[-1] - full_path = last_line.split(' file ')[-1].strip() - if not full_path.startswith('/'): - logger.error(f'Failed to extract filename from {last_line}') + if ' Cannot write ' in str(e): + # yt-dlp does not handle long file names well, get the name from the error (lol) + last_line = str(e).splitlines()[-1] + full_path = last_line.split(' file ')[-1].strip() + if not full_path.startswith('/'): + logger.error(f'Failed to extract filename from {last_line}') + raise + else: raise # Split filename from parent. diff --git a/wrolpi/common.py b/wrolpi/common.py index 20b71120..f3733c22 100644 --- a/wrolpi/common.py +++ b/wrolpi/common.py @@ -1222,7 +1222,7 @@ def escape_file_name(name: str) -> str: # Maximum length is probably 255, but we need more length for large suffixes like `.readability.json`, and temporary # downloading suffixes from yt-dlp. -MAXIMUM_FILE_LENGTH = 180 +MAXIMUM_FILE_LENGTH = 140 def trim_file_name(path: str | pathlib.Path) -> str | pathlib.Path: diff --git a/wrolpi/test/test_common.py b/wrolpi/test/test_common.py index 09b168a6..99467e32 100644 --- a/wrolpi/test/test_common.py +++ b/wrolpi/test/test_common.py @@ -1014,21 +1014,21 @@ async def test_config_valid(async_client, test_wrolpi_config): (pathlib.Path('foo'), pathlib.Path('foo')), ( 'this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long.txt', - 'this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.txt' + 'this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.txt' ), ( 'some/parent/is/not/trimmed/this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long.info.json', - 'some/parent/is/not/trimmed/this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.info.json' + 'some/parent/is/not/trimmed/this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.info.json' ), ( '/absolute/parent/is/not/trimmed/this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long.info.json', - '/absolute/parent/is/not/trimmed/this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.info.json' + '/absolute/parent/is/not/trimmed/this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.info.json' ), ( pathlib.Path( '/some/parent/is/not/trimmed/this name is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long.readability.json'), pathlib.Path( - '/some/parent/is/not/trimmed/this name is tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.readability.json') + '/some/parent/is/not/trimmed/this name is tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.readability.json') ), ]) def test_trim_file_name(name, expected_name):