mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Removing extra meta4 files after aria2c download.
This commit is contained in:
parent
d8b3db9d63
commit
2b811d1a51
5 changed files with 22 additions and 10 deletions
|
|
@ -5,7 +5,7 @@ WORKDIR /opt/wrolpi
|
|||
# Update dependencies for the services install.
|
||||
RUN apt update
|
||||
# ffmpeg for Videos
|
||||
RUN apt-get install -y ffmpeg catdoc sysstat
|
||||
RUN apt-get install -y ffmpeg catdoc sysstat aria2
|
||||
RUN ffmpeg -version
|
||||
# yt-dlp needs cache directory
|
||||
RUN mkdir /.cache && chown -R 1000:1000 /.cache
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ from wrolpi.api_utils import api_app, perpetual_signal
|
|||
from wrolpi.cmd import which
|
||||
from wrolpi.common import Base, ModelHelper, logger, wrol_mode_check, zig_zag, ConfigFile, \
|
||||
wrol_mode_enabled, background_task, get_wrolpi_config, get_absolute_media_path, timer, aiohttp_get, \
|
||||
get_download_info, trim_file_name
|
||||
get_download_info, trim_file_name, TRACE_LEVEL
|
||||
from wrolpi.dates import TZDateTime, now, Seconds
|
||||
from wrolpi.db import get_db_session, get_db_curs, optional_session
|
||||
from wrolpi.errors import InvalidDownload, UnrecoverableDownloadError, UnknownDownload, ValidationError, DownloadError
|
||||
|
|
@ -404,6 +404,11 @@ class Downloader:
|
|||
|
||||
async def download_file(self, download_id: int, url: str, destination: pathlib.Path, check_for_meta4: bool = True) \
|
||||
-> pathlib.Path:
|
||||
from wrolpi.files.lib import glob_shared_stem
|
||||
|
||||
if not ARIA2C_PATH:
|
||||
raise DownloadError('Cannot find aria2c executable')
|
||||
|
||||
meta4_contents = None
|
||||
if check_for_meta4:
|
||||
meta4_contents = await self.get_meta4_contents(url)
|
||||
|
|
@ -445,6 +450,14 @@ class Downloader:
|
|||
if not output_path.is_file():
|
||||
raise DownloadError(f'{error}\n\nOutput file not found: {output_path}')
|
||||
|
||||
# Delete any trailing meta4 files.
|
||||
matching_files = glob_shared_stem(output_path)
|
||||
for file in matching_files:
|
||||
if file.name.endswith('.meta4'):
|
||||
if logger.isEnabledFor(TRACE_LEVEL):
|
||||
logger.trace(f'Deleting meta4 file: {file}')
|
||||
file.unlink()
|
||||
|
||||
return output_path
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -888,13 +888,12 @@ def glob_shared_stem(path: pathlib.Path) -> List[pathlib.Path]:
|
|||
>>> glob_shared_stem(pathlib.Path('foo.mp4'))
|
||||
['foo.mp4', 'foo.png', 'foo.info.json']
|
||||
"""
|
||||
if isinstance(path, str):
|
||||
path = pathlib.Path(path)
|
||||
path = path if isinstance(path, pathlib.Path) else pathlib.Path(path)
|
||||
|
||||
stem, suffix = split_path_stem_and_suffix(path)
|
||||
escaped_stem = glob.escape(stem)
|
||||
paths = [pathlib.Path(i) for i in path.parent.glob(f'{escaped_stem}*') if
|
||||
split_path_stem_and_suffix(i)[0] == stem]
|
||||
paths = [pathlib.Path(i) for i in path.parent.glob(f'{escaped_stem}*')
|
||||
if i == path or i.name.startswith(f'{stem}.')]
|
||||
return paths
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -569,9 +569,9 @@ def test_glob_shared_stem(make_files_structure):
|
|||
def check(path, expected):
|
||||
assert sorted([i.name for i in lib.glob_shared_stem(path)]) == sorted(expected)
|
||||
|
||||
check(mp4, ['video.mp4', 'video.png', 'video.info.json', 'video'])
|
||||
check(png, ['video.mp4', 'video.png', 'video.info.json', 'video'])
|
||||
check(j, ['video.mp4', 'video.png', 'video.info.json', 'video'])
|
||||
check(mp4, ['video.mp4', 'video.png', 'video.info.json'])
|
||||
check(png, ['video.mp4', 'video.png', 'video.info.json'])
|
||||
check(j, ['video.mp4', 'video.png', 'video.info.json'])
|
||||
check(video, ['video.mp4', 'video.png', 'video.info.json', 'video'])
|
||||
|
||||
check(something, ['something'])
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ async def get_iostat_stats() -> IostatInfo:
|
|||
if iostat_stats:
|
||||
cpu_stats, *_ = iostat_stats
|
||||
|
||||
logger.debug(
|
||||
logger.trace(
|
||||
f'get_iostat_stats got percent_iowait={cpu_stats["percent_iowait"]} percent_idle={cpu_stats["percent_idle"]}')
|
||||
# Return only the CPU stats.
|
||||
return IostatInfo(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue