mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 19:36:20 -05:00
Adding toggle to skip already downloaded archives and files.
This commit is contained in:
parent
5eefc2098f
commit
86b7782361
3 changed files with 138 additions and 2 deletions
|
|
@ -504,6 +504,31 @@ function AdvancedVideoSettings({form, isVideoLevel = false, isConfigLoaded = tru
|
|||
</Accordion>
|
||||
}
|
||||
|
||||
function AdvancedDownloadSettings({form}) {
|
||||
const [active, setActive] = React.useState(false);
|
||||
|
||||
return <Accordion fluid>
|
||||
<Accordion.Title active={active} onClick={() => setActive(!active)}>
|
||||
<Icon name='dropdown'/>
|
||||
Advanced Settings
|
||||
</Accordion.Title>
|
||||
<Accordion.Content active={active}>
|
||||
<Grid stackable>
|
||||
<Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label='Skip URLs already downloaded'
|
||||
name='skip_already_downloaded'
|
||||
path='settings.skip_already_downloaded'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Accordion.Content>
|
||||
</Accordion>
|
||||
}
|
||||
|
||||
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({
|
|||
<DownloadTagsSelector form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<AdvancedDownloadSettings form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
{showMessage && <SuccessfulDownloadSubmitMessage/>}
|
||||
<Grid.Row>
|
||||
<Grid.Column textAlign='right'>
|
||||
|
|
@ -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({
|
|||
<DestinationForm required form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<AdvancedDownloadSettings form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
{showMessage && <SuccessfulDownloadSubmitMessage/>}
|
||||
<Grid.Row>
|
||||
<Grid.Column textAlign='right'>
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue