mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 09:56:17 -05:00
Searching wrolpi user's home directory for browser profiles.
This commit is contained in:
parent
d8ccebf9bb
commit
00c86e1a1a
22 changed files with 472 additions and 138 deletions
|
|
@ -1,14 +1,6 @@
|
|||
import React, {useState} from "react";
|
||||
import {getDownloaders, postDownload, putDownload} from "../api";
|
||||
import {
|
||||
APIButton,
|
||||
DirectorySearch,
|
||||
InfoHeader,
|
||||
InfoPopup,
|
||||
mergeDeep,
|
||||
RequiredAsterisk,
|
||||
useLocalStorage
|
||||
} from "./Common";
|
||||
import {fetchVideoDownloaderConfig, getDownloaders, postDownload, putDownload} from "../api";
|
||||
import {APIButton, DirectorySearch, InfoHeader, InfoPopup, mergeDeep, RequiredAsterisk, useLocalStorage} 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, FormInput, Header} from "./Theme";
|
||||
|
|
@ -16,7 +8,7 @@ import {Form as SForm, FormDropdown} from "semantic-ui-react";
|
|||
import {Link} from "react-router-dom";
|
||||
import {TagsSelector} from "../Tags";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import {commaSeparatedValidator, InputForm, NumberInputForm, UrlInput, UrlsTextarea, useForm} from "../hooks/useForm";
|
||||
import {commaSeparatedValidator, InputForm, NumberInputForm, ToggleForm, UrlInput, UrlsTextarea, useForm} from "../hooks/useForm";
|
||||
import {
|
||||
channelFrequencyOptions,
|
||||
days30Option,
|
||||
|
|
@ -263,7 +255,7 @@ 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});
|
||||
const [inputProps, inputAttrs] = form.getSelectionProps({name, path, type: 'array'});
|
||||
|
||||
return <>
|
||||
<InfoHeader
|
||||
|
|
@ -341,6 +333,34 @@ export function ChannelTagNameForm({form}) {
|
|||
</>
|
||||
}
|
||||
|
||||
export function UseBrowserProfile({form}) {
|
||||
const [config, setConfig] = useState(null);
|
||||
|
||||
const localFetchConfig = async () => {
|
||||
const result = await fetchVideoDownloaderConfig();
|
||||
setConfig(result);
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
localFetchConfig();
|
||||
}, []);
|
||||
|
||||
const popupContent = <>Use the browser profile to download videos.
|
||||
This is useful for downloading videos that require a login. See: <i>Videos > Settings</i></>;
|
||||
const label = <InfoHeader
|
||||
headerSize='h4'
|
||||
headerContent='Use Browser Profile'
|
||||
popupContent={popupContent}
|
||||
/>;
|
||||
return <ToggleForm
|
||||
form={form}
|
||||
label={label}
|
||||
disabled={!config?.browser_profile}
|
||||
name='use_browser_profile'
|
||||
path='settings.use_browser_profile'
|
||||
/>
|
||||
}
|
||||
|
||||
export function VideosDownloadForm({singleDownload = true, onCancel}) {
|
||||
const [showMessage, setShowMessage] = React.useState(false);
|
||||
|
||||
|
|
@ -354,8 +374,9 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) {
|
|||
tag_names: [],
|
||||
downloader: Downloaders.Video,
|
||||
settings: {
|
||||
video_resolutions: defaultVideoResolutions,
|
||||
use_browser_profile: false,
|
||||
video_format: defaultVideoFormat,
|
||||
video_resolutions: defaultVideoResolutions,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -437,6 +458,11 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) {
|
|||
<VideoFormatSelectorForm form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<UseBrowserProfile form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<ChannelTagNameForm form={form}/>
|
||||
|
|
@ -527,9 +553,10 @@ export function ChannelDownloadForm({
|
|||
minimum_duration: null,
|
||||
title_exclude: null,
|
||||
title_include: null,
|
||||
use_browser_profile: false,
|
||||
video_count_limit: null,
|
||||
video_resolutions: defaultVideoResolutions,
|
||||
video_format: defaultVideoFormat,
|
||||
video_resolutions: defaultVideoResolutions,
|
||||
},
|
||||
sub_downloader: Downloaders.Video,
|
||||
tag_names: [],
|
||||
|
|
@ -622,6 +649,11 @@ export function ChannelDownloadForm({
|
|||
<VideoMaximumDurationForm form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<UseBrowserProfile form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<ChannelTagNameForm form={form}/>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
findPosterPath,
|
||||
humanFileSize,
|
||||
humanNumber,
|
||||
InfoHeader,
|
||||
isoDatetimeToAgoPopup,
|
||||
mimetypeColor,
|
||||
PageContainer,
|
||||
|
|
@ -30,6 +31,7 @@ import {
|
|||
CardHeader,
|
||||
Container,
|
||||
Form,
|
||||
FormDropdown,
|
||||
Image,
|
||||
PlaceholderHeader,
|
||||
PlaceholderLine,
|
||||
|
|
@ -43,7 +45,7 @@ import {FileRowTagIcon, FilesView} from "./Files";
|
|||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
||||
import {Button, Card, Header, Loader, Placeholder, Popup, Segment, Statistic, StatisticGroup} from "./Theme";
|
||||
import {deleteVideos, fetchVideoDownloaderConfig, postVideoFileFormat, updateVideoDownloaderConfig} from "../api";
|
||||
import {deleteVideos, fetchBrowserProfiles, fetchVideoDownloaderConfig, postVideoFileFormat, updateVideoDownloaderConfig} from "../api";
|
||||
import {Media, QueryContext, ThemeContext} from "../contexts/contexts";
|
||||
import _ from "lodash";
|
||||
import {defaultFileOrder, defaultSearchOrder} from "./Vars";
|
||||
|
|
@ -257,43 +259,76 @@ function VideosSettings() {
|
|||
writesubtitles: true,
|
||||
writethumbnail: true,
|
||||
},
|
||||
always_use_browser_profile: false,
|
||||
yt_dlp_extra_args: '',
|
||||
browser_profile: '',
|
||||
};
|
||||
|
||||
const fetcher = async () => {
|
||||
return await fetchVideoDownloaderConfig();
|
||||
}
|
||||
const configSubmitter = async () => {
|
||||
return await updateVideoDownloaderConfig(configForm.formData);
|
||||
};
|
||||
|
||||
const submitter = async () => {
|
||||
return await updateVideoDownloaderConfig(form.formData);
|
||||
}
|
||||
|
||||
const form = useForm({
|
||||
fetcher,
|
||||
submitter,
|
||||
const configForm = useForm({
|
||||
fetcher: fetchVideoDownloaderConfig,
|
||||
submitter: configSubmitter,
|
||||
emptyFormData,
|
||||
});
|
||||
|
||||
const emptyProfilesOptions = [{key: null, text: 'No profiles found'}];
|
||||
const loadingProfilesOptions = [{key: null, text: 'Loading profiles, please wait...'}];
|
||||
const [browserProfilesOptions, setBrowserProfilesOptions] = useState(loadingProfilesOptions);
|
||||
|
||||
const localFetchBrowserProfiles = async () => {
|
||||
let tempProfiles = [];
|
||||
let localBrowserProfiles = await fetchBrowserProfiles();
|
||||
|
||||
const chromiumProfiles = localBrowserProfiles['chromium_profiles'];
|
||||
for (const value of Object.values(chromiumProfiles)) {
|
||||
tempProfiles.push({value: value, text: value});
|
||||
}
|
||||
const firefoxProfiles = localBrowserProfiles['firefox_profiles'];
|
||||
for (const value of Object.values(firefoxProfiles)) {
|
||||
tempProfiles.push({value: value, text: value});
|
||||
}
|
||||
|
||||
if (_.isEmpty(tempProfiles)) {
|
||||
tempProfiles = emptyProfilesOptions;
|
||||
}
|
||||
console.debug('VideosSettings: Got browser profiles:', tempProfiles);
|
||||
setBrowserProfilesOptions(tempProfiles);
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
localFetchBrowserProfiles();
|
||||
}, []);
|
||||
|
||||
const alwaysUseBrowserProfileLabel = <InfoHeader
|
||||
headerSize='h5'
|
||||
headerContent='Always Use Browser Profile'
|
||||
popupContent='Always download videos with the selected browser profile. This is risky, and therefore discouraged.'
|
||||
/>;
|
||||
|
||||
return <Segment>
|
||||
<Header as='h3'>Video Downloader Settings</Header>
|
||||
<Header as='h3'>Video Downloader Config</Header>
|
||||
|
||||
<Form>
|
||||
<Grid>
|
||||
<Grid.Row columns={2}>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<VideoResolutionSelectorForm
|
||||
form={form}
|
||||
form={configForm}
|
||||
name='video_resolutions'
|
||||
path='video_resolutions'
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<VideoFileNameForm form={form}/>
|
||||
<VideoFileNameForm form={configForm}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row columns={2}>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
form={configForm}
|
||||
label='Do not overwrite existing files'
|
||||
name='nooverwrites'
|
||||
path='yt_dlp_options.nooverwrites'
|
||||
|
|
@ -302,7 +337,7 @@ function VideosSettings() {
|
|||
</Grid.Column>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
form={configForm}
|
||||
label='Download automatic subtitles'
|
||||
name='writeautomaticsub'
|
||||
path='yt_dlp_options.writeautomaticsub'
|
||||
|
|
@ -313,7 +348,7 @@ function VideosSettings() {
|
|||
<Grid.Row>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
form={configForm}
|
||||
label='Download subtitles'
|
||||
name='writesubtitles'
|
||||
path='yt_dlp_options.writesubtitles'
|
||||
|
|
@ -322,7 +357,7 @@ function VideosSettings() {
|
|||
</Grid.Column>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
form={configForm}
|
||||
label='Download thumbnail'
|
||||
name='writethumbnail'
|
||||
path='yt_dlp_options.writethumbnail'
|
||||
|
|
@ -330,13 +365,41 @@ function VideosSettings() {
|
|||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<InputForm
|
||||
form={configForm}
|
||||
name='yt_dlp_extra_args'
|
||||
path='yt_dlp_extra_args'
|
||||
label='Extra yt-dlp Arguments'
|
||||
placeholder='--cookies-from-browser chromium'
|
||||
icon='terminal'
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<VideoBrowserCookiesSelector form={configForm} options={browserProfilesOptions}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column mobile={16} computer={8}/>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={configForm}
|
||||
label={alwaysUseBrowserProfileLabel}
|
||||
name='always_use_browser_profile'
|
||||
path='always_use_browser_profile'
|
||||
disabled={!configForm.formData.browser_profile}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
|
||||
<Grid.Row columns={1}>
|
||||
<Grid.Column textAlign='right'>
|
||||
<APIButton
|
||||
disabled={form.disabled || !form.ready}
|
||||
disabled={configForm.disabled || !configForm.ready}
|
||||
type='submit'
|
||||
style={{marginTop: '0.5em'}}
|
||||
onClick={form.onSubmit}
|
||||
onClick={configForm.onSubmit}
|
||||
id='video_settings_save_button'
|
||||
>Save</APIButton>
|
||||
</Grid.Column>
|
||||
|
|
@ -346,6 +409,39 @@ function VideosSettings() {
|
|||
</Segment>
|
||||
}
|
||||
|
||||
|
||||
export function VideoBrowserCookiesSelector({
|
||||
form,
|
||||
options,
|
||||
name = 'browser_profile',
|
||||
path = 'browser_profile',
|
||||
}) {
|
||||
const [inputProps, inputAttrs] = form.getSelectionProps({name, path});
|
||||
|
||||
const popupContent = <div>
|
||||
Select a browser profile to use for cookies. This is useful for sites that require login to download videos.
|
||||
<br/>
|
||||
<br/>
|
||||
<b>MUST BE FROM THE wrolpi USER!</b>
|
||||
</div>;
|
||||
|
||||
return <>
|
||||
<InfoHeader
|
||||
headerSize='h5'
|
||||
headerContent='Browser Profile'
|
||||
popupContent={popupContent}
|
||||
/>
|
||||
<FormDropdown
|
||||
selection
|
||||
placeholder='Select Browser Profile'
|
||||
options={options}
|
||||
name={name}
|
||||
id='browser_profile_dropdown'
|
||||
{...inputProps}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
function VideosStatistics() {
|
||||
useTitle('Video Statistics');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
import {APIButton} from "../Common";
|
||||
import {Icon, Table} from "../Theme";
|
||||
import {Icon, Popup, Table} from "../Theme";
|
||||
import React from "react";
|
||||
import {TableBody, TableCell, TableHeader, TableHeaderCell, TableRow} from "semantic-ui-react";
|
||||
import {TableRowPlaceholder} from "../Placeholder";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
|
||||
function WarningIcon({ok}) {
|
||||
return <Icon color={ok ? 'violet' : 'red'} name={ok ? 'check' : 'close'}/>
|
||||
// null is empty, true is valid, false is invalid.
|
||||
const trigger = <Icon
|
||||
color={ok === true ? 'violet' : ok === false ? 'red' : 'grey'}
|
||||
name={ok === true ? 'check' : ok === false ? 'close' : 'check'}
|
||||
/>;
|
||||
const content = ok === true ? 'Valid and can be imported.' : ok === false ? 'Invalid, can be overwritten.' : 'Empty config, can be overwritten.';
|
||||
return <Popup trigger={trigger} content={content}/>
|
||||
}
|
||||
|
||||
function ConfigTableRow({config, importConfig, saveConfig, fetchConfigs}) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue