diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index 16bd480b..26ef124a 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -70,14 +70,6 @@ class ChannelDownloader(Downloader, ABC): def __repr__(self): return f'' - @classmethod - def valid_url(cls, url) -> Tuple[bool, None]: - for ie in ChannelIEs: - if ie.suitable(url): - return True, None - logger.debug(f'{cls.__name__} not suitable for {url}') - return False, None - @staticmethod def is_a_playlist(info: dict): # A playlist may have an id different from its channel. @@ -95,6 +87,7 @@ class ChannelDownloader(Downloader, ABC): f' Try requesting the videos only:' f' https://example.com -> https://example.com/videos') + download.sub_downloader = video_downloader.name download.info_json = info if session := Session.object_session(download): # May not have a session during testing. @@ -183,44 +176,18 @@ class VideoDownloader(Downloader, ABC): @optional_session def already_downloaded(self, *urls: str, session: Session = None) -> List: # We only consider a video record with a video file as "downloaded". - videos = list(session.query(Video).filter( - Video.url.in_(urls), - Video.video_path != None, # noqa - )) + videos = list(session.query(Video).filter(Video.url.in_(urls))) return videos - @classmethod - def valid_url(cls, url) -> Tuple[bool, Optional[dict]]: - """Match against all Youtube-DL Info Extractors, except those that match a Channel.""" - for ie in YDL._ies.values(): - if ie.suitable(url) and not ChannelDownloader.valid_url(url)[0]: - try: - info = extract_info(url) - return True, info - except UnsupportedError: - logger.debug(f'Video downloader extract_info failed for {url}') - return False, None - except DownloadError: - logger.debug(f'Video downloader extract_info failed for {url}') - return False, None - logger.debug(f'{cls.__name__} not suitable for {url}') - return False, None - async def do_download(self, download: Download) -> DownloadResult: if download.attempts >= 10: raise UnrecoverableDownloadError('Max download attempts reached') url = download.url - info = download.info_json + info = download.info_json or extract_info(url) if not info: - # Info was not fetched by the DownloadManager, lets get it. - valid, info = self.valid_url(url) - if not valid: - raise UnrecoverableDownloadError(f'{self} cannot download {url}') - session = Session.object_session(download) - download.info_json = info - session.commit() + raise ValueError(f'Cannot download video with no info_json.') found_channel = None diff --git a/modules/videos/test/test_downloader.py b/modules/videos/test/test_downloader.py index 1694bdd0..7cf1b301 100644 --- a/modules/videos/test/test_downloader.py +++ b/modules/videos/test/test_downloader.py @@ -106,31 +106,6 @@ example_channel_json = { } -def test_video_valid_url(): - # A specific video can be downloaded. - assert video_downloader.valid_url('https://www.youtube.com/watch?v=31jPEBiAC3c')[0] is True - - # A channel cannot be downloaded. - assert video_downloader.valid_url('https://www.youtube.com/c/LearningSelfReliance/videos')[0] is False - assert video_downloader.valid_url('https://www.youtube.com/c/LearningSelfReliance')[0] is False - - -def test_channel_valid_url(): - # An entire domain cannot be downloaded. - assert not channel_downloader.valid_url('https://example.com')[0] - assert not channel_downloader.valid_url('https://youtube.com')[0] - - # Cannot download a single video. - assert not channel_downloader.valid_url('https://www.youtube.com/watch?v=31jPEBiAC3c')[0] - - # Can download entire channels. - assert channel_downloader.valid_url('https://www.youtube.com/c/LearningSelfReliance/videos')[0] - assert channel_downloader.valid_url('https://www.youtube.com/c/LearningSelfReliance')[0] - - # Can download entire playlists. - assert channel_downloader.valid_url('https://www.youtube.com/playlist?list=PLCdlMQeP-TbG12nkBCt0E96yr3EfwcH4E')[0] - - @pytest.mark.asyncio async def test_download_no_channel(test_session, video_download_manager, video_factory, test_directory, mock_video_extract_info, mock_video_process_runner): diff --git a/wrolpi/downloader.py b/wrolpi/downloader.py index 83800067..4212515a 100644 --- a/wrolpi/downloader.py +++ b/wrolpi/downloader.py @@ -180,10 +180,6 @@ class Downloader: def __repr__(self): return f'' - @classmethod - def valid_url(cls, url: str) -> Tuple[bool, Optional[dict]]: - raise NotImplementedError() - async def do_download(self, download: Download) -> DownloadResult: raise NotImplementedError()