diff --git a/app/src/components/Download.js b/app/src/components/Download.js index e045fa84..5ce4de7d 100644 --- a/app/src/components/Download.js +++ b/app/src/components/Download.js @@ -271,8 +271,13 @@ function VideoDownloadCountLimit({form, name = 'video_count_limit', path = 'sett /> } -export function VideoResolutionSelectorForm({form, name = 'video_resolutions', path = 'settings.video_resolutions'}) { - const [inputProps, inputAttrs] = form.getSelectionProps({name, path, type: 'array'}); +export function VideoResolutionSelectorForm({form, name = 'video_resolutions', path = 'settings.video_resolutions', onChange}) { + const [inputProps, inputAttrs] = form.getSelectionProps({ + name, + path, + type: 'array', + afterChange: onChange + }); return <> } -export function VideosDownloadForm({singleDownload = true, onCancel}) { +export function VideosDownloadForm({singleDownload = true, onCancel, onSuccess: propOnSuccess, download, submitter: propSubmitter, actions}) { const [showMessage, setShowMessage] = React.useState(false); + const [userChangedResolutions, setUserChangedResolutions] = React.useState(false); + const [config, setConfig] = React.useState(null); - // Keep video settings in session to help user start downloads consistently. - const [defaultVideoResolutions, setDefaultVideoResolutions] = useLocalStorage('video_resolutions', defaultVideoResolutionOptions); + // Keep video format in session to help user start downloads consistently. const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption); + // Use config video resolutions if available, otherwise use default + const configResolutions = config && config.video_resolutions ? config.video_resolutions : defaultVideoResolutionOptions; + const defaultFormData = { urls: '', // Textarea, one URL per line. destination: '', @@ -397,11 +406,11 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { settings: { use_browser_profile: false, video_format: defaultVideoFormat, - video_resolutions: defaultVideoResolutions, + video_resolutions: configResolutions, } } - const submitter = async (formData) => { + const submitter = propSubmitter || (async (formData) => { const downloadData = { destination: formData.destination, downloader: formData.downloader, @@ -410,24 +419,45 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { urls: formData.urls.split(/r?\n/), } await postDownload(downloadData); - } + }); const onSuccess = () => { setShowMessage(true); - form.reset(); + if (propOnSuccess) { + propOnSuccess(); + } else { + form.reset(); + } } const form = useForm({ submitter, - defaultFormData, + defaultFormData: download ? mergeDeep(defaultFormData, download) : defaultFormData, onSuccess, }); + // Fetch video downloader config when the modal opens React.useEffect(() => { - const {video_resolutions, video_format} = form.formData.settings; - if (video_resolutions && video_resolutions !== defaultVideoResolutions) { - setDefaultVideoResolutions(video_resolutions); - } + const fetchConfig = async () => { + try { + const result = await fetchVideoDownloaderConfig(); + setConfig(result); + + // Update form with video resolutions from config only if user hasn't changed them + // and if no download object was provided (this is a new download, not an edit) + if (result && result.video_resolutions && !userChangedResolutions && !download) { + form.setValue('settings.video_resolutions', result.video_resolutions); + } + } catch (error) { + console.error('Failed to fetch video downloader config:', error); + } + }; + + fetchConfig(); + }, []); + + React.useEffect(() => { + const {video_format} = form.formData.settings; if (video_format && video_format !== defaultVideoFormat) { setDefaultVideoFormat(video_format); } @@ -473,7 +503,10 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { - + setUserChangedResolutions(true)} + /> @@ -492,7 +525,7 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { {showMessage && } - + {actions ? actions({onCancel: localOnCancel, form}) : } @@ -511,6 +544,40 @@ export function VideoMinimumDurationForm({form}) { /> } +export function EditVideosDownloadForm({ + download, + onCancel, + onSuccess, + onDelete, + actions = EditDownloadFormButtons, +}) { + const submitter = async (formData) => { + // Create a copy of settings without channel_url and channel_id + const settings = {...formData.settings}; + // These settings are created when downloading the video, we can't submit them again. + delete settings.channel_url; + delete settings.channel_id; + + const downloadData = { + destination: formData.destination, + downloader: formData.downloader, + settings: settings, + tag_names: formData.tag_names, + urls: formData.urls.split(/r?\n/), + } + await putDownload(download.id, downloadData); + } + + return actions({...props, onDelete})} + /> +} + export function VideoMaximumDurationForm({form}) { return { @@ -557,10 +627,12 @@ export function ChannelDownloadForm({ } } - // Keep video settings in session to help user start downloads consistently. - const [defaultVideoResolutions, setDefaultVideoResolutions] = useLocalStorage('video_resolutions', defaultVideoResolutionOptions); + // Keep video format in session to help user start downloads consistently. const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption); + // Use config video resolutions if available, otherwise use default + const configResolutions = config && config.video_resolutions ? config.video_resolutions : defaultVideoResolutionOptions; + const emptyFormData = { destination: '', downloader: Downloaders.VideoChannel, @@ -577,7 +649,7 @@ export function ChannelDownloadForm({ use_browser_profile: false, video_count_limit: null, video_format: defaultVideoFormat, - video_resolutions: defaultVideoResolutions, + video_resolutions: configResolutions, }, sub_downloader: Downloaders.Video, tag_names: [], @@ -591,11 +663,30 @@ export function ChannelDownloadForm({ clearOnSuccess, }); + // Fetch video downloader config when the modal opens React.useEffect(() => { - const {video_resolutions, video_format} = form.formData.settings; - if (video_resolutions && video_resolutions !== defaultVideoResolutions) { - setDefaultVideoResolutions(video_resolutions); - } + const fetchConfig = async () => { + try { + const result = await fetchVideoDownloaderConfig(); + setConfig(result); + setIsConfigLoaded(true); + + // Update form with video resolutions from config only if user hasn't changed them + // and if no download object was provided (this is a new download, not an edit) + if (result && result.video_resolutions && !userChangedResolutions && !download) { + form.setValue('settings.video_resolutions', result.video_resolutions); + } + } catch (error) { + console.error('Failed to fetch video downloader config:', error); + setIsConfigLoaded(true); + } + }; + + fetchConfig(); + }, []); + + React.useEffect(() => { + const {video_format} = form.formData.settings; if (video_format && video_format !== defaultVideoFormat) { setDefaultVideoFormat(video_format); } @@ -656,7 +747,10 @@ export function ChannelDownloadForm({ - + setUserChangedResolutions(true)} + /> @@ -730,17 +824,42 @@ function SuccessfulDownloadSubmitMessage() { } -export function ArchiveDownloadForm({download, onCancel}) { - const [showMessage, setShowMessage] = React.useState(false); - +export function EditArchiveDownloadForm({ + download, + onCancel, + onSuccess, + onDelete, + actions = EditDownloadFormButtons, +}) { const submitter = async (formData) => { + const downloadData = { + downloader: formData.downloader, + tag_names: formData.tag_names, + urls: formData.urls.split(/\r?\n/), + } + await putDownload(download.id, downloadData); + } + + return actions({...props, onDelete})} + /> +} + +export function ArchiveDownloadForm({download, onCancel, onSuccess: propOnSuccess, submitter: propSubmitter, actions}) { + const [showMessage, setShowMessage] = React.useState(false); + + const submitter = propSubmitter || (async (formData) => { const downloadData = { downloader: formData.downloader, tag_names: formData.tag_names, urls: formData.urls.split(/\r?\n/), } await postDownload(downloadData); - }; + }); const emptyFormData = { downloader: Downloaders.Archive, @@ -748,14 +867,28 @@ export function ArchiveDownloadForm({download, onCancel}) { tag_names: [], }; + const onSuccess = () => { + setShowMessage(true); + if (propOnSuccess) { + propOnSuccess(); + } + } + const form = useForm({ submitter, defaultFormData: mergeDeep(emptyFormData, download), emptyFormData, - clearOnSuccess: true, - onSuccess: async () => setShowMessage(true), + clearOnSuccess: !propOnSuccess, + onSuccess, }); + const localOnCancel = (e) => { + if (e) e.preventDefault(); + if (onCancel) { + onCancel(); + } + } + return
Archives

Create a Singlefile Archive for each of the URLs provided below.

@@ -774,7 +907,7 @@ export function ArchiveDownloadForm({download, onCancel}) { {showMessage && } - + {actions ? actions({onCancel: localOnCancel, form}) : } @@ -783,8 +916,10 @@ export function ArchiveDownloadForm({download, onCancel}) { export function RSSDownloadForm({download, submitter, onDelete, onCancel, actions, clearOnSuccess = true}) { const [showMessage, setShowMessage] = React.useState(false); + const [config, setConfig] = React.useState(null); + const [isConfigLoaded, setIsConfigLoaded] = React.useState(false); + const [userChangedResolutions, setUserChangedResolutions] = React.useState(false); - const [defaultVideoResolutions, setDefaultVideoResolutions] = useLocalStorage('video_resolutions', defaultVideoResolutionOptions); const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption); submitter = submitter || (async (formData) => { @@ -800,6 +935,9 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action await postDownload(downloadData); }); + // Use config video resolutions if available, otherwise use default + const configResolutions = config && config.video_resolutions ? config.video_resolutions : defaultVideoResolutionOptions; + const emptyFormData = { destination: null, downloader: Downloaders.RSS, @@ -809,7 +947,7 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action excluded_urls: null, title_exclude: null, title_include: null, - video_resolutions: defaultVideoResolutions, + video_resolutions: configResolutions, video_format: defaultVideoFormat, }, tag_names: [], @@ -824,11 +962,30 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action onSuccess: async () => setShowMessage(true), }); + // Fetch video downloader config when the modal opens React.useEffect(() => { - const {video_resolutions, video_format} = form.formData.settings; - if (video_resolutions && video_resolutions !== defaultVideoResolutions) { - setDefaultVideoResolutions(video_resolutions); - } + const fetchConfig = async () => { + try { + const result = await fetchVideoDownloaderConfig(); + setConfig(result); + setIsConfigLoaded(true); + + // Update form with video resolutions from config only if user hasn't changed them + // and if no download object was provided (this is a new download, not an edit) + if (result && result.video_resolutions && !userChangedResolutions && !download) { + form.setValue('settings.video_resolutions', result.video_resolutions); + } + } catch (error) { + console.error('Failed to fetch video downloader config:', error); + setIsConfigLoaded(true); + } + }; + + fetchConfig(); + }, []); + + React.useEffect(() => { + const {video_format} = form.formData.settings; if (video_format && video_format !== defaultVideoFormat) { setDefaultVideoFormat(video_format); } @@ -859,7 +1016,10 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action - + setUserChangedResolutions(true)} + /> diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index cd594f3a..c2145e6a 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -93,6 +93,7 @@ function VideosPage() { {value: 'published_datetime', text: 'Published Date', short: 'P.Date'}, {value: 'length', text: 'Length'}, {value: 'size', text: 'Size'}, + {value: 'size_to_duration', text: 'Size to Duration', short: 'S/Duration'}, {value: 'view_count', text: 'Views'}, {value: 'viewed', text: 'Recently Viewed', short: 'R.Viewed'}, {value: 'download_datetime', text: 'Download Date', short: 'D.Date'}, diff --git a/app/src/components/admin/Downloads.js b/app/src/components/admin/Downloads.js index 9723eab3..6bee85c4 100644 --- a/app/src/components/admin/Downloads.js +++ b/app/src/components/admin/Downloads.js @@ -18,7 +18,7 @@ import { WROLModeMessage } from "../Common"; import { - Button as SButton, + Button as SButton, ButtonGroup, Label, Loader, PlaceholderLine, @@ -35,7 +35,9 @@ import { EditChannelDownloadForm, EditRSSDownloadForm, EditScrapeFilesDownloadForm, - EditZimDownloadForm + EditZimDownloadForm, + EditVideosDownloadForm, + EditArchiveDownloadForm } from "../Download"; import {Downloaders} from "../Vars"; @@ -246,6 +248,9 @@ function RecurringDownloadRow({download, fetchDownloads, onDelete}) { class OnceDownloadRow extends React.Component { constructor(props) { super(props); + this.state = { + editModalOpen: false + }; } handleDelete = async () => { @@ -272,8 +277,21 @@ class OnceDownloadRow extends React.Component { } }; + handleEditOpen = () => { + this.setState({ editModalOpen: true }); + }; + + handleEditClose = () => { + this.setState({ editModalOpen: false }); + }; + + handleEditSuccess = async () => { + await this.props.fetchDownloads(); + this.handleEditClose(); + }; + render() { - let {url, last_successful_download, status, location, error} = this.props; + let {url, last_successful_download, status, location, error, downloader, settings, id} = this.props; // Open downloads (/download), or external links in an anchor. const link = location && !location.startsWith('/download') ? @@ -297,6 +315,8 @@ class OnceDownloadRow extends React.Component { } else if (status === 'failed' || status === 'deferred') { buttonCell = ( + + + {(downloader === Downloaders.Video || downloader === Downloaders.Archive) && status !== 'pending' && ( +