From 41c52b9c1e36007f64ae65db14278f6bc800376b Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 5 May 2025 12:56:24 -0600 Subject: [PATCH] Not using browser profile if it is disabled, even if always_user_browser_profile is enabled. This enables the user to selectively disable cookies. --- app/src/components/Download.js | 25 +++++++++++++++++++++++-- app/src/hooks/useForm.js | 15 ++++++++++----- modules/videos/downloader.py | 5 ++++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/src/components/Download.js b/app/src/components/Download.js index 776919c8..67e9d323 100644 --- a/app/src/components/Download.js +++ b/app/src/components/Download.js @@ -1,6 +1,14 @@ import React, {useState} from "react"; import {fetchVideoDownloaderConfig, getDownloaders, postDownload, putDownload} from "../api"; -import {APIButton, DirectorySearch, InfoHeader, InfoPopup, mergeDeep, RequiredAsterisk, useLocalStorage} from "./Common"; +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"; @@ -8,7 +16,15 @@ 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, ToggleForm, UrlInput, UrlsTextarea, useForm} from "../hooks/useForm"; +import { + commaSeparatedValidator, + InputForm, + NumberInputForm, + ToggleForm, + UrlInput, + UrlsTextarea, + useForm +} from "../hooks/useForm"; import { channelFrequencyOptions, days30Option, @@ -22,6 +38,7 @@ import { frequencyOptions, weeklyOption } from "./Vars"; +import _ from "lodash"; export function DepthInputForm({form, required, name = 'depth', path = 'settings.depth'}) { return { const result = await fetchVideoDownloaderConfig(); setConfig(result); + if (result?.always_use_browser_profile === true) { + // Enable the toggle if "always_use_browser_profile" is set. + form.setValue('settings.use_browser_profile', true); + } } React.useEffect(() => { diff --git a/app/src/hooks/useForm.js b/app/src/hooks/useForm.js index 373171d2..f0b027fd 100644 --- a/app/src/hooks/useForm.js +++ b/app/src/hooks/useForm.js @@ -175,6 +175,10 @@ export function useForm({ } } + const setValue = (path, newValue) => { + patchFormData(_.set(formData, path, newValue)); + } + const getCustomProps = ({name, validator, type = 'text', path, required = false}) => { // Props for any other elements. @@ -188,8 +192,8 @@ export function useForm({ patchFormData(_.set(formData, path, type === 'array' ? [] : null)); } // Allow bypass of `handleInputEvent` which only handles an input event. - const setValue = newValue => { - patchFormData(_.set(formData, path, newValue)); + const localSetValue = newValue => { + setValue(path, newValue); debouncedValidate(path, newValue); } @@ -198,14 +202,14 @@ export function useForm({ type, disabled, value, - onChange: setValue, + onChange: (newValue) => {setValue(path, newValue)}, 'data-path': path, } // Attributes about the input, but should not be passed as properties. const inputAttrs = { valid: validValues[path], path, - setValue, + localSetValue, }; return [inputProps, inputAttrs] } @@ -259,6 +263,7 @@ export function useForm({ getInputProps, getSelectionProps, handleInputEvent, + setValue, loading, onSubmit, ready, @@ -440,4 +445,4 @@ export function ToggleForm({form, name, label, path, icon = null, iconSize = 'bi onChange={inputProps.onChange} /> -} \ No newline at end of file +} diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index c06a3a1f..042329f3 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -429,7 +429,10 @@ class VideoDownloader(Downloader, ABC): cmd = (*cmd, '--write-info-json') if config.yt_dlp_extra_args: cmd = (*cmd, *config.yt_dlp_extra_args.split(' ')) - if config.browser_profile and (config.always_use_browser_profile or settings.get('use_browser_profile')): + if config.browser_profile and ( + (i := settings.get('use_browser_profile')) or (config.always_use_browser_profile and i != False)): + # Use the browser profile to get cookies, but only if "always_use_browser_profile" is set and + # "use_browser_profile" is not False, or if "use_browser_profile" is set. browser_profile = pathlib.Path(config.browser_profile) if browser_profile.exists(): browser_profile = browser_profile_to_yt_dlp_arg(browser_profile)