2026-02-23 17:29:09 -07:00
import React , { useContext , useEffect , useRef , useState } from 'react' ;
2026-03-20 15:38:32 -06:00
import { Link , Outlet , useParams } from "react-router" ;
2026-02-23 17:29:09 -07:00
import { useHotkeys } from "react-hotkeys-hook" ;
2022-08-06 05:22:07 +00:00
import {
2023-07-27 15:53:47 -06:00
APIButton ,
2022-11-04 09:58:38 -06:00
CardLink ,
2023-03-29 13:46:39 -06:00
CardPoster ,
2022-11-04 09:58:38 -06:00
Duration ,
2023-03-29 13:46:39 -06:00
encodeMediaPath ,
2023-09-07 20:13:36 -06:00
ErrorMessage ,
2022-11-04 09:58:38 -06:00
FileIcon ,
2023-03-29 13:46:39 -06:00
findPosterPath ,
2023-11-02 16:56:05 -06:00
humanFileSize ,
2024-08-22 21:18:42 -06:00
humanNumber ,
2026-03-11 15:42:52 -06:00
HelpHeader ,
2025-04-17 17:02:39 -06:00
InfoHeader ,
2024-08-22 21:18:42 -06:00
isoDatetimeToAgoPopup ,
2022-11-04 09:58:38 -06:00
mimetypeColor ,
2022-01-31 16:52:22 -07:00
PageContainer ,
2023-07-27 15:53:47 -06:00
PreviewLink ,
2021-11-01 16:42:52 -06:00
scrollToTop ,
2023-04-09 14:34:33 -06:00
SearchInput ,
2023-11-02 16:56:05 -06:00
secondsToFullDuration ,
2023-04-09 14:34:33 -06:00
SortButton ,
2022-01-29 22:25:35 -07:00
TabLinks ,
2022-11-04 09:58:38 -06:00
textEllipsis ,
2026-03-06 15:15:36 -07:00
useTitle ,
CookiesUnlockModal
2021-11-01 16:42:52 -06:00
} from "./Common"
import VideoPage from "./VideoPlayer" ;
2022-11-04 09:58:38 -06:00
import {
2022-11-30 20:13:54 -07:00
CardContent ,
CardDescription ,
CardHeader ,
2022-11-04 09:58:38 -06:00
Container ,
2024-11-02 15:14:02 -06:00
Form ,
2025-04-17 17:02:39 -06:00
FormDropdown ,
2026-02-20 14:37:58 -07:00
FormInput ,
2026-02-23 17:29:09 -07:00
FormField ,
TextArea ,
2022-11-04 09:58:38 -06:00
Image ,
2026-02-20 14:37:58 -07:00
Label ,
2022-11-04 09:58:38 -06:00
PlaceholderHeader ,
PlaceholderLine ,
StatisticLabel ,
StatisticValue ,
TableCell
} from "semantic-ui-react" ;
2024-03-12 17:20:51 -06:00
import { useChannel , useSearchOrder , useSearchVideos , useVideo , useVideoStatistics } from "../hooks/customHooks" ;
2023-03-24 08:58:18 -06:00
import { FileRowTagIcon , FilesView } from "./Files" ;
2022-08-06 05:22:07 +00:00
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid" ;
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon" ;
2026-02-20 14:37:58 -07:00
import { Button , Card , Header , Loader , Modal , Placeholder , Popup , Segment , Statistic } from "./Theme" ;
2026-04-09 16:18:26 -06:00
import { BulkTagModal } from "./BulkTagModal" ;
2025-12-06 14:49:46 -07:00
import {
deleteVideos ,
2026-02-20 14:37:58 -07:00
deleteCookies ,
fetchSuggestedUserAgent ,
2025-12-06 14:49:46 -07:00
fetchVideoDownloaderConfig ,
2026-02-20 14:37:58 -07:00
getCookiesStatus ,
lockCookies ,
2025-12-06 14:49:46 -07:00
postVideoFileFormat ,
2026-02-19 16:15:18 -07:00
previewBatchReorganization ,
2026-02-20 14:37:58 -07:00
updateVideoDownloaderConfig ,
uploadCookies ,
2025-12-06 14:49:46 -07:00
} from "../api" ;
2024-03-06 17:41:04 -07:00
import { Media , QueryContext , ThemeContext } from "../contexts/contexts" ;
2023-01-04 09:14:33 -07:00
import _ from "lodash" ;
2026-03-11 15:42:52 -06:00
import { defaultFileOrder , defaultSearchOrder } from "./Vars" ;
2024-11-02 15:14:02 -06:00
import { InputForm , ToggleForm , useForm } from "../hooks/useForm" ;
2026-03-05 16:18:03 -07:00
import { VideoFormatSelectorForm , VideoResolutionSelectorForm } from "./Download" ;
2026-01-23 19:51:02 -07:00
import { BatchReorganizeModal } from "./collections/BatchReorganizeModal" ;
2022-08-06 05:22:07 +00:00
export function VideoWrapper ( ) {
2026-03-20 15:38:32 -06:00
const { fileGroupId } = useParams ( ) ;
const { videoFile , prevFile , nextFile , fetchVideo } = useVideo ( fileGroupId ) ;
2022-10-28 08:12:25 -06:00
2026-03-20 15:38:32 -06:00
// Scroll to the top when fileGroupId changes.
useEffect ( scrollToTop , [ fileGroupId ] ) ;
2022-08-06 05:22:07 +00:00
2023-03-24 08:58:18 -06:00
return < VideoPage videoFile = { videoFile } prevFile = { prevFile } nextFile = { nextFile } fetchVideo = { fetchVideo }
autoplay = { true } / >
2021-11-01 16:42:52 -06:00
}
2026-03-20 15:38:32 -06:00
export function VideosPage ( ) {
2022-10-25 15:57:44 -06:00
2022-08-06 05:22:07 +00:00
const { channelId } = useParams ( ) ;
2024-03-06 17:41:04 -07:00
const { searchParams } = React . useContext ( QueryContext ) ;
2022-09-23 16:43:45 -06:00
const [ selectedVideos , setSelectedVideos ] = useState ( [ ] ) ;
2026-04-09 16:18:26 -06:00
const [ bulkTagOpen , setBulkTagOpen ] = useState ( false ) ;
2026-02-23 17:29:09 -07:00
const searchInputRef = React . useRef ( ) ;
useHotkeys ( 'f' , ( e ) => {
e . preventDefault ( ) ;
if ( searchInputRef . current ) {
searchInputRef . current . focus ( ) ;
}
} , { enableOnFormTags : false } ) ;
2021-11-01 16:42:52 -06:00
2024-04-14 13:06:03 -06:00
let searchOrder = defaultFileOrder ;
2022-08-06 05:22:07 +00:00
if ( searchParams . get ( 'order' ) ) {
// Use whatever order the user specified.
searchOrder = searchParams . get ( 'order' ) ;
} else if ( searchParams . get ( 'q' ) ) {
// User used a search_str
searchOrder = defaultSearchOrder ;
2021-11-01 16:42:52 -06:00
}
2024-07-22 16:36:57 -06:00
const { searchStr , setSearchStr , videos , activePage , setPage , totalPages , fetchVideos , loading } =
2023-03-24 08:58:18 -06:00
useSearchVideos ( null , channelId , searchOrder ) ;
2021-11-01 16:42:52 -06:00
2022-08-06 05:22:07 +00:00
const { channel } = useChannel ( channelId ) ;
2021-11-01 16:42:52 -06:00
2022-12-01 09:54:37 -07:00
let title = 'Videos' ;
if ( channel && channel . name ) {
title = ` ${ channel . name } Videos ` ;
}
useTitle ( title ) ;
2022-10-24 15:17:48 -06:00
let videoOrders = [
2023-10-24 10:20:06 -06:00
{ value : 'published_datetime' , text : 'Published Date' , short : 'P.Date' } ,
{ value : 'length' , text : 'Length' } ,
2023-04-09 14:13:36 -06:00
{ value : 'size' , text : 'Size' } ,
2025-06-07 17:36:00 -06:00
{ value : 'size_to_duration' , text : 'Size to Duration' , short : 'S/Duration' } ,
2023-04-09 14:13:36 -06:00
{ value : 'view_count' , text : 'Views' } ,
2023-10-24 10:20:06 -06:00
{ value : 'viewed' , text : 'Recently Viewed' , short : 'R.Viewed' } ,
2024-03-12 11:06:30 -06:00
{ value : 'download_datetime' , text : 'Download Date' , short : 'D.Date' } ,
2023-04-09 14:13:36 -06:00
]
2022-10-24 15:17:48 -06:00
if ( searchStr ) {
2023-04-09 14:13:36 -06:00
videoOrders = [ { value : 'rank' , text : 'Search' } , ... videoOrders ] ;
2022-10-24 15:17:48 -06:00
}
2022-08-06 05:22:07 +00:00
let header ;
if ( channel && channel . name ) {
const editLink = ` /videos/channel/ ${ channelId } /edit ` ;
header = < >
< Header as = 'h1' >
{ channel . name }
< Link to = { editLink } >
< Icon name = 'edit' style = { { marginLeft : '0.5em' } } / >
< / L i n k >
< / H e a d e r >
< / > ;
} else if ( channelId ) {
header = < Placeholder style = { { marginBottom : '1em' } } >
< PlaceholderHeader >
< PlaceholderLine / >
< / P l a c e h o l d e r H e a d e r >
< / P l a c e h o l d e r > ;
2021-11-01 16:42:52 -06:00
}
2022-09-23 16:43:45 -06:00
const onSelect = ( path , checked ) => {
2023-05-29 18:04:03 -06:00
const newSelectedVideos = checked && path ? [ ... selectedVideos , path ] : selectedVideos . filter ( i => i !== path ) ;
console . debug ( ` Selected Videos: ${ newSelectedVideos } ` ) ;
setSelectedVideos ( newSelectedVideos ) ;
2022-09-23 16:43:45 -06:00
}
2023-07-27 15:53:47 -06:00
const onDelete = async ( ) => {
2026-03-20 15:38:32 -06:00
const fileGroupIds = videos . filter ( i => selectedVideos . indexOf ( i [ 'primary_path' ] ) >= 0 ) . map ( i => i [ 'id' ] ) ;
await deleteVideos ( fileGroupIds ) ;
2022-09-23 16:43:45 -06:00
await fetchVideos ( ) ;
setSelectedVideos ( [ ] ) ;
}
2022-10-24 17:15:15 -06:00
const invertSelection = async ( ) => {
const newSelectedVideos = videos . map ( video => video [ 'key' ] ) . filter ( i => selectedVideos . indexOf ( i ) < 0 ) ;
setSelectedVideos ( newSelectedVideos ) ;
}
const clearSelection = async ( e ) => {
if ( e ) e . preventDefault ( ) ;
setSelectedVideos ( [ ] ) ;
}
2026-04-09 16:18:26 -06:00
const onBulkTagComplete = async ( ) => {
await fetchVideos ( ) ;
setSelectedVideos ( [ ] ) ;
}
2022-09-23 16:43:45 -06:00
const selectElm = < div style = { { marginTop : '0.5em' } } >
2026-04-09 16:18:26 -06:00
< Button
color = 'violet'
disabled = { _ . isEmpty ( selectedVideos ) }
onClick = { ( ) => setBulkTagOpen ( true ) }
> Tag < / B u t t o n >
2023-07-27 15:53:47 -06:00
< APIButton
2022-09-23 16:43:45 -06:00
color = 'red'
2023-01-04 09:14:33 -07:00
disabled = { _ . isEmpty ( selectedVideos ) }
2022-09-23 16:43:45 -06:00
confirmButton = 'Delete'
2023-07-27 15:53:47 -06:00
confirmContent = 'Are you sure you want to delete these video files? This cannot be undone.'
onClick = { onDelete }
> Delete < / A P I B u t t o n >
2022-10-24 17:15:15 -06:00
< Button
color = 'grey'
onClick = { ( ) => invertSelection ( ) }
2023-01-04 09:14:33 -07:00
disabled = { _ . isEmpty ( videos ) }
2022-10-24 17:15:15 -06:00
>
Invert
< / B u t t o n >
< Button
color = 'yellow'
onClick = { ( ) => clearSelection ( ) }
2023-01-04 09:14:33 -07:00
disabled = { _ . isEmpty ( videos ) || _ . isEmpty ( selectedVideos ) }
2022-10-24 17:15:15 -06:00
>
Clear
< / B u t t o n >
2026-04-09 16:18:26 -06:00
< BulkTagModal
open = { bulkTagOpen }
onClose = { ( ) => setBulkTagOpen ( false ) }
paths = { selectedVideos }
onComplete = { onBulkTagComplete }
/ >
2022-09-23 16:43:45 -06:00
< / d i v > ;
2026-04-09 16:18:26 -06:00
const { body , paginator , viewButton , limitDropdown , tagQuerySelector } = FilesView (
2024-07-22 16:36:57 -06:00
{
files : videos ,
activePage : activePage ,
totalPages : totalPages ,
selectElem : selectElm ,
selectedKeys : selectedVideos ,
onSelect : onSelect ,
setPage : setPage ,
headlines : ! ! searchStr ,
loading : loading ,
} ,
2023-04-09 14:13:36 -06:00
) ;
2024-02-19 15:08:04 -07:00
const [ localSearchStr , setLocalSearchStr ] = React . useState ( searchStr || '' ) ;
2023-11-22 12:19:49 -07:00
const searchInput = < SearchInput
2024-03-12 17:20:51 -06:00
searchStr = { localSearchStr }
onChange = { setLocalSearchStr }
2024-05-08 17:44:44 -06:00
onClear = { ( ) => setLocalSearchStr ( null ) }
2024-03-12 17:20:51 -06:00
onSubmit = { setSearchStr }
placeholder = 'Search Videos...'
2026-02-23 17:29:09 -07:00
inputRef = { searchInputRef }
2023-04-09 14:52:44 -06:00
/ > ;
2023-04-09 14:13:36 -06:00
2022-01-03 15:13:02 -07:00
return < >
2022-08-06 05:22:07 +00:00
{ header }
2023-04-09 14:13:36 -06:00
< Media at = 'mobile' >
< Grid >
< Grid . Row >
< Grid . Column width = { 2 } > { viewButton } < / G r i d . C o l u m n >
< Grid . Column width = { 4 } > { limitDropdown } < / G r i d . C o l u m n >
< Grid . Column width = { 2 } > { tagQuerySelector } < / G r i d . C o l u m n >
2026-04-09 16:18:26 -06:00
< Grid . Column width = { 8 } > < SortButton sorts = { videoOrders } / > < / G r i d . C o l u m n >
2023-04-09 14:13:36 -06:00
< / G r i d . R o w >
< Grid . Row >
2023-11-21 13:01:52 -07:00
< Grid . Column width = { 16 } > { searchInput } < / G r i d . C o l u m n >
2023-04-09 14:13:36 -06:00
< / G r i d . R o w >
< / G r i d >
< / M e d i a >
< Media greaterThanOrEqual = 'tablet' >
< Grid >
< Grid . Row >
< Grid . Column width = { 1 } > { viewButton } < / G r i d . C o l u m n >
< Grid . Column width = { 2 } > { limitDropdown } < / G r i d . C o l u m n >
< Grid . Column width = { 1 } > { tagQuerySelector } < / G r i d . C o l u m n >
2023-04-09 14:52:44 -06:00
< Grid . Column width = { 4 } > < SortButton sorts = { videoOrders } / > < / G r i d . C o l u m n >
2026-04-09 16:18:26 -06:00
< Grid . Column width = { 8 } > { searchInput } < / G r i d . C o l u m n >
2023-04-09 14:13:36 -06:00
< / G r i d . R o w >
< / G r i d >
< / M e d i a >
{ body }
{ paginator }
2022-01-03 15:13:02 -07:00
< / >
2021-11-01 16:42:52 -06:00
}
2024-11-29 17:01:16 -07:00
function VideoFileNameForm ( { form } ) {
const [ message , setMessage ] = React . useState ( null ) ;
2026-01-23 19:51:02 -07:00
const debouncedOnChange = React . useCallback (
_ . debounce ( async ( value ) => {
const response = await postVideoFileFormat ( value ) ;
const { error , preview } = await response . json ( ) ;
if ( error ) {
setMessage ( { content : error , header : 'Invalid File Name' , negative : true } ) ;
} else {
setMessage ( { content : preview , header : 'File Name Preview' , positive : true } ) ;
}
} , 300 ) ,
[ ]
) ;
// Cleanup debounce on unmount
React . useEffect ( ( ) => {
return ( ) => debouncedOnChange . cancel ( ) ;
} , [ debouncedOnChange ] ) ;
const onChange = debouncedOnChange ;
2024-11-29 17:01:16 -07:00
2025-12-22 17:56:35 -07:00
const label = < InfoHeader
headerSize = 'h5'
headerContent = 'Video File Format'
popupProps = { { wide : 'very' , position : 'top left' } }
popupContent = { < >
< p > Common yt - dlp variables : < / p >
< ul >
< li > < code > % ( title ) s < / c o d e > - V i d e o t i t l e < / l i >
< li > < code > % ( uploader ) s < / c o d e > - C h a n n e l / u p l o a d e r n a m e < / l i >
< li > < code > % ( upload _date ) s < / c o d e > - U p l o a d d a t e ( Y Y Y Y M M D D ) < / l i >
2025-12-23 18:49:33 -07:00
< li > < code > % ( upload _year ) s < / c o d e > - U p l o a d y e a r ( Y Y Y Y ) < / l i >
< li > < code > % ( upload _month ) s < / c o d e > - U p l o a d m o n t h ( 0 1 - 1 2 ) < / l i >
2025-12-22 17:56:35 -07:00
< li > < code > % ( id ) s < / c o d e > - V i d e o I D < / l i >
< li > < code > % ( channel ) s < / c o d e > - C h a n n e l n a m e < / l i >
< li > < code > % ( duration ) s < / c o d e > - D u r a t i o n i n s e c o n d s < / l i >
< li > < code > % ( playlist _index ) s < / c o d e > - P l a y l i s t i n d e x < / l i >
2026-01-23 19:51:02 -07:00
< li > < code > % ( ext ) s < / c o d e > - F i l e e x t e n s i o n ( r e q u i r e d , m u s t b e a t e n d ) < / l i >
2025-12-22 17:56:35 -07:00
< / u l >
< p > See yt - dlp docs for all variables . Subdirectories supported . < / p >
< / > }
/ > ;
2024-11-29 17:01:16 -07:00
return < InputForm
form = { form }
name = 'file_name_format'
path = 'yt_dlp_options.file_name_format'
2025-12-22 17:56:35 -07:00
label = { label }
2024-11-29 17:01:16 -07:00
onChange = { onChange }
message = { message }
/ >
}
2026-03-20 15:38:32 -06:00
export function VideosSettingsPage ( ) {
2024-11-02 15:14:02 -06:00
useTitle ( 'Videos Settings' ) ;
2026-01-23 19:51:02 -07:00
const [ batchModalOpen , setBatchModalOpen ] = useState ( false ) ;
const [ channelsNeedingReorg , setChannelsNeedingReorg ] = useState ( 0 ) ;
const [ fetchingReorgCount , setFetchingReorgCount ] = useState ( true ) ;
// Check how many channels need reorganization on mount
useEffect ( ( ) => {
setFetchingReorgCount ( true ) ;
previewBatchReorganization ( 'channel' )
. then ( data => {
setChannelsNeedingReorg ( data . total _collections || 0 ) ;
} )
. catch ( ( ) => {
setChannelsNeedingReorg ( 0 ) ;
} )
. finally ( ( ) => {
setFetchingReorgCount ( false ) ;
} ) ;
} , [ ] ) ;
2024-11-02 15:14:02 -06:00
const emptyFormData = {
video _resolutions : [ '1080p' , '720p' , '480p' , 'maximum' ] ,
yt _dlp _options : {
2026-03-05 16:18:03 -07:00
continue _dl : true ,
2024-11-02 15:14:02 -06:00
file _name _format : '%(uploader)s_%(upload_date)s_%(id)s_%(title)s.%(ext)s' ,
2026-03-05 16:18:03 -07:00
merge _output _format : 'mp4' ,
2024-11-02 15:14:02 -06:00
nooverwrites : true ,
writeautomaticsub : true ,
2026-03-05 16:18:03 -07:00
writeinfojson : true ,
2024-11-02 15:14:02 -06:00
writesubtitles : true ,
writethumbnail : true ,
} ,
2025-04-17 17:02:39 -06:00
yt _dlp _extra _args : '' ,
2026-02-19 16:15:18 -07:00
download _missing _video _comments : false ,
2026-02-20 14:37:58 -07:00
user _agent : '' ,
sleep _requests : 0.75 ,
2024-11-02 15:14:02 -06:00
} ;
2025-04-17 17:02:39 -06:00
const configSubmitter = async ( ) => {
return await updateVideoDownloaderConfig ( configForm . formData ) ;
} ;
2024-11-02 15:14:02 -06:00
2025-04-17 17:02:39 -06:00
const configForm = useForm ( {
fetcher : fetchVideoDownloaderConfig ,
submitter : configSubmitter ,
2024-11-02 15:14:02 -06:00
emptyFormData ,
} ) ;
2026-02-20 14:37:58 -07:00
const [ suggestedUserAgent , setSuggestedUserAgent ] = useState ( '' ) ;
2025-04-17 17:02:39 -06:00
React . useEffect ( ( ) => {
2026-02-20 14:37:58 -07:00
const fetchSuggested = async ( ) => {
const ua = await fetchSuggestedUserAgent ( ) ;
setSuggestedUserAgent ( ua ) ;
} ;
fetchSuggested ( ) ;
2025-04-17 17:02:39 -06:00
} , [ ] ) ;
2026-02-19 16:15:18 -07:00
const downloadMissingVideoCommentsLabel = < InfoHeader
headerSize = 'h5'
headerContent = 'Download Missing Video Comments'
popupContent = 'When enabled, WROLPi will automatically download comments for videos that are missing them.'
/ > ;
2025-04-17 17:02:39 -06:00
2026-01-23 19:51:02 -07:00
return < >
< Segment >
< Header as = 'h3' > Video Downloader Config < / H e a d e r >
2024-11-02 15:14:02 -06:00
2026-01-23 19:51:02 -07:00
< Form >
2026-02-19 16:15:18 -07:00
< Grid >
< Grid . Row columns = { 2 } >
< Grid . Column mobile = { 16 } computer = { 8 } >
< VideoResolutionSelectorForm
form = { configForm }
name = 'video_resolutions'
path = 'video_resolutions'
/ >
< / G r i d . C o l u m n >
2026-03-05 16:18:03 -07:00
< Grid . Column mobile = { 16 } computer = { 4 } >
< VideoFormatSelectorForm
form = { configForm }
name = 'merge_output_format'
path = 'yt_dlp_options.merge_output_format'
/ >
< / G r i d . C o l u m n >
< Grid . Column mobile = { 16 } computer = { 4 } >
2026-02-19 16:15:18 -07:00
< VideoFileNameForm form = { configForm } / >
< / G r i d . C o l u m n >
< / G r i d . R o w >
< Grid . Row columns = { 2 } >
< Grid . Column mobile = { 16 } computer = { 8 } >
< ToggleForm
form = { configForm }
label = 'Do not overwrite existing files'
name = 'nooverwrites'
path = 'yt_dlp_options.nooverwrites'
icon = 'file video'
/ >
< / G r i d . C o l u m n >
< Grid . Column mobile = { 16 } computer = { 8 } >
< ToggleForm
form = { configForm }
label = 'Download automatic subtitles'
name = 'writeautomaticsub'
path = 'yt_dlp_options.writeautomaticsub'
icon = 'closed captioning'
/ >
< / G r i d . C o l u m n >
< / G r i d . R o w >
2026-03-05 16:18:03 -07:00
< Grid . Row columns = { 2 } >
2026-02-19 16:15:18 -07:00
< Grid . Column mobile = { 16 } computer = { 8 } >
< ToggleForm
form = { configForm }
label = 'Download subtitles'
name = 'writesubtitles'
path = 'yt_dlp_options.writesubtitles'
icon = 'closed captioning outline'
/ >
< / G r i d . C o l u m n >
< Grid . Column mobile = { 16 } computer = { 8 } >
< ToggleForm
form = { configForm }
label = 'Download thumbnail'
name = 'writethumbnail'
path = 'yt_dlp_options.writethumbnail'
icon = 'image'
/ >
< / G r i d . C o l u m n >
< / G r i d . R o w >
2026-03-05 16:18:03 -07:00
< 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'
/ >
< / G r i d . C o l u m n >
< Grid . Column mobile = { 16 } computer = { 8 } >
< ToggleForm
form = { configForm }
label = 'Continue partial downloads'
name = 'continue_dl'
path = 'yt_dlp_options.continue_dl'
icon = 'play'
/ >
< / G r i d . C o l u m n >
< / G r i d . R o w >
2026-02-21 14:24:22 -07:00
< Grid . Row >
< Grid . Column mobile = { 16 } computer = { 8 } >
< ToggleForm
form = { configForm }
label = { downloadMissingVideoCommentsLabel }
name = 'download_missing_video_comments'
path = 'download_missing_video_comments'
icon = 'comments'
/ >
< / G r i d . C o l u m n >
< / G r i d . R o w >
2026-02-19 16:15:18 -07:00
< 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 = '--prefer-free-formats'
icon = 'terminal'
/ >
< / G r i d . C o l u m n >
2026-02-21 14:24:22 -07:00
< Grid . Column mobile = { 16 } computer = { 4 } >
2026-02-20 14:37:58 -07:00
< Form . Field >
< InfoHeader
headerSize = 'h5'
headerContent = 'Sleep Between Requests'
popupContent = 'Seconds to sleep between yt-dlp API requests. Helps avoid rate limiting and bot detection. Set to 0 to disable. Does not affect video download speed.'
/ >
< FormInput
type = 'number'
step = '0.25'
min = '0'
max = '10'
value = { configForm . formData . sleep _requests ? ? 0.75 }
onChange = { ( e ) => configForm . setValue ( 'sleep_requests' , parseFloat ( e . target . value ) || 0 ) }
placeholder = '0.75'
label = { { basic : true , content : 'seconds' } }
labelPosition = 'right'
/ >
< / F o r m . F i e l d >
2026-02-19 16:15:18 -07:00
< / G r i d . C o l u m n >
< / G r i d . R o w >
< Grid . Row >
2026-02-21 14:24:22 -07:00
< Grid . Column mobile = { 16 } computer = { 16 } >
< Form . Field >
< InfoHeader
headerSize = 'h5'
headerContent = 'User Agent'
popupContent = 'Custom user-agent string for yt-dlp. Should match the browser used to export cookies. Click "Use Current Browser" to auto-fill with your browser's user-agent.'
/ >
< FormInput
value = { configForm . formData . user _agent || '' }
onChange = { ( e ) => configForm . setValue ( 'user_agent' , e . target . value ) }
placeholder = 'Leave empty to use yt-dlp default'
action = { {
content : 'Use Current Browser' ,
onClick : ( ) => configForm . setValue ( 'user_agent' , suggestedUserAgent ) ,
} }
/ >
< / F o r m . F i e l d >
2026-02-19 16:15:18 -07:00
< / G r i d . C o l u m n >
< / G r i d . R o w >
< Grid . Row columns = { 1 } >
< Grid . Column textAlign = 'right' >
< APIButton
disabled = { configForm . disabled || ! configForm . ready }
type = 'submit'
style = { { marginTop : '0.5em' } }
onClick = { configForm . onSubmit }
id = 'video_settings_save_button'
> Save < / A P I B u t t o n >
< / G r i d . C o l u m n >
< / G r i d . R o w >
< / G r i d >
< / F o r m >
2026-01-23 19:51:02 -07:00
< / S e g m e n t >
< Segment >
< Header as = 'h4' > File Organization < / H e a d e r >
< p >
{ fetchingReorgCount
? 'Checking for channels that need reorganization...'
: < >
< strong > { channelsNeedingReorg } < / s t r o n g > c h a n n e l { c h a n n e l s N e e d i n g R e o r g ! = = 1 ? ' s ' : ' ' }
{ channelsNeedingReorg > 0
? ' have files that do not match the current file name format.'
: '. All channels are organized correctly.' }
2026-02-19 16:15:18 -07:00
< / >
2026-01-23 19:51:02 -07:00
}
< / p >
< Button
color = 'orange'
onClick = { ( ) => setBatchModalOpen ( true ) }
id = 'reorganize_all_channels_button'
disabled = { fetchingReorgCount || channelsNeedingReorg === 0 }
loading = { fetchingReorgCount }
>
< Icon name = 'folder open outline' / > Reorganize All Channels
< / B u t t o n >
< / S e g m e n t >
2026-02-20 14:37:58 -07:00
< CookiesSettingsSection / >
2026-01-23 19:51:02 -07:00
< BatchReorganizeModal
open = { batchModalOpen }
onClose = { ( ) => setBatchModalOpen ( false ) }
kind = 'channel'
onComplete = { ( ) => {
setBatchModalOpen ( false ) ;
setChannelsNeedingReorg ( 0 ) ;
} }
/ >
< / >
2024-11-02 15:14:02 -06:00
}
2026-02-20 14:37:58 -07:00
function CookiesSettingsSection ( ) {
const [ status , setStatus ] = useState ( { cookies _exist : false , cookies _unlocked : false } ) ;
const [ loading , setLoading ] = useState ( true ) ;
const [ uploadModalOpen , setUploadModalOpen ] = useState ( false ) ;
const [ unlockModalOpen , setUnlockModalOpen ] = useState ( false ) ;
const [ cookiesContent , setCookiesContent ] = useState ( '' ) ;
const [ password , setPassword ] = useState ( '' ) ;
const [ submitting , setSubmitting ] = useState ( false ) ;
2026-02-23 17:29:09 -07:00
const cookiesContentRef = useRef ( null ) ;
useEffect ( ( ) => {
if ( uploadModalOpen ) {
const timer = setTimeout ( ( ) => {
if ( cookiesContentRef . current ) {
cookiesContentRef . current . focus ( ) ;
}
} , 100 ) ;
return ( ) => clearTimeout ( timer ) ;
}
} , [ uploadModalOpen ] ) ;
2026-02-20 14:37:58 -07:00
const fetchStatus = async ( ) => {
setLoading ( true ) ;
const result = await getCookiesStatus ( ) ;
if ( result ) {
setStatus ( result ) ;
}
setLoading ( false ) ;
} ;
useEffect ( ( ) => {
fetchStatus ( ) ;
} , [ ] ) ;
const handleUpload = async ( ) => {
if ( password . length < 8 ) {
return ;
}
setSubmitting ( true ) ;
const result = await uploadCookies ( cookiesContent , password ) ;
setSubmitting ( false ) ;
if ( result . success ) {
setUploadModalOpen ( false ) ;
setCookiesContent ( '' ) ;
setPassword ( '' ) ;
fetchStatus ( ) ;
}
} ;
const handleLock = async ( ) => {
setSubmitting ( true ) ;
await lockCookies ( ) ;
setSubmitting ( false ) ;
fetchStatus ( ) ;
} ;
const handleDelete = async ( ) => {
setSubmitting ( true ) ;
await deleteCookies ( ) ;
setSubmitting ( false ) ;
fetchStatus ( ) ;
} ;
const getStatusLabel = ( ) => {
if ( loading ) return < Label color = 'grey' > Loading ... < / L a b e l > ;
if ( ! status . cookies _exist ) return < Label color = 'grey' > No cookies stored < / L a b e l > ;
if ( status . cookies _unlocked ) return < Label color = 'green' > Unlocked < / L a b e l > ;
return < Label color = 'yellow' > Locked < / L a b e l > ;
} ;
2025-04-17 17:02:39 -06:00
2026-02-20 14:37:58 -07:00
return < Segment >
2026-03-11 15:42:52 -06:00
< HelpHeader
headerSize = 'h4'
headerContent = 'Encrypted Cookies'
helpPath = '/modules/videos/cookies/'
/ >
2026-02-20 14:37:58 -07:00
< p > Use this feature at your own risk ! You may be suspended or blocked if abused !
< / p >
< div style = { { marginBottom : '1em' } } >
< strong > Status : < / s t r o n g > { g e t S t a t u s L a b e l ( ) }
< / d i v >
< Button . Group >
{ ! status . cookies _exist && (
< Button
color = 'blue'
onClick = { ( ) => setUploadModalOpen ( true ) }
disabled = { loading }
>
< Icon name = 'upload' / > Upload Cookies
< / B u t t o n >
) }
{ status . cookies _exist && ! status . cookies _unlocked && (
< Button
color = 'green'
onClick = { ( ) => setUnlockModalOpen ( true ) }
disabled = { loading }
>
< Icon name = 'unlock' / > Unlock Cookies
< / B u t t o n >
) }
{ status . cookies _exist && status . cookies _unlocked && (
< Button
color = 'yellow'
onClick = { handleLock }
loading = { submitting }
disabled = { loading || submitting }
>
< Icon name = 'lock' / > Lock Cookies
< / B u t t o n >
) }
{ status . cookies _exist && (
< >
< Button
color = 'blue'
onClick = { ( ) => setUploadModalOpen ( true ) }
disabled = { loading }
>
< Icon name = 'refresh' / > Replace
< / B u t t o n >
< APIButton
color = 'red'
onClick = { handleDelete }
confirmButton = 'Delete'
confirmContent = 'Are you sure you want to delete the stored cookies? This cannot be undone.'
disabled = { loading || submitting }
>
< Icon name = 'trash' / > Delete
< / A P I B u t t o n >
< / >
) }
< / B u t t o n . G r o u p >
{ /* Upload Modal */ }
< Modal
open = { uploadModalOpen }
onClose = { ( ) => setUploadModalOpen ( false ) }
size = 'small'
>
< Modal . Header > Upload Cookies < / M o d a l . H e a d e r >
< Modal . Content >
< Form >
2026-02-23 17:29:09 -07:00
< FormField >
< label > Cookies Content < / l a b e l >
< TextArea
ref = { cookiesContentRef }
placeholder = 'Paste your cookies.txt content here (Netscape/Mozilla format)'
value = { cookiesContent }
onChange = { ( e ) => setCookiesContent ( e . target . value ) }
rows = { 10 }
/ >
< / F o r m F i e l d >
2026-02-20 14:37:58 -07:00
< FormInput
label = 'Encryption Password'
type = 'password'
placeholder = 'Minimum 8 characters'
value = { password }
onChange = { ( e ) => setPassword ( e . target . value ) }
error = { password . length > 0 && password . length < 8 ? 'Password must be at least 8 characters' : null }
/ >
< p style = { { color : 'grey' , fontSize : '0.9em' } } >
Remember this password - you ' ll need it to unlock cookies after each restart .
< / p >
< / F o r m >
< / M o d a l . C o n t e n t >
< Modal . Actions >
< Button onClick = { ( ) => setUploadModalOpen ( false ) } > Cancel < / B u t t o n >
< Button
color = 'blue'
onClick = { handleUpload }
loading = { submitting }
disabled = { ! cookiesContent || password . length < 8 || submitting }
>
< Icon name = 'lock' / > Encrypt & Save
< / B u t t o n >
< / M o d a l . A c t i o n s >
< / M o d a l >
2026-03-06 15:15:36 -07:00
< CookiesUnlockModal
2026-02-20 14:37:58 -07:00
open = { unlockModalOpen }
onClose = { ( ) => setUnlockModalOpen ( false ) }
2026-03-06 15:15:36 -07:00
onSuccess = { fetchStatus }
/ >
2026-02-20 14:37:58 -07:00
< / S e g m e n t > ;
2025-04-17 17:02:39 -06:00
}
2026-03-20 15:38:32 -06:00
export function VideosStatistics ( ) {
2022-10-25 15:57:44 -06:00
useTitle ( 'Video Statistics' ) ;
2022-08-06 05:22:07 +00:00
const { statistics } = useVideoStatistics ( ) ;
2021-12-23 09:38:12 -07:00
2023-09-07 20:13:36 -06:00
if ( statistics === null ) {
// Request is pending.
2022-08-06 05:22:07 +00:00
return < Loader active inline = 'centered' / >
2023-09-07 20:13:36 -06:00
} else if ( statistics === undefined ) {
return < ErrorMessage > Unable to fetch Video Statistics < / E r r o r M e s s a g e >
2021-12-23 09:38:12 -07:00
}
2023-09-07 20:13:36 -06:00
const { videos , historical , channels } = statistics ;
2022-08-06 05:22:07 +00:00
const videoNames = [
2022-10-19 09:18:53 -06:00
{ key : 'videos' , label : 'Videos' } ,
2022-08-06 05:22:07 +00:00
{ key : 'sum_size' , label : 'Total Size' } ,
{ key : 'max_size' , label : 'Largest Video' } ,
{ key : 'week' , label : 'Downloads Past Week' } ,
{ key : 'month' , label : 'Downloads Past Month' } ,
{ key : 'year' , label : 'Downloads Past Year' } ,
{ key : 'sum_duration' , label : 'Total Duration' } ,
2024-08-15 19:32:01 -06:00
{ key : 'censored_videos' , label : 'Censored Videos' } ,
2024-04-14 13:15:00 -06:00
] ;
const commentsNames = [
2024-04-14 13:06:03 -06:00
{ key : 'have_comments' , label : 'Have Comments' } ,
2024-06-25 22:12:13 -06:00
{ key : 'missing_comments' , label : 'Missing Comments' } ,
2024-04-14 13:06:03 -06:00
{ key : 'failed_comments' , label : 'Failed Comments' } ,
2022-08-06 05:22:07 +00:00
] ;
const historicalNames = [
{ key : 'average_count' , label : 'Average Monthly Downloads' } ,
{ key : 'average_size' , label : 'Average Monthly Usage' } ,
] ;
const channelNames = [
{ key : 'channels' , label : 'Channels' } ,
2024-08-15 19:32:01 -06:00
{ key : 'tagged_channels' , label : 'Tagged Channels' } ,
2022-08-06 05:22:07 +00:00
] ;
2021-11-01 16:42:52 -06:00
2022-08-06 05:22:07 +00:00
const buildSegment = ( title , names , stats ) => {
return < Segment >
< Header textAlign = 'center' as = 'h1' > { title } < / H e a d e r >
2025-12-07 11:32:07 -07:00
< Statistic . Group >
2022-08-06 05:22:07 +00:00
{ names . map (
( { key , label } ) =>
< Statistic key = { key } style = { { margin : '2em' } } >
< StatisticValue > { stats [ key ] } < / S t a t i s t i c V a l u e >
< StatisticLabel > { label } < / S t a t i s t i c L a b e l >
< / S t a t i s t i c >
) }
2025-12-07 11:32:07 -07:00
< / S t a t i s t i c . G r o u p >
2022-08-06 05:22:07 +00:00
< / S e g m e n t >
2021-11-01 16:42:52 -06:00
}
2023-02-17 16:09:24 -07:00
return < >
{ buildSegment ( 'Videos' , videoNames , videos ) }
2024-04-14 13:15:00 -06:00
{ buildSegment ( 'Video Comments' , commentsNames , videos ) }
2023-02-17 16:09:24 -07:00
{ buildSegment ( 'Historical Video' , historicalNames , historical ) }
{ buildSegment ( 'Channels' , channelNames , channels ) }
< / >
2022-01-29 22:25:35 -07:00
}
2026-03-20 15:38:32 -06:00
export function VideosTabLayout ( ) {
2022-01-29 22:25:35 -07:00
const links = [
2022-08-06 05:22:07 +00:00
{ text : 'Videos' , to : '/videos' , key : 'videos' , end : true } ,
2022-02-02 14:02:51 -07:00
{ text : 'Channels' , to : '/videos/channel' , key : 'channel' } ,
2024-11-02 15:14:02 -06:00
{ text : 'Settings' , to : '/videos/settings' , key : 'settings' } ,
2022-08-06 05:22:07 +00:00
{ text : 'Statistics' , to : '/videos/statistics' , key : 'statistics' } ,
2022-01-29 22:25:35 -07:00
] ;
2023-02-17 16:09:24 -07:00
return < PageContainer >
< TabLinks links = { links } / >
2026-03-20 15:38:32 -06:00
< Outlet / >
2023-02-17 16:09:24 -07:00
< / P a g e C o n t a i n e r >
2021-11-01 16:42:52 -06:00
}
2022-11-04 09:58:38 -06:00
export function VideoCard ( { file } ) {
2023-03-29 13:46:39 -06:00
const { video } = file ;
2022-11-04 09:58:38 -06:00
const { s } = useContext ( ThemeContext ) ;
2026-03-17 18:35:57 -06:00
const { sort } = useSearchOrder ( ) ;
const sortField = sort ? sort . replace ( /^-/ , '' ) : null ;
2022-11-04 09:58:38 -06:00
2023-07-27 15:53:47 -06:00
// Default to video FilePreview for lone video files.
2026-03-20 15:38:32 -06:00
let video _url = ` /videos/ ${ file . id } ` ;
2023-07-27 15:53:47 -06:00
2022-11-04 09:58:38 -06:00
// A video may not have a channel.
const channel = video . channel ? video . channel : null ;
let channel _url = null ;
if ( channel ) {
channel _url = ` /videos/channel/ ${ channel . id } /video ` ;
}
2023-03-29 13:46:39 -06:00
let poster = < CardPoster to = { video _url } file = { file } / > ;
2022-11-04 09:58:38 -06:00
2024-08-20 13:13:21 -06:00
const title = file . title || file . name || video . stem || video . name ;
let header = < span { ... s } className = 'card-title-ellipsis' > { title } < / s p a n > ;
2023-07-27 15:53:47 -06:00
if ( video _url ) {
// Link to Channel-Video page or Video page.
header = < Link to = { video _url } className = "no-link-underscore card-link" > { header } < / L i n k > ;
} else {
// Video is just a lone video file.
header = < PreviewLink file = { file } >
{ header }
< / P r e v i e w L i n k > ;
}
2022-11-30 20:13:54 -07:00
const color = mimetypeColor ( file . mimetype ) ;
return < Card color = { color } >
2022-11-08 22:42:00 -07:00
{ poster }
2023-10-24 10:20:06 -06:00
< Duration totalSeconds = { file . length } / >
2022-11-30 20:13:54 -07:00
< CardContent { ... s } >
< CardHeader >
2022-11-04 09:58:38 -06:00
< Container textAlign = 'left' >
2024-08-20 13:13:21 -06:00
< Popup on = 'hover'
trigger = { header }
content = { title } / >
2022-11-04 09:58:38 -06:00
< / C o n t a i n e r >
2022-11-30 20:13:54 -07:00
< / C a r d H e a d e r >
< CardDescription >
2022-11-04 09:58:38 -06:00
< Container textAlign = 'left' >
{ channel && < Link to = { channel _url } className = "no-link-underscore card-link" >
< b { ... s } > { channel . name } < / b >
< / L i n k > }
2026-03-17 18:35:57 -06:00
{ sortField === 'length'
? < p { ... s } > { secondsToFullDuration ( file . length || 0 ) } < / p >
: sortField === 'size'
? < p { ... s } > { humanFileSize ( file . size ) } < / p >
: sortField === 'view_count'
? < p { ... s } > { humanNumber ( video . view _count || 0 ) } views < / p >
: sortField === 'viewed'
? < p { ... s } > { isoDatetimeToAgoPopup ( file . viewed , false ) } < / p >
: sortField === 'download_datetime'
? < p { ... s } > { isoDatetimeToAgoPopup ( file . download _datetime , false ) } < / p >
: < p { ... s } > { isoDatetimeToAgoPopup ( file . published _datetime , false ) } < / p >
}
2022-11-04 09:58:38 -06:00
< / C o n t a i n e r >
2022-11-30 20:13:54 -07:00
< / C a r d D e s c r i p t i o n >
< / C a r d C o n t e n t >
< / C a r d >
2022-11-04 09:58:38 -06:00
}
export function VideoRowCells ( { file } ) {
const { video } = file ;
2023-11-02 16:56:05 -06:00
let { sort } = useSearchOrder ( ) ;
sort = sort ? sort . replace ( /^-+/ , '' ) : null ;
2022-11-04 09:58:38 -06:00
2026-03-20 15:38:32 -06:00
let video _url = ` /videos/ ${ file . id } ` ;
2023-03-29 13:46:39 -06:00
const poster _path = findPosterPath ( file ) ;
const poster _url = poster _path ? ` /media/ ${ encodeMediaPath ( poster _path ) } ` : null ;
2022-11-04 09:58:38 -06:00
let poster ;
if ( poster _url ) {
poster = < CardLink to = { video _url } >
< Image wrapped
src = { poster _url }
width = '50px'
/ >
< / C a r d L i n k >
} else {
poster = < FileIcon file = { file } size = 'large' / > ;
}
2024-11-02 15:14:02 -06:00
let dataCell = file . published _datetime ? isoDatetimeToAgoPopup ( file . published _datetime ) : '' ;
2023-11-02 16:56:05 -06:00
if ( sort === 'length' ) {
dataCell = secondsToFullDuration ( file . length || 0 ) ;
} else if ( sort === 'size' ) {
dataCell = humanFileSize ( file . size ) ;
} else if ( sort === 'view_count' ) {
dataCell = humanNumber ( video . view _count || 0 ) ;
} else if ( sort === 'viewed' ) {
2024-11-02 15:14:02 -06:00
dataCell = isoDatetimeToAgoPopup ( file . viewed ) ;
2023-11-02 16:56:05 -06:00
}
2022-11-04 09:58:38 -06:00
// Fragment for SelectableRow
return < React . Fragment >
< TableCell >
< center >
{ poster }
< / c e n t e r >
< / T a b l e C e l l >
< TableCell >
< CardLink to = { video _url } >
2023-03-24 08:58:18 -06:00
< FileRowTagIcon file = { file } / >
2023-04-09 14:52:44 -06:00
{ textEllipsis ( file . title || video . stem || video . video _path ) }
2022-11-04 09:58:38 -06:00
< / C a r d L i n k >
< / T a b l e C e l l >
2023-11-02 16:56:05 -06:00
< TableCell > { dataCell } < / T a b l e C e l l >
2022-11-04 09:58:38 -06:00
< / R e a c t . F r a g m e n t >
}