Unifying video download settings so that global/channel/rss/video

download settings have inheritance.  Allowing more granular control of
potentially failed downloads.
This commit is contained in:
Roland 2026-03-05 16:18:03 -07:00
parent 6be6fe6e19
commit 0ffbc05e91
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
13 changed files with 683 additions and 71 deletions

View file

@ -197,6 +197,11 @@ textarea.otp {
color: #DDDDDD !important;
}
.ui.inverted.accordion .title,
.ui.inverted.accordion .content {
background-color: #171616 !important;
}
/* Mobile-responsive Confirm modal */
.ui.modal.themed-confirm {
max-width: 95vw;

View file

@ -421,6 +421,11 @@ export async function fetchVideoDownloaderConfig() {
return await getConfig('videos_downloader.yaml');
}
export async function fetchVideoDownloadDefaults() {
const response = await apiGet(`${VIDEOS_API}/download-defaults`);
return await response.json();
}
export async function updateConfig(fileName, config) {
const body = {config};
const response = await apiPost(`${API_URI}/config?file_name=${fileName}`, body);

View file

@ -1,5 +1,5 @@
import React, {useState} from "react";
import {fetchVideoDownloaderConfig, getDownloaders, postDownload, putDownload} from "../api";
import {fetchVideoDownloadDefaults, getDownloaders, postDownload, putDownload} from "../api";
import {
APIButton,
DirectorySearch,
@ -11,7 +11,7 @@ import {
} from "./Common";
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
import {Button, Form, Header} from "./Theme";
import {Accordion, Button, Form, Header} from "./Theme";
import {Form as SForm, FormDropdown} from "semantic-ui-react";
import {Link} from "react-router";
import {TagsSelector} from "../Tags";
@ -298,7 +298,7 @@ export function VideoResolutionSelectorForm({
</>
}
function VideoFormatSelectorForm({form, name = 'video_format', path = 'settings.video_format'}) {
export function VideoFormatSelectorForm({form, name = 'video_format', path = 'settings.video_format'}) {
const [inputProps, inputAttrs] = form.getSelectionProps({
name,
path,
@ -359,6 +359,116 @@ export function ChannelTagNameForm({form}) {
</>
}
function AdvancedVideoSettings({form, isVideoLevel = false, isConfigLoaded = true}) {
const [active, setActive] = React.useState(false);
if (!isConfigLoaded) return null;
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={2}>
<Grid.Column>
<ToggleForm
form={form}
label='Download subtitles'
name='writesubtitles'
path='settings.writesubtitles'
icon='closed captioning outline'
/>
</Grid.Column>
<Grid.Column>
<ToggleForm
form={form}
label='Download automatic subtitles'
name='writeautomaticsub'
path='settings.writeautomaticsub'
icon='closed captioning'
/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={2}>
<Grid.Column>
<ToggleForm
form={form}
label='Download thumbnail'
name='writethumbnail'
path='settings.writethumbnail'
icon='image'
/>
</Grid.Column>
<Grid.Column>
<ToggleForm
form={form}
label='Download info JSON'
name='writeinfojson'
path='settings.writeinfojson'
icon='file code'
/>
</Grid.Column>
</Grid.Row>
{isVideoLevel &&
<Grid.Row columns={2}><Grid.Column>
<ToggleForm
form={form}
label='Continue partial downloads'
name='continue_dl'
path='settings.continue_dl'
icon='play'
/>
</Grid.Column>
<Grid.Column>
<ToggleForm
form={form}
label='Do not overwrite existing files'
name='nooverwrites'
path='settings.nooverwrites'
icon='file video'
/>
</Grid.Column>
</Grid.Row>}
<Grid.Row columns={2}>
<Grid.Column>
<NumberInputForm
form={form}
label='Sleep between requests (seconds)'
name='sleep_requests'
path='settings.sleep_requests'
placeholder='0.75'
min={0}
max={60}
/>
</Grid.Column>
<Grid.Column>
<InputForm
form={form}
label='User agent'
name='user_agent'
path='settings.user_agent'
placeholder='Mozilla/5.0...'
/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={1}>
<Grid.Column>
<InputForm
form={form}
label='Extra yt-dlp arguments'
name='yt_dlp_extra_args'
path='settings.yt_dlp_extra_args'
placeholder='--no-playlist --geo-bypass'
/>
</Grid.Column>
</Grid.Row>
</Grid>
</Accordion.Content>
</Accordion>
}
export function VideosDownloadForm({
singleDownload = true,
onCancel,
@ -370,6 +480,7 @@ export function VideosDownloadForm({
const [showMessage, setShowMessage] = React.useState(false);
const [userChangedResolutions, setUserChangedResolutions] = React.useState(false);
const [config, setConfig] = React.useState(null);
const [isConfigLoaded, setIsConfigLoaded] = React.useState(false);
// Keep video format in session to help user start downloads consistently.
const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption);
@ -385,6 +496,15 @@ export function VideosDownloadForm({
settings: {
video_format: defaultVideoFormat,
video_resolutions: configResolutions,
writesubtitles: false,
writeautomaticsub: false,
writethumbnail: false,
writeinfojson: false,
yt_dlp_extra_args: '',
sleep_requests: '',
user_agent: '',
continue_dl: false,
nooverwrites: false,
}
}
@ -414,25 +534,43 @@ export function VideosDownloadForm({
onSuccess,
});
// Fetch video downloader config when the modal opens
// Fetch global defaults to pre-fill the form
React.useEffect(() => {
const fetchConfig = async () => {
const fetchDefaults = async () => {
try {
const result = await fetchVideoDownloaderConfig();
setConfig(result);
const defaults = await fetchVideoDownloadDefaults();
setConfig(defaults);
// Update form with video resolutions from config only if user hasn't changed them
// and if the download doesn't already have video_resolutions set
const downloadHasResolutions = download?.settings?.video_resolutions?.length > 0;
if (result && result.video_resolutions && !userChangedResolutions && !downloadHasResolutions) {
form.setValue('settings.video_resolutions', result.video_resolutions);
if (defaults && download) {
// Edit mode: only fill settings not already in the download
for (const [key, value] of Object.entries(defaults)) {
if (download.settings?.[key] === undefined || download.settings?.[key] === null) {
form.setValue(`settings.${key}`, value);
}
}
} else if (defaults) {
// New download: pre-fill all settings from global defaults
const downloadHasResolutions = download?.settings?.video_resolutions?.length > 0;
for (const [key, value] of Object.entries(defaults)) {
if (key === 'video_resolutions' && (userChangedResolutions || downloadHasResolutions)) {
continue;
}
if (key === 'video_format') {
continue; // Handled by localStorage default
}
form.setValue(`settings.${key}`, value);
}
if (!userChangedResolutions && !downloadHasResolutions && defaults.video_resolutions) {
form.setValue('settings.video_resolutions', defaults.video_resolutions);
}
}
} catch (error) {
console.error('Failed to fetch video downloader config:', error);
console.error('Failed to fetch video download defaults:', error);
}
setIsConfigLoaded(true);
};
fetchConfig();
fetchDefaults();
}, []);
React.useEffect(() => {
@ -496,6 +634,11 @@ export function VideosDownloadForm({
<ChannelTagNameForm form={form}/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={1}>
<Grid.Column>
<AdvancedVideoSettings form={form} isVideoLevel={true} isConfigLoaded={isConfigLoaded}/>
</Grid.Column>
</Grid.Row>
{showMessage && <SuccessfulDownloadSubmitMessage/>}
<Grid.Row>
<Grid.Column>
@ -625,6 +768,13 @@ export function ChannelDownloadForm({
video_count_limit: null,
video_format: defaultVideoFormat,
video_resolutions: configResolutions,
writesubtitles: false,
writeautomaticsub: false,
writethumbnail: false,
writeinfojson: false,
yt_dlp_extra_args: '',
sleep_requests: '',
user_agent: '',
},
sub_downloader: Downloaders.Video,
tag_names: [],
@ -638,27 +788,42 @@ export function ChannelDownloadForm({
clearOnSuccess,
});
// Fetch video downloader config when the modal opens
// Fetch global defaults to pre-fill the form
React.useEffect(() => {
const fetchConfig = async () => {
const fetchDefaults = async () => {
try {
const result = await fetchVideoDownloaderConfig();
setConfig(result);
const defaults = await fetchVideoDownloadDefaults();
setConfig(defaults);
setIsConfigLoaded(true);
// Update form with video resolutions from config only if user hasn't changed them
// and if the download doesn't already have video_resolutions set
const downloadHasResolutions = download?.settings?.video_resolutions?.length > 0;
if (result && result.video_resolutions && !userChangedResolutions && !downloadHasResolutions) {
form.setValue('settings.video_resolutions', result.video_resolutions);
if (defaults && download) {
// Edit mode: only fill settings not already in the download
for (const [key, value] of Object.entries(defaults)) {
if (key === 'continue_dl' || key === 'nooverwrites') continue;
if (download.settings?.[key] === undefined || download.settings?.[key] === null) {
form.setValue(`settings.${key}`, value);
}
}
} else if (defaults) {
// New download: pre-fill all inheritable settings from global defaults
const downloadHasResolutions = download?.settings?.video_resolutions?.length > 0;
for (const [key, value] of Object.entries(defaults)) {
if (key === 'continue_dl' || key === 'nooverwrites') continue;
if (key === 'video_resolutions' && (userChangedResolutions || downloadHasResolutions)) continue;
if (key === 'video_format') continue;
form.setValue(`settings.${key}`, value);
}
if (!userChangedResolutions && !downloadHasResolutions && defaults.video_resolutions) {
form.setValue('settings.video_resolutions', defaults.video_resolutions);
}
}
} catch (error) {
console.error('Failed to fetch video downloader config:', error);
console.error('Failed to fetch video download defaults:', error);
setIsConfigLoaded(true);
}
};
fetchConfig();
fetchDefaults();
}, []);
React.useEffect(() => {
@ -745,6 +910,11 @@ export function ChannelDownloadForm({
<ChannelTagNameForm form={form}/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={1}>
<Grid.Column>
<AdvancedVideoSettings form={form} isConfigLoaded={isConfigLoaded}/>
</Grid.Column>
</Grid.Row>
{showMessage && <SuccessfulDownloadSubmitMessage/>}
<Grid.Row>
<Grid.Column textAlign='right'>
@ -828,7 +998,14 @@ export function EditArchiveDownloadForm({
/>
}
export function ArchiveDownloadForm({singleDownload = false, 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) => {
@ -933,6 +1110,13 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action
title_include: null,
video_resolutions: configResolutions,
video_format: defaultVideoFormat,
writesubtitles: false,
writeautomaticsub: false,
writethumbnail: false,
writeinfojson: false,
yt_dlp_extra_args: '',
sleep_requests: '',
user_agent: '',
},
tag_names: [],
url: '',
@ -946,27 +1130,40 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action
onSuccess: async () => setShowMessage(true),
});
// Fetch video downloader config when the modal opens
// Fetch global defaults to pre-fill the form
React.useEffect(() => {
const fetchConfig = async () => {
const fetchDefaults = async () => {
try {
const result = await fetchVideoDownloaderConfig();
setConfig(result);
const defaults = await fetchVideoDownloadDefaults();
setConfig(defaults);
setIsConfigLoaded(true);
// Update form with video resolutions from config only if user hasn't changed them
// and if the download doesn't already have video_resolutions set
const downloadHasResolutions = download?.settings?.video_resolutions?.length > 0;
if (result && result.video_resolutions && !userChangedResolutions && !downloadHasResolutions) {
form.setValue('settings.video_resolutions', result.video_resolutions);
if (defaults && download) {
for (const [key, value] of Object.entries(defaults)) {
if (key === 'continue_dl' || key === 'nooverwrites') continue;
if (download.settings?.[key] === undefined || download.settings?.[key] === null) {
form.setValue(`settings.${key}`, value);
}
}
} else if (defaults) {
const downloadHasResolutions = download?.settings?.video_resolutions?.length > 0;
for (const [key, value] of Object.entries(defaults)) {
if (key === 'continue_dl' || key === 'nooverwrites') continue;
if (key === 'video_resolutions' && (userChangedResolutions || downloadHasResolutions)) continue;
if (key === 'video_format') continue;
form.setValue(`settings.${key}`, value);
}
if (!userChangedResolutions && !downloadHasResolutions && defaults.video_resolutions) {
form.setValue('settings.video_resolutions', defaults.video_resolutions);
}
}
} catch (error) {
console.error('Failed to fetch video downloader config:', error);
console.error('Failed to fetch video download defaults:', error);
setIsConfigLoaded(true);
}
};
fetchConfig();
fetchDefaults();
}, []);
React.useEffect(() => {
@ -1018,6 +1215,11 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action
<VideoMaximumDurationForm form={form}/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={1}>
<Grid.Column>
<AdvancedVideoSettings form={form} isConfigLoaded={isConfigLoaded}/>
</Grid.Column>
</Grid.Row>
</>;
} else if (form.formData.sub_downloader === Downloaders.Archive) {
downloaderRows = <Grid.Row>

View file

@ -2,6 +2,8 @@ import React, {useContext, useEffect, useState, forwardRef, HTMLAttributes, CSSP
import {ThemeContext} from "../contexts/contexts";
import {
Accordion as SAccordion,
AccordionContent as SAccordionContent,
AccordionTitle as SAccordionTitle,
Breadcrumb as SBreadcrumb,
Button as SButton,
ButtonGroup as SButtonGroup,
@ -36,7 +38,9 @@ import {
TableRow as STableRow,
TabPane as STabPane,
TextArea as STextArea,
AccordionContentProps,
AccordionProps,
AccordionTitleProps,
BreadcrumbProps,
ButtonProps,
ButtonGroupProps,
@ -218,11 +222,36 @@ const defaultGrey = <T extends object>(props: T, inverted: boolean): T => {
return props;
}
export function Accordion(props: AccordionProps) {
// ----------------------------------------------------------------------------
// Accordion Compound Component
// ----------------------------------------------------------------------------
type AccordionTitleComponent = React.FC<AccordionTitleProps>;
type AccordionContentComponent = React.FC<AccordionContentProps>;
interface AccordionComponent extends React.FC<AccordionProps> {
Title: AccordionTitleComponent;
Content: AccordionContentComponent;
}
const AccordionTitle: AccordionTitleComponent = (props) => {
return <SAccordionTitle {...props}/>
};
const AccordionContent: AccordionContentComponent = (props) => {
return <SAccordionContent {...props}/>
};
const AccordionBase: React.FC<AccordionProps> = (props) => {
const {i, inverted} = useContext(ThemeContext);
const mergedProps = defaultGrey({...i, ...props}, !!inverted);
return <SAccordion {...mergedProps}/>
}
};
export const Accordion: AccordionComponent = Object.assign(AccordionBase, {
Title: AccordionTitle,
Content: AccordionContent,
});
// ----------------------------------------------------------------------------
// Button Compound Component

View file

@ -67,7 +67,7 @@ import {Media, QueryContext, ThemeContext} from "../contexts/contexts";
import _ from "lodash";
import {defaultFileOrder, defaultSearchOrder, HELP_VIEWER_URI} from "./Vars";
import {InputForm, ToggleForm, useForm} from "../hooks/useForm";
import {VideoResolutionSelectorForm} from "./Download";
import {VideoFormatSelectorForm, VideoResolutionSelectorForm} from "./Download";
import {BatchReorganizeModal} from "./collections/BatchReorganizeModal";
export function VideoWrapper() {
@ -332,9 +332,12 @@ function VideosSettingsPage() {
const emptyFormData = {
video_resolutions: ['1080p', '720p', '480p', 'maximum'],
yt_dlp_options: {
continue_dl: true,
file_name_format: '%(uploader)s_%(upload_date)s_%(id)s_%(title)s.%(ext)s',
merge_output_format: 'mp4',
nooverwrites: true,
writeautomaticsub: true,
writeinfojson: true,
writesubtitles: true,
writethumbnail: true,
},
@ -384,7 +387,14 @@ function VideosSettingsPage() {
path='video_resolutions'
/>
</Grid.Column>
<Grid.Column mobile={16} computer={8}>
<Grid.Column mobile={16} computer={4}>
<VideoFormatSelectorForm
form={configForm}
name='merge_output_format'
path='yt_dlp_options.merge_output_format'
/>
</Grid.Column>
<Grid.Column mobile={16} computer={4}>
<VideoFileNameForm form={configForm}/>
</Grid.Column>
</Grid.Row>
@ -408,7 +418,7 @@ function VideosSettingsPage() {
/>
</Grid.Column>
</Grid.Row>
<Grid.Row>
<Grid.Row columns={2}>
<Grid.Column mobile={16} computer={8}>
<ToggleForm
form={configForm}
@ -428,6 +438,26 @@ function VideosSettingsPage() {
/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={2}>
<Grid.Column mobile={16} computer={8}>
<ToggleForm
form={configForm}
label='Download info JSON'
name='writeinfojson'
path='yt_dlp_options.writeinfojson'
icon='file code'
/>
</Grid.Column>
<Grid.Column mobile={16} computer={8}>
<ToggleForm
form={configForm}
label='Continue partial downloads'
name='continue_dl'
path='yt_dlp_options.continue_dl'
icon='play'
/>
</Grid.Column>
</Grid.Row>
<Grid.Row>
<Grid.Column mobile={16} computer={8}>
<ToggleForm