A user can define a destination when creating a channel/playlist download. This destination is then sent to VideoDownloader.

This commit is contained in:
Roland 2023-08-17 17:53:29 -06:00
parent 027d305abb
commit 7f54e592ed
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
4 changed files with 66 additions and 13 deletions

View file

@ -752,12 +752,12 @@ export function mimetypeColor(mimetype) {
return 'pink'
} else if (mimetype.startsWith('text/html')) {
return 'green'
} else if (mimetype.startsWith('application/zip') || mimetype.startsWith('application/zlib') || mimetype.startsWith('application/x-7z-compressed') || mimetype.startsWith('application/x-bzip2') || mimetype.startsWith('application/x-xz')) {
return 'purple'
} else if (mimetype.startsWith('application/epub') || mimetype.startsWith('application/x-mobipocket-ebook')) {
} else if (mimetype.startsWith('application/epub')) {
return 'yellow'
} else if (mimetype.startsWith('audio/')) {
return 'violet'
} else if (isZipMimetype(mimetype)) {
return 'purple'
}
} catch (e) {
console.error(e);

View file

@ -161,7 +161,15 @@ class ChannelDownload extends React.Component {
constructor(props) {
super(props);
this.state = {
url: '', frequency: 604800, pending: false, disabled: false, ready: false, error: null, success: null,
advancedOpen: false,
destination: null,
disabled: false,
error: null,
frequency: 604800,
pending: false,
ready: false,
success: null,
url: '',
};
this.freqOptions = [{key: 'once', text: 'Once', value: 0}, ...frequencyOptions.slice(1),];
this.handleUrlChange = this.handleUrlChange.bind(this);
@ -181,12 +189,13 @@ class ChannelDownload extends React.Component {
handleSubmit = async () => {
this.setState({disabled: true, pending: true, success: null, error: null});
const {url, frequency} = this.state;
const {url, frequency, destination} = this.state;
if (!url) {
this.setState({error: 'URL is required'});
return;
}
let response = await postDownload(url, 'video_channel', frequency);
let response = await postDownload(url, 'video_channel', frequency,
null, null, destination);
if (response.status === 204) {
this.setState({pending: false, disabled: false, success: true, url: '', ready: false});
} else {
@ -196,8 +205,15 @@ class ChannelDownload extends React.Component {
}
}
toggleAdvancedAccordion = (e) => {
if (e) {
e.preventDefault();
}
this.setState({advancedOpen: !this.state.advancedOpen});
}
render() {
const {ready, disabled, url, error, frequency, pending, success} = this.state;
const {advancedOpen, ready, disabled, url, error, frequency, pending, success} = this.state;
const buttonDisabled = !ready || disabled;
const onceMessage = (<Message>
@ -207,6 +223,17 @@ class ChannelDownload extends React.Component {
in the future.</Message.Content>
</Message>);
const directorySearch = <div style={{marginTop: '1em'}}>
<SForm.Field>
<label>
Destination
<HelpPopup
content="Always download videos into this directory, rather than the Channel's directory."/>
</label>
<DirectorySearch onSelect={i => this.setState({destination: i})}/>
</SForm.Field>
</div>;
return <Form>
<WROLModeMessage content='Downloading is disabled while WROL Mode is enabled'/>
<Header as='h4'><Icon name='film' color='blue'/> Channel / Playlist</Header>
@ -232,6 +259,18 @@ class ChannelDownload extends React.Component {
{frequency === 0 && onceMessage}
<Accordion>
<AccordionTitle active={advancedOpen} onClick={this.toggleAdvancedAccordion}>
<Icon name='dropdown'/>
Advanced
</AccordionTitle>
<AccordionContent active={advancedOpen}>
{directorySearch}
</AccordionContent>
</Accordion>
<br/>
<Button content='Cancel' onClick={this.props.clearSelected}/>
<APIButton
onClick={this.handleSubmit}

View file

@ -78,7 +78,7 @@ def video_cleanup():
SET
channel_id = c.id
FROM channel c
LEFT JOIN file_group fg ON fg.primary_path LIKE c.directory || '/%'::VARCHAR
LEFT JOIN file_group fg ON fg.primary_path LIKE c.directory || '/%'::VARCHAR
WHERE
v.channel_id IS NULL
AND fg.id = v.file_group_id

View file

@ -103,7 +103,15 @@ class ChannelDownloader(Downloader, ABC):
channel.dict() # get all attributes while we have the session.
location = f'/videos/channel/{channel.id}/video' if channel and channel.id else None
settings = dict(channel_id=channel.id, channel_url=download.url) if channel else None
# The settings to send to the VideoDownloader.
settings = dict()
if channel:
settings.update(dict(channel_id=channel.id, channel_url=download.url))
# Downloads will inherit the destination, if defined.
destination = download.settings.get('destination') if download.settings else None
if destination:
settings['destination'] = destination
is_a_playlist = self.is_a_playlist(info)
try:
@ -211,15 +219,19 @@ class VideoDownloader(Downloader, ABC):
pass
settings = download.settings or dict()
destination = settings.get('destination')
if not channel and destination:
# Destination may override the real Channel.
channel = get_channel(directory=destination, return_dict=False)
found_channel = 'download_settings_directory'
local_channel_id = settings.get('channel_id')
channel_url = settings.get('channel_url')
destination = settings.get('destination')
if not channel and (local_channel_id or channel_url or destination):
if not channel and (local_channel_id or channel_url):
# Could not find channel via yt-dlp info_json, use info from ChannelDownloader if it created this Download.
logger.info(f'Using download.settings to find channel')
try:
channel = get_channel(channel_id=local_channel_id, url=channel_url, directory=destination,
return_dict=False)
channel = get_channel(channel_id=local_channel_id, url=channel_url, return_dict=False)
except UnknownChannel:
# We do not need a Channel if we have a destination directory.
if not destination:
@ -234,6 +246,8 @@ class VideoDownloader(Downloader, ABC):
logger.debug(f'Found {channel} using yt_dlp')
elif found_channel == 'download_settings':
logger.info(f'Found {channel} using Download.settings')
elif found_channel == 'download_settings_directory':
logger.info(f'Found {channel} using Download.settings directory')
else:
logger.warning('Could not find channel')