Not deleting video poster when converting to jpg.

This commit is contained in:
Roland 2024-10-16 17:32:54 -06:00
parent d411221412
commit 04d92dca09
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 8 additions and 10 deletions

View file

@ -186,11 +186,8 @@ def convert_or_generate_poster(video: Video) -> Tuple[Optional[pathlib.Path], Op
# Poster is not valid, convert it and place it in the new location.
try:
convert_image(old, new)
if not new.is_file():
if not new.is_file() or not new.stat().st_size:
raise FileNotFoundError(f'Failed to convert poster: {new}')
if old != new:
# Only remove the old one if we are not converting in-place.
old.unlink(missing_ok=True)
logger.info(f'Converted invalid poster {repr(str(old))} to {repr(str(new))}')
return new, None
except Exception as e:

View file

@ -16,7 +16,8 @@ from wrolpi.vars import PROJECT_DIR
from .. import common
from ..common import convert_image, update_view_counts_and_censored, get_video_duration, generate_video_poster, \
is_valid_poster
from ..lib import save_channels_config, get_channels_config, import_channels_config, ChannelsConfig
from ..lib import save_channels_config, get_channels_config, import_channels_config, ChannelsConfig, \
convert_or_generate_poster
def test_get_absolute_media_path(test_directory):

View file

@ -108,14 +108,14 @@ def test_validate_video(test_directory, video_factory, image_bytes_factory, vide
assert vid1.file_group.published_datetime and vid1.file_group.published_datetime.year == 2024
assert vid1.file_group.title == 'The full title'
# A PNG is replaced.
# A PNG is converted, but not deleted.
vid2 = video_factory(with_video_file=True, with_poster_ext='.png')
vid2.poster_path.with_suffix('.jpg').write_bytes(image_bytes_factory()) # New poster exists, replace it.
assert vid2.poster_path and vid2.poster_path.is_file() and vid2.poster_path.suffix == '.png', \
'Poster was not initialized'
assert vid2.poster_path and vid2.poster_path.suffix == '.png', 'Poster was not initialized'
assert {i.suffix for i in vid2.file_group.my_paths()} == {'.png', '.mp4'}
validate_video(vid2, True)
assert vid2.poster_path.is_file(), 'New poster was not generated'
assert vid2.poster_path.suffix == '.jpg'
assert vid2.poster_path.suffix == '.jpg' and vid2.poster_path.stat().st_size > 0
assert {i.suffix for i in vid2.file_group.my_paths()} == {'.jpg', '.png', '.mp4'}
@pytest.mark.asyncio