mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 13:49:57 -05:00
Downloads can be re-created and their settings are preserved.
This commit is contained in:
parent
1e4644e15c
commit
b9d79d5440
6 changed files with 49 additions and 9 deletions
|
|
@ -136,15 +136,24 @@ def ffmpeg_poster(video_path: Path, poster_path: Path, seconds: int):
|
|||
|
||||
|
||||
def ffmpeg_video_complete(video_path: Path, seconds: int = None) -> bool:
|
||||
"""Checks if video file is complete by taking screenshot from the end of the video."""
|
||||
seconds = seconds or get_video_duration(video_path) - 5
|
||||
"""Checks if video file is complete by taking screenshot from the end of the video.
|
||||
|
||||
@raise FileNotFoundError: raised if the video file does not exist.
|
||||
"""
|
||||
if not video_path.is_file():
|
||||
raise FileNotFoundError(f'Video file not found: {video_path}')
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix='.jpg', delete=False) as fh:
|
||||
path = Path(fh.name)
|
||||
path.unlink()
|
||||
try:
|
||||
seconds = seconds or get_video_duration(video_path) - 5
|
||||
ffmpeg_poster(video_path, path, seconds)
|
||||
return True
|
||||
except Exception:
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
except TypeError:
|
||||
# "N/A" duration.
|
||||
return False
|
||||
finally:
|
||||
if path.is_file():
|
||||
|
|
@ -234,7 +243,7 @@ async def ffprobe_json(video_path: Union[Path, str]) -> dict:
|
|||
return content
|
||||
|
||||
|
||||
def get_video_duration(video_path: Path) -> int:
|
||||
def get_video_duration(video_path: Path) -> Optional[int]:
|
||||
"""Get the duration of a video in seconds. Do this using ffprobe."""
|
||||
if not isinstance(video_path, Path):
|
||||
video_path = Path(video_path)
|
||||
|
|
@ -252,8 +261,10 @@ def get_video_duration(video_path: Path) -> int:
|
|||
logger.warning(f'FFPROBE failed to get duration with stdout: {e.stdout.decode()}')
|
||||
logger.warning(f'FFPROBE failed to get duration with stderr: {e.stderr.decode()}')
|
||||
raise
|
||||
stdout = proc.stdout.decode()
|
||||
duration = int(Decimal(stdout.strip()))
|
||||
stdout = proc.stdout.decode().strip()
|
||||
if stdout == 'N/A':
|
||||
return None
|
||||
duration = int(Decimal(stdout))
|
||||
return duration
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ class VideoDownloader(Downloader, ABC):
|
|||
if name not in existing_names:
|
||||
video.add_tag(name)
|
||||
|
||||
# Check that video is valid.
|
||||
# Check that video has both audio and video streams.
|
||||
await video.get_ffprobe_json()
|
||||
if not video.get_streams_by_codec_type('video'):
|
||||
return DownloadResult(
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def test_get_absolute_media_path():
|
|||
assert str(path).endswith('videos')
|
||||
|
||||
|
||||
def test_get_video_duration(test_directory):
|
||||
def test_get_video_duration(test_directory, corrupted_video_file):
|
||||
"""
|
||||
Video duration can be retrieved from the video file.
|
||||
"""
|
||||
|
|
@ -36,6 +36,9 @@ def test_get_video_duration(test_directory):
|
|||
empty_file.touch()
|
||||
get_video_duration(empty_file)
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
get_video_duration(corrupted_video_file)
|
||||
|
||||
|
||||
def test_convert_image():
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue