mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Storing parent url for every child download, useful for knowing why WROLPi is downloading something. This is displayed on the Video and Archive download edit page. Updating Archive Download edit modal to use single url input.
This commit is contained in:
parent
308b1d9c88
commit
99a716aa13
6 changed files with 95 additions and 10 deletions
|
|
@ -856,6 +856,7 @@ export function EditArchiveDownloadForm({
|
|||
}
|
||||
|
||||
return <ArchiveDownloadForm
|
||||
singleDownload={true}
|
||||
download={download}
|
||||
onCancel={onCancel}
|
||||
onSuccess={onSuccess}
|
||||
|
|
@ -864,7 +865,7 @@ export function EditArchiveDownloadForm({
|
|||
/>
|
||||
}
|
||||
|
||||
export function ArchiveDownloadForm({download, onCancel, onSuccess: propOnSuccess, submitter: propSubmitter, actions}) {
|
||||
export function ArchiveDownloadForm({singleDownload = false, download, onCancel, onSuccess: propOnSuccess, submitter: propSubmitter, actions}) {
|
||||
const [showMessage, setShowMessage] = React.useState(false);
|
||||
|
||||
const submitter = propSubmitter || (async (formData) => {
|
||||
|
|
@ -904,6 +905,10 @@ export function ArchiveDownloadForm({download, onCancel, onSuccess: propOnSucces
|
|||
}
|
||||
}
|
||||
|
||||
const urlInput = singleDownload ?
|
||||
<UrlInput required form={form} path='urls'/>
|
||||
: <UrlsTextarea required form={form}/>;
|
||||
|
||||
return <Form>
|
||||
<Header as='h3'><Icon name='file text' color='green'/> Archives</Header>
|
||||
<p>Create a Singlefile Archive for each of the URLs provided below.</p>
|
||||
|
|
@ -911,7 +916,7 @@ export function ArchiveDownloadForm({download, onCancel, onSuccess: propOnSucces
|
|||
<Grid stackable columns={1}>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<UrlsTextarea required form={form}/>
|
||||
{urlInput}
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
|
|
|
|||
|
|
@ -285,6 +285,7 @@ function OnceDownloadRow({download, fetchDownloads, isSelected, onSelect}) {
|
|||
const [editModalOpen, setEditModalOpen] = React.useState(false);
|
||||
|
||||
const {url, last_successful_download, status, location, error, downloader, settings, id, tag_names} = download;
|
||||
const parentDownloadUrl = settings?.parent_download_url;
|
||||
|
||||
const handleDelete = async () => {
|
||||
try {
|
||||
|
|
@ -328,13 +329,23 @@ function OnceDownloadRow({download, fetchDownloads, isSelected, onSelect}) {
|
|||
if (status === 'pending' || status === 'new') {
|
||||
buttonCell = (
|
||||
<TableCell>
|
||||
<APIButton
|
||||
color='red'
|
||||
onClick={handleStop}
|
||||
confirmContent='Are you sure you want to stop this download? It will not be retried.'
|
||||
confirmButton='Stop'
|
||||
obeyWROLMode={true}
|
||||
>Stop</APIButton>
|
||||
<ButtonGroup>
|
||||
<APIButton
|
||||
color='red'
|
||||
icon='stop circle'
|
||||
onClick={handleStop}
|
||||
confirmContent='Are you sure you want to stop this download? It will not be retried.'
|
||||
confirmButton='Stop'
|
||||
obeyWROLMode={true}
|
||||
/>
|
||||
{status === 'new' && (downloader === Downloaders.Video || downloader === Downloaders.Archive) && (
|
||||
<Button
|
||||
icon='edit'
|
||||
color='blue'
|
||||
onClick={handleEditOpen}
|
||||
/>
|
||||
)}
|
||||
</ButtonGroup>
|
||||
</TableCell>
|
||||
);
|
||||
} else if (status === 'failed' || status === 'deferred') {
|
||||
|
|
@ -411,6 +422,13 @@ function OnceDownloadRow({download, fetchDownloads, isSelected, onSelect}) {
|
|||
onSuccess={handleEditSuccess}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
{parentDownloadUrl && (
|
||||
<p style={{marginTop: '1em', color: '#666'}}>
|
||||
From: <a href={parentDownloadUrl} target='_blank' rel='noopener noreferrer'>
|
||||
{parentDownloadUrl}
|
||||
</a>
|
||||
</p>
|
||||
)}
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
);
|
||||
|
|
@ -433,6 +451,13 @@ function OnceDownloadRow({download, fetchDownloads, isSelected, onSelect}) {
|
|||
onSuccess={handleEditSuccess}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
{parentDownloadUrl && (
|
||||
<p style={{marginTop: '1em', color: '#666'}}>
|
||||
From: <a href={parentDownloadUrl} target='_blank' rel='noopener noreferrer'>
|
||||
{parentDownloadUrl}
|
||||
</a>
|
||||
</p>
|
||||
)}
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -177,6 +177,7 @@ async def test_download_channel(test_session, test_directory, simple_channel, vi
|
|||
'collection_id': simple_channel.collection_id,
|
||||
'channel_url': 'https://www.youtube.com/c/LearningSelfReliance/videos',
|
||||
'destination': str(test_directory),
|
||||
'parent_download_url': url,
|
||||
}
|
||||
|
||||
reset_downloads()
|
||||
|
|
@ -195,6 +196,7 @@ async def test_download_channel(test_session, test_directory, simple_channel, vi
|
|||
'collection_id': simple_channel.collection_id,
|
||||
'channel_url': 'https://www.youtube.com/c/LearningSelfReliance/videos',
|
||||
'destination': str(test_directory),
|
||||
'parent_download_url': url,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1265,8 +1265,10 @@ async def signal_download_download(download_id: int, download_url: str):
|
|||
urls = download.filter_excluded(result.downloads) if result.downloads else None
|
||||
if urls:
|
||||
worker_logger.info(f'Adding {len(result.downloads)} downloads from result of {download.url}')
|
||||
child_settings = dict(result.settings) if result.settings else {}
|
||||
child_settings['parent_download_url'] = download.url
|
||||
download_manager.create_downloads(session, urls, downloader_name=download.sub_downloader,
|
||||
settings=result.settings)
|
||||
settings=child_settings)
|
||||
|
||||
if try_again is False and not download.frequency:
|
||||
# Only once-downloads can fail.
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@ class DownloadSettings:
|
|||
video_count_limit: Optional[int] = None
|
||||
video_format: Optional[str] = None
|
||||
video_resolutions: List[str] = field(default_factory=list)
|
||||
parent_download_url: Optional[str] = None
|
||||
|
||||
def __post_init__(self):
|
||||
if self.excluded_urls and self.excluded_urls.endswith(','):
|
||||
|
|
|
|||
|
|
@ -802,3 +802,53 @@ async def test_batch_api_endpoints(async_client, test_session, test_download_man
|
|||
body = dict(download_ids=[])
|
||||
request, response = await async_client.post('/api/download/batch/delete', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_child_downloads_have_parent_download_url(test_session, test_download_manager, test_downloader):
|
||||
"""Child downloads spawned by a parent download should have parent_download_url set in their settings."""
|
||||
import asyncio
|
||||
from wrolpi.downloader import DownloadResult
|
||||
|
||||
parent_url = 'https://example.com/parent'
|
||||
child_urls = ['https://example.com/child1', 'https://example.com/child2']
|
||||
|
||||
# Track which URLs have been processed to avoid returning children for child downloads
|
||||
processed_urls = set()
|
||||
|
||||
# Configure the test_downloader to return child downloads only for the parent URL
|
||||
async def download_with_children(download, *a, **kwargs):
|
||||
await asyncio.sleep(0.1)
|
||||
if download.url == parent_url and parent_url not in processed_urls:
|
||||
processed_urls.add(parent_url)
|
||||
return DownloadResult(success=True, downloads=child_urls)
|
||||
# Return success without children for child downloads
|
||||
return DownloadResult(success=True)
|
||||
|
||||
test_downloader.do_download.side_effect = download_with_children
|
||||
|
||||
# Create the parent download with a sub_downloader specified
|
||||
test_download_manager.create_download(test_session, parent_url, test_downloader.name,
|
||||
sub_downloader_name=test_downloader.name)
|
||||
test_session.commit()
|
||||
|
||||
# Wait for the parent download to complete and create child downloads
|
||||
await test_download_manager.wait_for_all_downloads()
|
||||
|
||||
# Get all downloads
|
||||
downloads = test_session.query(Download).all()
|
||||
assert len(downloads) == 3, f'Expected 3 downloads (1 parent + 2 children), got {len(downloads)}'
|
||||
|
||||
# Find parent and child downloads
|
||||
parent_download = next((d for d in downloads if d.url == parent_url), None)
|
||||
child_downloads = [d for d in downloads if d.url in child_urls]
|
||||
|
||||
assert parent_download is not None, 'Parent download not found'
|
||||
assert len(child_downloads) == 2, f'Expected 2 child downloads, got {len(child_downloads)}'
|
||||
|
||||
# Verify child downloads have parent_download_url in their settings
|
||||
for child in child_downloads:
|
||||
assert child.settings is not None, f'Child download {child.url} has no settings'
|
||||
assert 'parent_download_url' in child.settings, f'Child download {child.url} missing parent_download_url'
|
||||
assert child.settings['parent_download_url'] == parent_url, \
|
||||
f'Child download {child.url} has wrong parent_download_url: {child.settings.get("parent_download_url")}'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue