From fa83728f5266a5f82f71ede8cd0c055164f47e7f Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 26 Jun 2022 15:45:45 -0600 Subject: [PATCH] Including process logs in video result. Upgrading yt-dlp. --- modules/videos/conftest.py | 2 +- modules/videos/downloader.py | 22 ++++++++++++++++++---- requirements.txt | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/videos/conftest.py b/modules/videos/conftest.py index 4011f244..ddc4e55f 100644 --- a/modules/videos/conftest.py +++ b/modules/videos/conftest.py @@ -187,7 +187,7 @@ def mock_video_prepare_filename(): @pytest.fixture def mock_video_process_runner(): with mock.patch('modules.videos.downloader.VideoDownloader.process_runner') as mock_process_runner: - mock_process_runner.return_value = (0, {}) + mock_process_runner.return_value = (0, {'stdout': None, 'stderr': None}) yield mock_process_runner diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index c0b8e6e9..03c66426 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -89,7 +89,7 @@ class ChannelDownloader(Downloader, ABC): channel_source_id = info['channel_id'] channel = get_or_create_channel(channel_source_id, download.url, name) channel.dict() # get all attributes while we have the session. - # Resolve all entries. + # Resolve the entries generator. info['entries'] = list(info['entries']) if self.is_a_playlist(info): @@ -128,6 +128,8 @@ class ChannelDownloader(Downloader, ABC): try: # Playlists require more information to download. info = extract_info(download.url, process=True) + # Resolve the entries generator. + info['entries'] = list(info['entries']) # Get all Video.source_id of this Channel. with get_db_session() as session: @@ -246,11 +248,23 @@ class VideoDownloader(Downloader, ABC): ) return_code, logs = self.process_runner(url, cmd, out_dir) + stdout = logs['stdout'].decode() if hasattr(logs['stdout'], 'decode') else logs['stdout'] + stderr = logs['stderr'].decode() if hasattr(logs['stderr'], 'decode') else logs['stderr'] + if return_code != 0: - raise ValueError(f'video downloader process exited with {return_code}') + error = f'{stdout}\n\n\n{stderr}\n\nvideo downloader process exited with {return_code}' + return DownloadResult( + success=False, + error=error, + ) if not video_path.is_file(): - raise ValueError(f'Video file could not be found! {video_path}') + error = f'{stdout}\n\n\n{stderr}\n\n' \ + f'Video file could not be found! {video_path}' + return DownloadResult( + success=False, + error=error, + ) with get_db_session(commit=True) as session: # If the video is from a channel, it will already be in the database. @@ -369,7 +383,7 @@ def update_channel_catalog(channel: Channel, info: dict): logger.info(f'Downloading video list for {channel.name} at {channel.url} This may take several minutes.') # Resolve all entries to dictionaries. - entries = info['entries'] + entries = info['entries'] = list(info['entries']) # yt-dlp may hand back a list of URLs, lets use the "Uploads" URL, if available. try: diff --git a/requirements.txt b/requirements.txt index d7ee42bb..8efad86a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,4 +21,4 @@ SQLAlchemy==1.3.22 srt==3.5.1 websockets==10.1 webvtt-py==0.4.6 -yt-dlp==2022.5.18 +yt-dlp==2022.6.22.1