diff --git a/podcasts/antennapod.py b/podcasts/antennapod.py index faf4b7f..e44b127 100644 --- a/podcasts/antennapod.py +++ b/podcasts/antennapod.py @@ -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)}):', diff --git a/podcasts/management/commands/import_antennapod.py b/podcasts/management/commands/import_antennapod.py index 8579391..4d61207 100644 --- a/podcasts/management/commands/import_antennapod.py +++ b/podcasts/management/commands/import_antennapod.py @@ -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): diff --git a/podcasts/test_antennapod.py b/podcasts/test_antennapod.py index 124870b..9df20b8 100644 --- a/podcasts/test_antennapod.py +++ b/podcasts/test_antennapod.py @@ -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)