mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Trimming file names more because yt-dlp uses huge temporary names while downloading.
This commit is contained in:
parent
9b8e8e9ffb
commit
4905235083
4 changed files with 22 additions and 19 deletions
2
main.py
2
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:
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue