mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Testing generate_video_poster
This commit is contained in:
parent
1c85a2b74b
commit
9d74b24f2b
4 changed files with 33 additions and 27 deletions
|
|
@ -12,13 +12,13 @@ from PIL import Image
|
|||
from sqlalchemy.orm import Session
|
||||
|
||||
from wrolpi import before_startup
|
||||
from wrolpi.common import logger, CONFIG_PATH, get_config, iterify, chunks, get_media_directory, \
|
||||
from wrolpi.common import logger, get_config, iterify, chunks, get_media_directory, \
|
||||
minimize_dict
|
||||
from wrolpi.db import get_db_session, get_db_curs
|
||||
from wrolpi.errors import UnknownFile, UnknownDirectory, ChannelNameConflict, ChannelURLConflict, \
|
||||
ChannelLinkConflict, ChannelDirectoryConflict, ChannelSourceIdConflict
|
||||
from wrolpi.media_path import MediaPath
|
||||
from wrolpi.vars import DOCKERIZED, DEFAULT_FILE_PERMISSIONS
|
||||
from wrolpi.vars import DEFAULT_FILE_PERMISSIONS
|
||||
from .models import Channel, Video
|
||||
|
||||
logger = logger.getChild(__name__)
|
||||
|
|
@ -270,29 +270,6 @@ def check_for_channel_conflicts(session: Session, id_=None, url=None, name=None,
|
|||
raise ChannelSourceIdConflict()
|
||||
|
||||
|
||||
def verify_config():
|
||||
"""
|
||||
Check that the local.yaml config file exists. Check some basic expectations about it's structure.
|
||||
"""
|
||||
if not pathlib.Path(CONFIG_PATH).exists():
|
||||
raise Exception(f'local.yaml does not exist, looked here: {CONFIG_PATH}')
|
||||
|
||||
media_directory = get_media_directory()
|
||||
error = None
|
||||
if not media_directory.is_absolute():
|
||||
error = f'Media directory is not absolute! {media_directory} '
|
||||
elif not media_directory.exists():
|
||||
error = f'Media directory does not exist! {media_directory} '
|
||||
|
||||
if error and DOCKERIZED:
|
||||
error += 'Have you mounted your media directory in docker-compose.yml?'
|
||||
elif error:
|
||||
error += 'Have you updated your local.yaml with the media_directory?'
|
||||
|
||||
if error:
|
||||
raise Exception(error)
|
||||
|
||||
|
||||
def get_matching_directories(path: Union[str, Path]) -> List[str]:
|
||||
"""
|
||||
Return a list of directory strings that start with the provided path. If the path is a directory, return it's
|
||||
|
|
@ -338,7 +315,7 @@ def replace_extension(path: pathlib.Path, new_ext) -> pathlib.Path:
|
|||
return path
|
||||
|
||||
|
||||
def generate_video_poster(video_path: Path):
|
||||
def generate_video_poster(video_path: Path) -> Path:
|
||||
"""
|
||||
Create a poster (aka thumbnail) next to the provided video_path.
|
||||
"""
|
||||
|
|
@ -352,6 +329,7 @@ def generate_video_poster(video_path: Path):
|
|||
logger.warning(f'FFMPEG poster generation failed with stdout: {e.stdout.decode()}')
|
||||
logger.warning(f'FFMPEG poster generation failed with stdout: {e.stderr.decode()}')
|
||||
raise
|
||||
return poster_path
|
||||
|
||||
|
||||
async def generate_bulk_posters(video_ids: List[int]):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
import pathlib
|
||||
import shutil
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from modules.videos.channel.lib import spread_channel_downloads
|
||||
from modules.videos.models import Channel, Video
|
||||
from wrolpi.downloader import DownloadFrequency
|
||||
from wrolpi.vars import PROJECT_DIR
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -53,3 +58,13 @@ def simple_video(test_session, test_directory, simple_channel) -> Video:
|
|||
test_session.commit()
|
||||
video = test_session.query(Video).filter_by(id=video.id).one()
|
||||
return video
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def video_file(test_directory) -> pathlib.Path:
|
||||
destination = test_directory / f'{uuid4()}.mp4'
|
||||
shutil.copy(PROJECT_DIR / 'test/big_buck_bunny_720p_1mb.mp4', destination)
|
||||
|
||||
yield destination
|
||||
|
||||
destination.unlink()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from wrolpi.db import get_db_session
|
|||
from wrolpi.test.common import build_test_directories, wrap_test_db, TestAPI
|
||||
from wrolpi.vars import PROJECT_DIR
|
||||
from ..common import get_matching_directories, convert_image, bulk_validate_posters, remove_duplicate_video_paths, \
|
||||
update_view_count, get_video_duration
|
||||
update_view_count, get_video_duration, generate_video_poster, replace_extension
|
||||
|
||||
|
||||
class TestCommon(TestAPI):
|
||||
|
|
@ -282,3 +282,14 @@ def test_update_view_count(tempdir: pathlib.Path):
|
|||
check_view_counts({'vid1.mp4': 8, 'vid2.mp4': 11, 'vid3.mp4': 13, 'vid4.mp4': 14})
|
||||
update_view_count(channel1.id)
|
||||
check_view_counts({'vid1.mp4': 10, 'vid2.mp4': 11, 'vid3.mp4': 13, 'vid4.mp4': 14})
|
||||
|
||||
|
||||
def test_generate_video_poster(video_file):
|
||||
"""
|
||||
A poster can be generated from a video file.
|
||||
"""
|
||||
poster_path = replace_extension(video_file, '.jpg')
|
||||
assert not poster_path.is_file(), f'{poster_path} already exists!'
|
||||
generate_video_poster(video_file)
|
||||
assert poster_path.is_file(), f'{poster_path} was not created!'
|
||||
assert poster_path.stat().st_size > 0
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ def get_test_db_engine():
|
|||
conn.execute(f'DROP DATABASE IF EXISTS {db_name}')
|
||||
conn.execute(f'CREATE DATABASE {db_name}')
|
||||
conn.execute('commit')
|
||||
conn.close()
|
||||
|
||||
test_args = get_db_args(db_name)
|
||||
test_engine = create_engine('postgresql://{user}:{password}@{host}:{port}/{dbname}'.format(**test_args))
|
||||
|
|
@ -68,6 +69,7 @@ def test_session() -> Session:
|
|||
test_engine.dispose()
|
||||
conn = postgres_engine.connect()
|
||||
conn.execute(f'DROP DATABASE IF EXISTS {test_engine.engine.url.database}')
|
||||
conn.close()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue