Modifying Video/Channel/RSS Downloaders so that they can download videos, but audio only. These audio files are grouped under their channel directories.

This commit is contained in:
Roland 2026-04-14 15:00:49 -06:00
parent 52e186f34d
commit 9468448a54
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
15 changed files with 392 additions and 71 deletions

View file

@ -28,8 +28,10 @@ import {
import {
channelFrequencyOptions,
days30Option,
defaultAudioFormatOption,
defaultVideoFormatOption,
defaultVideoResolutionOptions,
downloadAudioFormatOptions,
Downloaders,
downloadFormatOptions,
downloadOrderOptions,
@ -320,6 +322,39 @@ export function VideoFormatSelectorForm({form, name = 'video_format', path = 'se
</>
}
export function AudioOnlyToggle({form, onChange}) {
return <ToggleForm
form={form}
label='Audio only'
name='audio_only'
path='settings.audio_only'
helpContent='Download only the audio track from videos.'
onChange={onChange}
/>
}
export function AudioFormatSelectorForm({form, name = 'audio_format', path = 'settings.audio_format'}) {
const [inputProps, inputAttrs] = form.getSelectionProps({
name,
path,
defaultValue: defaultAudioFormatOption,
});
return <>
<InfoHeader
headerSize='h5'
headerContent='Audio Format'
popupContent='Audio will be downloaded and converted to this format.'
for_='audio_format_input'
/>
<FormDropdown selection
id='audio_format_input'
options={downloadAudioFormatOptions}
{...inputProps}
/>
</>
}
function VideoDurationLimit({form, name, path, label, helpContent, placeholder, helpPosition}) {
return <NumberInputForm
form={form}
@ -496,6 +531,8 @@ export function VideosDownloadForm({
settings: {
video_format: defaultVideoFormat,
video_resolutions: configResolutions,
audio_only: false,
audio_format: defaultAudioFormatOption,
writesubtitles: false,
writeautomaticsub: false,
writethumbnail: false,
@ -618,17 +655,29 @@ export function VideosDownloadForm({
/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={2}>
<Grid.Column width={11}>
<VideoResolutionSelectorForm
form={form}
onChange={() => setUserChangedResolutions(true)}
/>
</Grid.Column>
<Grid.Column width={4}>
<VideoFormatSelectorForm form={form}/>
<Grid.Row>
<Grid.Column>
<AudioOnlyToggle form={form}/>
</Grid.Column>
</Grid.Row>
{form.formData?.settings?.audio_only
? <Grid.Row columns={1}>
<Grid.Column width={5}>
<AudioFormatSelectorForm form={form}/>
</Grid.Column>
</Grid.Row>
: <Grid.Row columns={2}>
<Grid.Column width={11}>
<VideoResolutionSelectorForm
form={form}
onChange={() => setUserChangedResolutions(true)}
/>
</Grid.Column>
<Grid.Column width={4}>
<VideoFormatSelectorForm form={form}/>
</Grid.Column>
</Grid.Row>
}
<Grid.Row columns={1}>
<Grid.Column>
<ChannelTagNameForm form={form}/>
@ -768,6 +817,8 @@ export function ChannelDownloadForm({
video_count_limit: null,
video_format: defaultVideoFormat,
video_resolutions: configResolutions,
audio_only: false,
audio_format: defaultAudioFormatOption,
writesubtitles: false,
writeautomaticsub: false,
writethumbnail: false,
@ -886,17 +937,29 @@ export function ChannelDownloadForm({
<VideoDownloadCountLimit form={form}/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={2}>
<Grid.Column width={11}>
<VideoResolutionSelectorForm
form={form}
onChange={() => setUserChangedResolutions(true)}
/>
</Grid.Column>
<Grid.Column width={4}>
<VideoFormatSelectorForm form={form}/>
<Grid.Row>
<Grid.Column>
<AudioOnlyToggle form={form}/>
</Grid.Column>
</Grid.Row>
{form.formData?.settings?.audio_only
? <Grid.Row columns={1}>
<Grid.Column width={5}>
<AudioFormatSelectorForm form={form}/>
</Grid.Column>
</Grid.Row>
: <Grid.Row columns={2}>
<Grid.Column width={11}>
<VideoResolutionSelectorForm
form={form}
onChange={() => setUserChangedResolutions(true)}
/>
</Grid.Column>
<Grid.Column width={4}>
<VideoFormatSelectorForm form={form}/>
</Grid.Column>
</Grid.Row>
}
<Grid.Row columns={2}>
<Grid.Column tablet={8} computer={4}>
<VideoMinimumDurationForm form={form}/>
@ -1110,6 +1173,8 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action
title_include: null,
video_resolutions: configResolutions,
video_format: defaultVideoFormat,
audio_only: false,
audio_format: defaultAudioFormatOption,
writesubtitles: false,
writeautomaticsub: false,
writethumbnail: false,
@ -1196,17 +1261,29 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action
<TitleExclusionInput form={form}/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={2}>
<Grid.Column mobile={16} computer={11}>
<VideoResolutionSelectorForm
form={form}
onChange={() => setUserChangedResolutions(true)}
/>
</Grid.Column>
<Grid.Column mobile={8} computer={3}>
<VideoFormatSelectorForm form={form}/>
<Grid.Row>
<Grid.Column>
<AudioOnlyToggle form={form}/>
</Grid.Column>
</Grid.Row>
{form.formData?.settings?.audio_only
? <Grid.Row columns={1}>
<Grid.Column width={5}>
<AudioFormatSelectorForm form={form}/>
</Grid.Column>
</Grid.Row>
: <Grid.Row columns={2}>
<Grid.Column mobile={16} computer={11}>
<VideoResolutionSelectorForm
form={form}
onChange={() => setUserChangedResolutions(true)}
/>
</Grid.Column>
<Grid.Column mobile={8} computer={3}>
<VideoFormatSelectorForm form={form}/>
</Grid.Column>
</Grid.Row>
}
<Grid.Row columns={2}>
<Grid.Column tablet={8} computer={4}>
<VideoMinimumDurationForm form={form}/>

View file

@ -120,10 +120,23 @@ export const defaultVideoResolutionOptions = ['1080p', '720p', '480p', 'maximum'
export const downloadFormatOptions = [
{key: 'mp4', text: '.mp4', value: 'mp4'},
{key: 'mkv', text: '.mkv', value: 'mkv'},
{key: 'ogg', text: '.ogg', value: 'ogg'},
{key: 'webm', text: '.webm', value: 'webm'},
]
export const defaultVideoFormatOption = 'mp4';
export const downloadAudioFormatOptions = [
{key: 'mp3', text: '.mp3', value: 'mp3'},
{key: 'opus', text: '.opus', value: 'opus'},
{key: 'm4a', text: '.m4a', value: 'm4a'},
{key: 'flac', text: '.flac', value: 'flac'},
{key: 'vorbis', text: '.ogg', value: 'vorbis'},
{key: 'wav', text: '.wav', value: 'wav'},
];
export const defaultAudioFormatOption = 'mp3';
export const Downloaders = {
Archive: 'archive',
File: 'file',

View file

@ -1,4 +1,4 @@
import React, {useContext, useState} from 'react';
import React, {useContext, useEffect, useState} from 'react';
import {useHotkeys} from 'react-hotkeys-hook';
import {deleteVideos, downloadVideoMetadata, tagFileGroup, untagFileGroup} from "../api";
import {Link, useNavigate, useParams} from "react-router";
@ -25,7 +25,7 @@ import {ThemeContext} from "../contexts/contexts";
import {Button, darkTheme, Header, Icon, Loader, Segment, Tab} from "./Theme";
import {VideoCard} from "./Videos";
import {TagsSelector} from "../Tags";
import {Comment, CommentGroup, Input, Label} from "semantic-ui-react";
import {Comment, CommentGroup, Input, Label, Transition} from "semantic-ui-react";
const MEDIA_PATH = '/media';
@ -249,6 +249,26 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
}
}, {enableOnFormTags: false});
const isAudioFile = videoFile?.mimetype?.startsWith('audio/');
const [showAudioOverlay, setShowAudioOverlay] = useState(!!isAudioFile);
const [audioPosterHover, setAudioPosterHover] = useState(false);
const [audioPlaying, setAudioPlaying] = useState(false);
useEffect(() => {
if (!isAudioFile) return;
setShowAudioOverlay(true);
const timer = setTimeout(() => setShowAudioOverlay(false), 3000);
return () => clearTimeout(timer);
}, [isAudioFile]);
useEffect(() => {
const el = videoRef.current;
if (!isAudioFile || !el) return;
const onPlay = () => setAudioPlaying(true);
const onPause = () => setAudioPlaying(false);
el.addEventListener('play', onPlay);
el.addEventListener('pause', onPause);
return () => { el.removeEventListener('play', onPlay); el.removeEventListener('pause', onPause); };
}, [isAudioFile]);
if (videoFile === null) {
return <VideoPlaceholder/>;
}
@ -313,10 +333,10 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
<table style={tableStyle}>
<tbody>
<tr>
<td style={labelStyle}><strong>Video File</strong></td>
<td style={labelStyle}><strong>{isAudio ? 'Audio File' : 'Video File'}</strong></td>
<td>
{video['video_path']
? <><PreviewPath path={video['video_path']} mimetype='video/*' taggable={false}>
? <><PreviewPath path={video['video_path']} mimetype={isAudio ? 'audio/*' : 'video/*'} taggable={false}>
{video['video_path']}
</PreviewPath>{fileSize(videoPathFile)}</>
: 'Unknown'}
@ -434,6 +454,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
}
let videoSource = <source src={videoUrl}/>;
const isAudio = videoFile.mimetype && videoFile.mimetype.startsWith('audio/');
let prevNextVideosSegment = <Segment><p>No related videos found.</p></Segment>;
if (prevFile || nextFile) {
@ -463,7 +484,42 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
<BackButton/>
</Container>
<video controls
{isAudio ? <>
{posterUrl && <div
className='audio-poster-container'
onClick={() => {
if (videoRef.current) {
videoRef.current.paused ? videoRef.current.play() : videoRef.current.pause();
}
}}
onMouseEnter={() => setAudioPosterHover(true)}
onMouseLeave={() => setAudioPosterHover(false)}
>
<img
src={posterUrl}
alt={mediaTitle || 'Audio thumbnail'}
style={{maxWidth: '100%', maxHeight: '400px', cursor: 'pointer'}}
/>
<Transition visible={showAudioOverlay} animation='fade' duration={500}>
<div className='audio-poster-overlay'>
<Icon name='volume up' size='massive'/>
</div>
</Transition>
<Transition visible={audioPosterHover && !showAudioOverlay} animation='fade' duration={200}>
<div className='audio-poster-overlay'>
<Icon name={audioPlaying ? 'pause circle outline' : 'play circle outline'} size='massive'/>
</div>
</Transition>
</div>}
<audio controls
autoPlay={props.autoplay !== undefined ? props.autoplay : true}
id="player"
style={{width: '100%', marginTop: posterUrl ? '0.5em' : 0}}
ref={videoRef}
>
{videoSource}
</audio>
</> : <video controls
className='video-player'
autoPlay={props.autoplay !== undefined ? props.autoplay : true}
poster={posterUrl}
@ -475,7 +531,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
{videoSource}
{/* Only WebVTT captions can be displayed. */}
{captionUrls.map(i => <CaptionTrack key={i} src={i}/>)}
</video>
</video>}
<Container style={{marginTop: '1em'}}>
<Segment>