diff --git a/app/src/components/Download.js b/app/src/components/Download.js
index e9497320..a0b6e4fb 100644
--- a/app/src/components/Download.js
+++ b/app/src/components/Download.js
@@ -504,6 +504,31 @@ function AdvancedVideoSettings({form, isVideoLevel = false, isConfigLoaded = tru
}
+function AdvancedDownloadSettings({form}) {
+ const [active, setActive] = React.useState(false);
+
+ return
+ setActive(!active)}>
+
+ Advanced Settings
+
+
+
+
+
+
+
+
+
+
+
+}
+
export function VideosDownloadForm({
singleDownload = true,
onCancel,
@@ -1076,6 +1101,7 @@ export function ArchiveDownloadForm({
downloader: formData.downloader,
tag_names: formData.tag_names,
urls: formData.urls.split(/\r?\n/),
+ settings: formData.settings,
}
await postDownload(downloadData);
});
@@ -1084,6 +1110,9 @@ export function ArchiveDownloadForm({
downloader: Downloaders.Archive,
urls: '',
tag_names: [],
+ settings: {
+ skip_already_downloaded: false,
+ },
};
const onSuccess = () => {
@@ -1127,6 +1156,11 @@ export function ArchiveDownloadForm({
+
+
+
+
+
{showMessage && }
@@ -1440,6 +1474,7 @@ export function FilesDownloadForm({
tag_names: formData.tag_names,
destination: formData.destination,
urls: formData.urls.split(/\r?\n/),
+ settings: formData.settings,
}
await postDownload(downloadData);
});
@@ -1448,6 +1483,9 @@ export function FilesDownloadForm({
destination: null,
tag_names: [],
urls: '',
+ settings: {
+ skip_already_downloaded: false,
+ },
};
const form = useForm({
@@ -1480,6 +1518,11 @@ export function FilesDownloadForm({
+
+
+
+
+
{showMessage && }
diff --git a/wrolpi/downloader.py b/wrolpi/downloader.py
index 904b509e..ba25fb5e 100644
--- a/wrolpi/downloader.py
+++ b/wrolpi/downloader.py
@@ -391,7 +391,9 @@ class Downloader:
raise NotImplementedError()
def already_downloaded(self, session: Session, *urls: List[str]):
- raise NotImplementedError()
+ # Subclasses that can detect prior downloads via a stored URL (e.g. FileGroup.url)
+ # should override. Default returns nothing so callers can opt into the dedup check.
+ return []
async def process_runner(self, download: Download, cmd: Tuple[str | pathlib.Path, ...], cwd: pathlib.Path,
timeout: int = None, debug: bool = True,
@@ -765,13 +767,26 @@ class DownloadManager:
downloads = []
# Throws an error if no downloader is found.
- self.find_downloader_by_name(downloader_name)
+ downloader = self.find_downloader_by_name(downloader_name)
if destination:
destination = pathlib.Path(destination) if isinstance(destination, str) else destination
if not destination.is_absolute():
destination = get_absolute_media_path(destination)
+ if settings and settings.get('skip_already_downloaded') and urls:
+ # Filter out URLs that already exist on disk (FileGroup.url) or as a completed Download.
+ existing_urls = {fg.url for fg in downloader.already_downloaded(session, *urls) if fg.url}
+ existing_urls.update(
+ row[0] for row in session.query(Download.url)
+ .filter(Download.url.in_(urls), Download.status == DownloadStatus.complete)
+ )
+ if existing_urls:
+ urls = [u for u in urls if u not in existing_urls]
+ logger.info(f'Skipped {len(existing_urls)} URL(s) already downloaded')
+ if not urls:
+ logger.info('All requested URLs were already downloaded; nothing to queue')
+
for url in urls:
if url in get_download_manager_config().skip_urls and override_skip:
# User manually entered this download, remove it from the skip list.
diff --git a/wrolpi/test/test_downloader.py b/wrolpi/test/test_downloader.py
index 2721efc8..e5f2109e 100644
--- a/wrolpi/test/test_downloader.py
+++ b/wrolpi/test/test_downloader.py
@@ -583,6 +583,84 @@ async def test_skip_urls_none(test_session, test_download_manager, test_download
assert len(downloads) == 1
+@pytest.mark.asyncio
+async def test_skip_already_downloaded_via_filegroup(test_session, test_download_manager, assert_download_urls,
+ test_downloader):
+ """When skip_already_downloaded is set, URLs already present in FileGroup.url are filtered out."""
+ test_downloader.set_test_success()
+ # The downloader reports any URL with 'existing' in it as already downloaded.
+ test_downloader.already_downloaded = lambda session, *urls: [
+ type('FG', (), {'url': u})() for u in urls if 'existing' in u
+ ]
+
+ test_download_manager.create_downloads(
+ test_session,
+ [
+ 'https://example.com/new1',
+ 'https://example.com/existing1',
+ 'https://example.com/new2',
+ 'https://example.com/existing2',
+ ],
+ downloader_name=test_downloader.name,
+ settings={'skip_already_downloaded': True},
+ )
+ assert_download_urls({'https://example.com/new1', 'https://example.com/new2'})
+
+
+@pytest.mark.asyncio
+async def test_skip_already_downloaded_via_completed_download(test_session, test_download_manager,
+ assert_download_urls, test_downloader):
+ """When skip_already_downloaded is set, URLs of completed Downloads are filtered out."""
+ # Pre-existing completed download.
+ completed = Download(url='https://example.com/done', status='complete', downloader=test_downloader.name)
+ test_session.add(completed)
+ test_session.commit()
+
+ test_downloader.set_test_success()
+ test_download_manager.create_downloads(
+ test_session,
+ ['https://example.com/fresh', 'https://example.com/done'],
+ downloader_name=test_downloader.name,
+ settings={'skip_already_downloaded': True},
+ )
+ # The completed URL is excluded; fresh URL is queued. The completed Download row remains.
+ # Row-count + URL-set checks confirm no new row was inserted for 'done'.
+ completed_id = completed.id
+ assert test_session.query(Download).count() == 2
+ assert_download_urls({'https://example.com/done', 'https://example.com/fresh'})
+ fresh = test_session.query(Download).filter_by(url='https://example.com/fresh').one()
+ assert fresh.status == 'new'
+ done = test_session.query(Download).filter_by(url='https://example.com/done').one()
+ # Status unchanged and id preserved — confirms the filter prevented renew().
+ assert done.status == 'complete'
+ assert done.id == completed_id
+
+
+@pytest.mark.asyncio
+async def test_skip_already_downloaded_disabled(test_session, test_download_manager, assert_download_urls,
+ test_downloader):
+ """Without skip_already_downloaded, existing URLs are still queued (renewed)."""
+ completed = Download(url='https://example.com/done', status='complete', downloader=test_downloader.name)
+ test_session.add(completed)
+ test_session.commit()
+
+ test_downloader.set_test_success()
+ # Even though already_downloaded() returns the URL, we don't call it without the setting.
+ test_downloader.already_downloaded = lambda session, *urls: [
+ type('FG', (), {'url': 'https://example.com/done'})()
+ ]
+
+ test_download_manager.create_downloads(
+ test_session,
+ ['https://example.com/done'],
+ downloader_name=test_downloader.name,
+ )
+ # The existing Download row is reused and renewed (status reset to new).
+ assert_download_urls({'https://example.com/done'})
+ download = test_session.query(Download).filter_by(url='https://example.com/done').one()
+ assert download.status == 'new'
+
+
@pytest.mark.asyncio
async def test_process_runner_timeout(async_client, test_session, test_directory):
"""A Downloader can cancel its download using a timeout."""