mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 14:36:22 -05:00
A channels.yaml import keeps a Channel's once-Downloads (#898)
channels.yaml saves only a Channel's recurring Downloads (Channel.downloads), but its import compared every Download of a Channel's Collection. A once-Download of a Channel's video was "removed from the file", so an import with deletes deleted it, even one that had not run yet. The import now compares, and deletes, only recurring Downloads. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ce7095c0a1
commit
a44cc8a456
2 changed files with 24 additions and 2 deletions
|
|
@ -410,9 +410,10 @@ class ChannelDownloadsSection(ConfigSection):
|
|||
return bool(config.get('channels'))
|
||||
|
||||
def db_rows(self, session: Session) -> Dict[tuple, dict]:
|
||||
# A once-Download (no frequency) is not a Channel's Download; channels.yaml does not save it.
|
||||
query = session.query(Collection.directory, Download.url, Download.frequency) \
|
||||
.join(Collection, Collection.id == Download.collection_id) \
|
||||
.filter(Collection.kind == 'channel', Collection.directory.isnot(None))
|
||||
.filter(Collection.kind == 'channel', Collection.directory.isnot(None), Download.frequency.isnot(None))
|
||||
return {(media_relative(directory), url): dict(frequency=frequency) for directory, url, frequency in query}
|
||||
|
||||
def same(self, file_row: dict, db_row: dict) -> bool:
|
||||
|
|
@ -438,7 +439,8 @@ class ChannelDownloadsSection(ConfigSection):
|
|||
media_directory = get_media_directory()
|
||||
query = session.query(Download, Collection.directory) \
|
||||
.join(Collection, Collection.id == Download.collection_id) \
|
||||
.filter(Collection.kind == 'channel', Download.url.in_([url for _, url in keys]))
|
||||
.filter(Collection.kind == 'channel', Download.frequency.isnot(None),
|
||||
Download.url.in_([url for _, url in keys]))
|
||||
for download, directory in query.all():
|
||||
if (media_relative(directory), download.url) in keys:
|
||||
logger.warning(f'Deleting {download} because it is no longer in its Channel')
|
||||
|
|
|
|||
|
|
@ -304,3 +304,23 @@ async def test_saved_change_is_in_step(test_session, saved_channels, await_switc
|
|||
edit_channel(saved_channels, 'two', url='https://example.com/edited')
|
||||
import_channels_config()
|
||||
assert channels(test_session)['two'].url == 'https://example.com/edited'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_once_download_is_not_a_channel_download(test_session, saved_channels):
|
||||
"""A once-Download of a Channel's video is not one of the Channel's Downloads (channels.yaml does not save it), so
|
||||
importing the config neither deletes it nor writes anything."""
|
||||
two = channels(test_session)['two']
|
||||
download = Download(url='https://example.com/two/video', downloader='video', collection_id=two.collection_id)
|
||||
test_session.add(download)
|
||||
test_session.commit()
|
||||
get_channels_config().dump_config()
|
||||
|
||||
config = get_channels_config()
|
||||
with statements() as collected:
|
||||
config.import_config()
|
||||
|
||||
assert config.successful_import is True
|
||||
test_session.expire_all()
|
||||
assert test_session.query(Download).filter_by(url='https://example.com/two/video').one()
|
||||
assert writes(collected) == []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue