From a665677ecc58f32ed13ccd9f300cf274ee4da1ea Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 16 Mar 2024 19:58:58 -0600 Subject: [PATCH] Adding more lower-quality video formats to download when no other is available. Getting video ffprobe json when downloading. --- modules/videos/downloader.py | 11 ++++++++--- modules/videos/models.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index 90dc0c46..739d6394 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -41,8 +41,10 @@ ChannelIEs = { PREFERRED_VIDEO_EXTENSION = 'mp4' PREFERRED_VIDEO_FORMAT = ','.join([ 'res:720', # Use the best 720p available first - '136+140', # 130=720p video-only, 140= high quality audio only + '136+140', # 130=720p video-only, 140=medium quality audio only '22', # 720p video with audio + '135+140', # 135=480p video-only, 140=medium quality audio only + '135+139', # 135=480p video-only, 139=low quality audio only 'mp4-480p', 'bestvideo*+bestaudio/best', # Download the highest resolution as a last resort (can be quite large). ]) @@ -382,11 +384,12 @@ class VideoDownloader(Downloader, ABC): need_commit = True location = video.location + await video.get_ffprobe_json() + if need_commit: session.commit() # 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( success=False, @@ -399,6 +402,7 @@ class VideoDownloader(Downloader, ABC): error='Video was downloaded but did not contain audio stream', location=location, ) + logger.info(f'Successfully downloaded video {url} {video}') with get_db_session(commit=True) as session: await Video.delete_duplicate_videos(session, download.url, entry['id'], video_path) @@ -430,7 +434,6 @@ class VideoDownloader(Downloader, ABC): return DownloadResult(success=False, error=error, location=location) logger.debug(f'Downloaded video {location=}') - logger.info(f'Successfully downloaded video {url} {video}') result = DownloadResult( success=True, @@ -500,6 +503,8 @@ class VideoDownloader(Downloader, ABC): if video.get_comments(): video.have_comments = True + await video.get_ffprobe_json() + logger.debug(f'Downloaded video info json {location=}') logger.info(f'Successfully downloaded video info json {url} {video}') diff --git a/modules/videos/models.py b/modules/videos/models.py index f27f81ca..55121865 100644 --- a/modules/videos/models.py +++ b/modules/videos/models.py @@ -334,6 +334,7 @@ class Video(ModelHelper, Base): return video def add_tag(self, tag_or_tag_name: Union[Tag, str], session: Session = None) -> TagFile: + session = session or Session.object_session(self) tag = Tag.find_by_name(tag_or_tag_name) if isinstance(tag_or_tag_name, str) else tag_or_tag_name return self.file_group.add_tag(tag, session=session)