diff --git a/modules/videos/channel/test/test_models.py b/modules/videos/channel/test/test_models.py index 036ddacc..3668db42 100644 --- a/modules/videos/channel/test/test_models.py +++ b/modules/videos/channel/test/test_models.py @@ -110,8 +110,8 @@ async def test_create_channel_download(test_session, simple_channel): test_session.flush() settings = dict(destination=str(simple_channel.directory)) - download_manager.create_download('https://example.com/2', RSSDownloader.name, test_session, - sub_downloader_name=VideoDownloader.name, settings=settings) + download_manager.recurring_download('https://example.com/2', 1, RSSDownloader.name, test_session, + sub_downloader_name=VideoDownloader.name, settings=settings) download = test_session.query(Download).one() assert download.settings['destination'] == str(simple_channel.directory) download = test_session.query(Download).one() diff --git a/modules/videos/test/test_lib.py b/modules/videos/test/test_lib.py index 0bd3caf0..fc2fee71 100644 --- a/modules/videos/test/test_lib.py +++ b/modules/videos/test/test_lib.py @@ -181,9 +181,9 @@ def test_link_channel_and_downloads_migration(test_async_client, test_session, c """Test the 8d0d81bc9c34_channel_channel_downloads.py migration.""" # A simple Channel which has a download for its URL. channel1 = channel_factory(url='https://example.com/channel1') + download1 = Download(url='https://example.com/channel1', downloader=ChannelDownloader.name, frequency=1) # A Channel which has two Downloads. One for it's URL, another which is an RSS feed in its directory. channel2 = channel_factory(url='https://example.com/channel2') - download1 = Download(url='https://example.com/channel1', downloader=ChannelDownloader.name, frequency=1) download2a = Download(url='https://example.com/channel2/rss', downloader=RSSDownloader.name, frequency=1, settings=dict(destination=str(channel2.directory))) download2b = Download(url='https://example.com/channel2', downloader=ChannelDownloader.name, frequency=1, diff --git a/wrolpi/downloader.py b/wrolpi/downloader.py index aa326af5..11904214 100644 --- a/wrolpi/downloader.py +++ b/wrolpi/downloader.py @@ -253,12 +253,6 @@ class Download(ModelHelper, Base): # noqa return download raise UnknownDownload(f'Cannot find Download with URL: {url}') - @staticmethod - @optional_session - def get_by_channel_id(channel_id: int, session: Session = None) -> Optional['Download']: - download = session.query(Download).filter(Download.channel_id == channel_id).one_or_none() - return download - class Downloader: name: str = None @@ -537,13 +531,6 @@ class DownloadManager: download.sub_downloader = sub_downloader_name download.settings = settings if settings is not None else download.settings - from modules.videos.models import Channel - if channel := Channel.get_by_url(url=download.url, session=session): - download.channel_id = channel.id - if destination := (download.settings or dict()).get('destination'): - if channel := Channel.get_by_path(destination, session): - download.channel_id = channel.id - downloads.append(download) logger.debug(f'Created {len(downloads)} new downloads') @@ -582,6 +569,15 @@ class DownloadManager: reset_attempts=reset_attempts, sub_downloader_name=sub_downloader_name, settings=settings) download.frequency = frequency + + # Only recurring Downloads can be Channel Downloads. + from modules.videos.models import Channel + if channel := Channel.get_by_url(url=download.url, session=session): + download.channel_id = channel.id + if destination := (download.settings or dict()).get('destination'): + if channel := Channel.get_by_path(destination, session): + download.channel_id = channel.id + session.commit() return download