AntennaPod-Import: --no-downloads bietet die geladenen Folgen nicht an
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8ba82a0e55
commit
561776556f
3 changed files with 20 additions and 4 deletions
|
|
@ -259,6 +259,7 @@ class Stats:
|
|||
downloads_bytes: int = 0
|
||||
downloads_created: int = 0
|
||||
downloads_missing: int = 0
|
||||
downloads_offered: bool = True
|
||||
backup_date: datetime | None = None
|
||||
seconds: float = 0.0
|
||||
|
||||
|
|
@ -291,11 +292,13 @@ def _columns(db, table):
|
|||
|
||||
|
||||
class AntennaPodImport:
|
||||
def __init__(self, user, path, backup_date, global_auto_download=False):
|
||||
def __init__(self, user, path, backup_date, global_auto_download=False, offer_downloads=True):
|
||||
self.user = user
|
||||
self.path = path
|
||||
self.backup_date = backup_date
|
||||
self.global_auto_download = global_auto_download
|
||||
# False: the app doesn't offer AntennaPod's downloads (they stay in AntennaPod).
|
||||
self.offer_downloads = offer_downloads
|
||||
self.stats = Stats(backup_date=backup_date)
|
||||
|
||||
def run(self, dry_run=False):
|
||||
|
|
@ -676,7 +679,8 @@ class AntennaPodImport:
|
|||
entries.append({'episode_id': ep_id, 'size': size})
|
||||
st.downloads = len(entries)
|
||||
st.downloads_bytes = sum(e['size'] for e in entries)
|
||||
settings.import_downloads = entries
|
||||
st.downloads_offered = self.offer_downloads
|
||||
settings.import_downloads = entries if self.offer_downloads else []
|
||||
settings.save(update_fields=['import_downloads'])
|
||||
|
||||
|
||||
|
|
@ -723,7 +727,7 @@ def summary_lines(st, username, path, dry_run, global_auto_download):
|
|||
+ (f'; kept sorted by "{st.keep_sorted}"' if st.keep_sorted else ''),
|
||||
f'Inbox: {st.inbox_before} before, {st.inbox_after} after',
|
||||
f'Downloads: {st.downloads} on the phone in AntennaPod ({st.downloads_bytes / 1_000_000:.0f} MB) '
|
||||
f'-> offered to the app for download'
|
||||
+ ('-> offered to the app for download' if st.downloads_offered else '-> not offered (--no-downloads)')
|
||||
+ (f' ({st.downloads_created} episodes created for them)' if st.downloads_created else '')
|
||||
+ (f'; {st.downloads_missing} not found (feeds not imported, no audio URL)' if st.downloads_missing else ''),
|
||||
f'Created feeds ({len(st.created_titles)}):',
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ class Command(BaseCommand):
|
|||
help='Do everything inside a transaction that is rolled back, print the summary')
|
||||
parser.add_argument('--global-auto-download', choices=('on', 'off'), default='off',
|
||||
help="Auto-download for feeds that use AntennaPod's global setting (default off)")
|
||||
parser.add_argument('--no-downloads', action='store_true',
|
||||
help="Don't offer AntennaPod's downloaded episodes to the app (they stay in AntennaPod)")
|
||||
parser.add_argument('--backup-date',
|
||||
help='When the backup was made (ISO date/time, UTC if no zone); default: the file date. '
|
||||
'diora changes after it win over the backup.')
|
||||
|
|
@ -50,7 +52,8 @@ class Command(BaseCommand):
|
|||
|
||||
global_auto_download = options['global_auto_download'] == 'on'
|
||||
try:
|
||||
stats = AntennaPodImport(user, path, backup_date, global_auto_download).run(dry_run=options['dry_run'])
|
||||
stats = AntennaPodImport(user, path, backup_date, global_auto_download,
|
||||
offer_downloads=not options['no_downloads']).run(dry_run=options['dry_run'])
|
||||
except AntennaPodImportError as e:
|
||||
raise CommandError(str(e))
|
||||
for line in summary_lines(stats, user.username, path, options['dry_run'], global_auto_download):
|
||||
|
|
|
|||
|
|
@ -498,6 +498,15 @@ class DownloadImportTests(ImportTestCase):
|
|||
self.assertEqual(self.offered(), [])
|
||||
self.assertIn('Downloads: 0 on the phone in AntennaPod (0 MB)', out)
|
||||
|
||||
def test_no_downloads_offers_nothing(self):
|
||||
self.episode(self.feed, 'known')
|
||||
self.ap.item(self.ap_feed, 'known', read=0, downloaded=1, size=20_400_000)
|
||||
self.run_import()
|
||||
self.assertEqual(len(self.offered()), 1)
|
||||
out = self.run_import('--no-downloads')
|
||||
self.assertEqual(self.offered(), [])
|
||||
self.assertIn('Downloads: 1 on the phone in AntennaPod (20 MB) -> not offered (--no-downloads)\n', out)
|
||||
|
||||
def test_one_entry_per_episode(self):
|
||||
ep = self.episode(self.feed, 'g')
|
||||
self.ap.item(self.ap_feed, 'g', read=1, downloaded=1, size=10)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue