mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Not deleting video poster when converting to jpg.
This commit is contained in:
parent
d411221412
commit
04d92dca09
3 changed files with 8 additions and 10 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue