import clsx from "clsx"; import { ProxyImage } from "@/components/custom/proxyImage"; import { AspectRatio } from "@/components/ui/aspect-ratio"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; import { toast } from "sonner"; import { useAppContext } from "@/providers/appContextProvider"; import { useCurrentVideoMetadataStore, useDownloaderPageStatesStore, useSettingsPageStatesStore } from "@/services/store"; import { determineFileType, fileFormatFilter, formatBitrate, formatDurationString, formatFileSize, formatReleaseDate, formatYtStyleCount, isObjEmpty, sortByBitrate } from "@/utils"; import { Calendar, Clock, DownloadCloud, Eye, Info, Loader2, Music, ThumbsUp, Video, File, ListVideo, PackageSearch, AlertCircleIcon, X, Settings2, Clipboard } from "lucide-react"; import { FormatSelectionGroup, FormatSelectionGroupItem } from "@/components/custom/formatSelectionGroup"; import { useEffect, useRef } from "react"; import { ToggleGroup, ToggleGroupItem } from "@/components/custom/legacyToggleGroup"; import { VideoFormat } from "@/types/video"; // import { PlaylistToggleGroup, PlaylistToggleGroupItem } from "@/components/custom/playlistToggleGroup"; import { PlaylistSelectionGroup, PlaylistSelectionGroupItem } from "@/components/custom/playlistSelectionGroup"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod" import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form"; import { config } from "@/config"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { invoke } from "@tauri-apps/api/core"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { readText } from '@tauri-apps/plugin-clipboard-manager'; const searchFormSchema = z.object({ url: z.url({ error: (issue) => issue.input === undefined || issue.input === null || issue.input === "" ? "URL is required" : "Invalid URL format" }), }); export default function DownloaderPage() { const { fetchVideoMetadata, startDownload } = useAppContext(); const videoUrl = useCurrentVideoMetadataStore((state) => state.videoUrl); const videoMetadata = useCurrentVideoMetadataStore((state) => state.videoMetadata); const isMetadataLoading = useCurrentVideoMetadataStore((state) => state.isMetadataLoading); const requestedUrl = useCurrentVideoMetadataStore((state) => state.requestedUrl); const autoSubmitSearch = useCurrentVideoMetadataStore((state) => state.autoSubmitSearch); const searchPid = useCurrentVideoMetadataStore((state) => state.searchPid); const setVideoUrl = useCurrentVideoMetadataStore((state) => state.setVideoUrl); const setVideoMetadata = useCurrentVideoMetadataStore((state) => state.setVideoMetadata); const setIsMetadataLoading = useCurrentVideoMetadataStore((state) => state.setIsMetadataLoading); const setRequestedUrl = useCurrentVideoMetadataStore((state) => state.setRequestedUrl); const setAutoSubmitSearch = useCurrentVideoMetadataStore((state) => state.setAutoSubmitSearch); const setSearchPid = useCurrentVideoMetadataStore((state) => state.setSearchPid); const setShowSearchError = useCurrentVideoMetadataStore((state) => state.setShowSearchError); const activeDownloadModeTab = useDownloaderPageStatesStore((state) => state.activeDownloadModeTab); const activeDownloadConfigurationTab = useDownloaderPageStatesStore((state) => state.activeDownloadConfigurationTab); const isStartingDownload = useDownloaderPageStatesStore((state) => state.isStartingDownload); const selectedDownloadFormat = useDownloaderPageStatesStore((state) => state.selectedDownloadFormat); const selectedCombinableVideoFormat = useDownloaderPageStatesStore((state) => state.selectedCombinableVideoFormat); const selectedCombinableAudioFormat = useDownloaderPageStatesStore((state) => state.selectedCombinableAudioFormat); const selectedSubtitles = useDownloaderPageStatesStore((state) => state.selectedSubtitles); const selectedPlaylistVideoIndex = useDownloaderPageStatesStore((state) => state.selectedPlaylistVideoIndex); const downloadConfiguration = useDownloaderPageStatesStore((state) => state.downloadConfiguration); const setActiveDownloadModeTab = useDownloaderPageStatesStore((state) => state.setActiveDownloadModeTab); const setActiveDownloadConfigurationTab = useDownloaderPageStatesStore((state) => state.setActiveDownloadConfigurationTab); const setIsStartingDownload = useDownloaderPageStatesStore((state) => state.setIsStartingDownload); const setSelectedDownloadFormat = useDownloaderPageStatesStore((state) => state.setSelectedDownloadFormat); const setSelectedCombinableVideoFormat = useDownloaderPageStatesStore((state) => state.setSelectedCombinableVideoFormat); const setSelectedCombinableAudioFormat = useDownloaderPageStatesStore((state) => state.setSelectedCombinableAudioFormat); const setSelectedSubtitles = useDownloaderPageStatesStore((state) => state.setSelectedSubtitles); const setSelectedPlaylistVideoIndex = useDownloaderPageStatesStore((state) => state.setSelectedPlaylistVideoIndex); const setDownloadConfigurationKey = useDownloaderPageStatesStore((state) => state.setDownloadConfigurationKey); const resetDownloadConfiguration = useDownloaderPageStatesStore((state) => state.resetDownloadConfiguration); const videoFormat = useSettingsPageStatesStore(state => state.settings.video_format); const audioFormat = useSettingsPageStatesStore(state => state.settings.audio_format); const embedVideoMetadata = useSettingsPageStatesStore(state => state.settings.embed_video_metadata); const embedAudioMetadata = useSettingsPageStatesStore(state => state.settings.embed_audio_metadata); const embedAudioThumbnail = useSettingsPageStatesStore(state => state.settings.embed_audio_thumbnail); const useCustomCommands = useSettingsPageStatesStore(state => state.settings.use_custom_commands); const customCommands = useSettingsPageStatesStore(state => state.settings.custom_commands); const audioOnlyFormats = videoMetadata?._type === 'video' ? sortByBitrate(videoMetadata?.formats.filter(fileFormatFilter('audio'))) : videoMetadata?._type === 'playlist' ? sortByBitrate(videoMetadata?.entries[Number(selectedPlaylistVideoIndex) - 1].formats.filter(fileFormatFilter('audio'))) : []; const videoOnlyFormats = videoMetadata?._type === 'video' ? sortByBitrate(videoMetadata?.formats.filter(fileFormatFilter('video'))) : videoMetadata?._type === 'playlist' ? sortByBitrate(videoMetadata?.entries[Number(selectedPlaylistVideoIndex) - 1].formats.filter(fileFormatFilter('video'))) : []; const combinedFormats = videoMetadata?._type === 'video' ? sortByBitrate(videoMetadata?.formats.filter(fileFormatFilter('video+audio'))) : videoMetadata?._type === 'playlist' ? sortByBitrate(videoMetadata?.entries[Number(selectedPlaylistVideoIndex) - 1].formats.filter(fileFormatFilter('video+audio'))) : []; const av1VideoFormats = videoMetadata?.webpage_url_domain === 'youtube.com' && videoMetadata?._type === 'video' ? sortByBitrate(videoMetadata?.formats.filter((format) => format.vcodec?.startsWith('av01'))) : videoMetadata?.webpage_url_domain === 'youtube.com' && videoMetadata?._type === 'playlist' ? sortByBitrate(videoMetadata?.entries[Number(selectedPlaylistVideoIndex) - 1].formats.filter((format) => format.vcodec?.startsWith('av01'))) : []; const opusAudioFormats = videoMetadata?.webpage_url_domain === 'youtube.com' && videoMetadata?._type === 'video' ? sortByBitrate(videoMetadata?.formats.filter((format) => format.acodec?.startsWith('opus'))) : videoMetadata?.webpage_url_domain === 'youtube.com' && videoMetadata?._type === 'playlist' ? sortByBitrate(videoMetadata?.entries[Number(selectedPlaylistVideoIndex) - 1].formats.filter((format) => format.acodec?.startsWith('opus'))) : []; const qualityPresetFormats: VideoFormat[] | undefined = videoMetadata?.webpage_url_domain === 'youtube.com' ? av1VideoFormats && opusAudioFormats ? av1VideoFormats.map((av1Format) => { const opusFormat = av1Format.format_note.startsWith('144p') || av1Format.format_note.startsWith('240p') ? opusAudioFormats[opusAudioFormats.length - 1] : opusAudioFormats[0] return { ...av1Format, format: `${av1Format.format}+${opusFormat?.format}`, format_id: `${av1Format.format_id}+${opusFormat?.format_id}`, format_note: `${av1Format.format_note}+${opusFormat?.format_note}`, filesize_approx: av1Format.filesize_approx && opusFormat.filesize_approx ? av1Format.filesize_approx + opusFormat.filesize_approx : null, acodec: opusFormat?.acodec, audio_ext: opusFormat.audio_ext, ext: 'webm', tbr: av1Format.tbr && opusFormat.tbr ? av1Format.tbr + opusFormat.tbr : null, }; }) : [] : []; const allFilteredFormats = [...(audioOnlyFormats || []), ...(videoOnlyFormats || []), ...(combinedFormats || []), ...(qualityPresetFormats || [])]; const selectedFormat = (() => { if (videoMetadata?._type === 'video') { if (selectedDownloadFormat === 'best') { return videoMetadata?.requested_downloads[0]; } return allFilteredFormats.find( (format) => format.format_id === selectedDownloadFormat ); } else if (videoMetadata?._type === 'playlist') { if (selectedDownloadFormat === 'best') { return videoMetadata?.entries[Number(selectedPlaylistVideoIndex) - 1].requested_downloads[0]; } return allFilteredFormats.find( (format) => format.format_id === selectedDownloadFormat ); } })(); const selectedFormatFileType = determineFileType(selectedFormat?.vcodec, selectedFormat?.acodec); const selectedVideoFormat = (() => { if (videoMetadata?._type === 'video') { return allFilteredFormats.find( (format) => format.format_id === selectedCombinableVideoFormat ); } else if (videoMetadata?._type === 'playlist') { return allFilteredFormats.find( (format) => format.format_id === selectedCombinableVideoFormat ); } })(); const selectedAudioFormat = (() => { if (videoMetadata?._type === 'video') { return allFilteredFormats.find( (format) => format.format_id === selectedCombinableAudioFormat ); } else if (videoMetadata?._type === 'playlist') { return allFilteredFormats.find( (format) => format.format_id === selectedCombinableAudioFormat ); } })(); const subtitles = videoMetadata?._type === 'video' ? (videoMetadata?.subtitles || {}) : videoMetadata?._type === 'playlist' ? (videoMetadata?.entries[Number(selectedPlaylistVideoIndex) - 1].subtitles || {}) : {}; const subtitleLanguages = Object.keys(subtitles).map(langCode => ({ code: langCode, lang: subtitles[langCode][0].name || langCode })); const containerRef = useRef(null); const bottomBarRef = useRef(null); let selectedFormatExtensionMsg = 'Auto - unknown'; if (activeDownloadModeTab === 'combine') { if (downloadConfiguration.output_format && downloadConfiguration.output_format !== 'auto') { selectedFormatExtensionMsg = `Combined - ${downloadConfiguration.output_format.toUpperCase()}`; } else if (videoFormat !== 'auto') { selectedFormatExtensionMsg = `Combined - ${videoFormat.toUpperCase()}`; } else if (selectedAudioFormat?.ext && selectedVideoFormat?.ext) { selectedFormatExtensionMsg = `Combined - ${selectedVideoFormat.ext.toUpperCase()} + ${selectedAudioFormat.ext.toUpperCase()}`; } else { selectedFormatExtensionMsg = `Combined - unknown`; } } else if (selectedFormat?.ext) { if ((selectedFormatFileType === 'video+audio' || selectedFormatFileType === 'video') && ((downloadConfiguration.output_format && downloadConfiguration.output_format !== 'auto') || videoFormat !== 'auto')) { selectedFormatExtensionMsg = `Forced - ${(downloadConfiguration.output_format && downloadConfiguration.output_format !== 'auto') ? downloadConfiguration.output_format.toUpperCase() : videoFormat.toUpperCase()}`; } else if (selectedFormatFileType === 'audio' && ((downloadConfiguration.output_format && downloadConfiguration.output_format !== 'auto') || audioFormat !== 'auto')) { selectedFormatExtensionMsg = `Forced - ${(downloadConfiguration.output_format && downloadConfiguration.output_format !== 'auto') ? downloadConfiguration.output_format.toUpperCase() : audioFormat.toUpperCase()}`; } else if (selectedFormatFileType === 'unknown' && downloadConfiguration.output_format && downloadConfiguration.output_format !== 'auto') { selectedFormatExtensionMsg = `Forced - ${downloadConfiguration.output_format.toUpperCase()}`; } else { selectedFormatExtensionMsg = `Auto - ${selectedFormat.ext.toUpperCase()}`; } } let selectedFormatResolutionMsg = 'unknown'; if (activeDownloadModeTab === 'combine') { selectedFormatResolutionMsg = `${selectedVideoFormat?.resolution ?? 'unknown'} + ${selectedAudioFormat?.tbr ? formatBitrate(selectedAudioFormat.tbr) : 'unknown'}`; } else if (selectedFormat?.resolution) { selectedFormatResolutionMsg = selectedFormat.resolution; } let selectedFormatDynamicRangeMsg = ''; if (activeDownloadModeTab === 'combine') { selectedFormatDynamicRangeMsg = selectedVideoFormat?.dynamic_range && selectedVideoFormat.dynamic_range !== 'SDR' ? selectedVideoFormat.dynamic_range : ''; } else if (selectedFormat?.dynamic_range && selectedFormat.dynamic_range !== 'SDR') { selectedFormatDynamicRangeMsg = selectedFormat.dynamic_range; } let selectedFormatFileSizeMsg = 'unknown filesize'; if (activeDownloadModeTab === 'combine') { selectedFormatFileSizeMsg = selectedVideoFormat?.filesize_approx && selectedAudioFormat?.filesize_approx ? formatFileSize(selectedVideoFormat.filesize_approx + selectedAudioFormat.filesize_approx) : 'unknown filesize'; } else if (selectedFormat?.filesize_approx) { selectedFormatFileSizeMsg = formatFileSize(selectedFormat.filesize_approx); } let selectedFormatFinalMsg = ''; if (activeDownloadModeTab === 'combine') { if (selectedCombinableVideoFormat && selectedCombinableAudioFormat) { selectedFormatFinalMsg = `${selectedFormatExtensionMsg} (${selectedFormatResolutionMsg}) ${selectedFormatDynamicRangeMsg} ${selectedSubtitles.length > 0 ? `• ESUB` : ''} • ${selectedFormatFileSizeMsg}`; } else { selectedFormatFinalMsg = `Choose a video and audio stream to combine`; } } else { if (selectedFormat) { selectedFormatFinalMsg = `${selectedFormatExtensionMsg} (${selectedFormatResolutionMsg}) ${selectedFormatDynamicRangeMsg} ${selectedSubtitles.length > 0 ? `• ESUB` : ''} • ${selectedFormatFileSizeMsg}`; } else { selectedFormatFinalMsg = `Choose a stream to download`; } } const searchForm = useForm>({ resolver: zodResolver(searchFormSchema), defaultValues: { url: videoUrl, }, mode: "onChange", }) const watchedUrl = searchForm.watch("url"); const { errors: searchFormErrors } = searchForm.formState; function handleSearchSubmit(values: z.infer) { setVideoMetadata(null); setSearchPid(null); setShowSearchError(true); setIsMetadataLoading(true); setSelectedDownloadFormat('best'); setSelectedCombinableVideoFormat(''); setSelectedCombinableAudioFormat(''); setSelectedSubtitles([]); setSelectedPlaylistVideoIndex('1'); resetDownloadConfiguration(); fetchVideoMetadata(values.url).then((metadata) => { if (!metadata || (metadata._type !== 'video' && metadata._type !== 'playlist') || (metadata && metadata._type === 'video' && metadata.formats.length <= 0) || (metadata && metadata._type === 'playlist' && metadata.entries.length <= 0)) { const showSearchError = useCurrentVideoMetadataStore.getState().showSearchError; if (showSearchError) { toast.error("Oops! No results found", { description: "The provided URL does not contain any downloadable content or you are not connected to the internet. Please check the URL, your network connection and try again.", }); } } if (metadata && (metadata._type === 'video' || metadata._type === 'playlist') && ((metadata._type === 'video' && metadata.formats.length > 0) || (metadata._type === 'playlist' && metadata.entries.length > 0))) setVideoMetadata(metadata); if (metadata) console.log(metadata); setIsMetadataLoading(false); }); } const cancelSearch = async (pid: number | null) => { setShowSearchError(false); if (pid) { console.log("Killing process with PID:", pid); await invoke('kill_all_process', { pid: pid }); } setVideoMetadata(null); setIsMetadataLoading(false); }; useEffect(() => { const updateBottomBarWidth = (): void => { if (containerRef.current && bottomBarRef.current) { bottomBarRef.current.style.width = `${containerRef.current.offsetWidth}px`; const containerRect = containerRef.current.getBoundingClientRect(); bottomBarRef.current.style.left = `${containerRect.left}px`; } }; updateBottomBarWidth(); const resizeObserver = new ResizeObserver(() => { updateBottomBarWidth(); }); if (containerRef.current) { resizeObserver.observe(containerRef.current); } window.addEventListener('resize', updateBottomBarWidth); window.addEventListener('scroll', updateBottomBarWidth); return () => { resizeObserver.disconnect(); window.removeEventListener('resize', updateBottomBarWidth); window.removeEventListener('scroll', updateBottomBarWidth); }; }, []); useEffect(() => { useCustomCommands ? setActiveDownloadConfigurationTab('commands') : setActiveDownloadConfigurationTab('options'); }, []); useEffect(() => { if (watchedUrl !== videoUrl) { setVideoUrl(watchedUrl); } }, [watchedUrl, videoUrl, setVideoUrl]); useEffect(() => { const handleAutoSubmitRequest = async () => { // Update form and state when requestedUrl changes if (requestedUrl && requestedUrl !== searchForm.getValues("url") && !isMetadataLoading) { searchForm.setValue("url", requestedUrl); setVideoUrl(requestedUrl); } // Auto-submit the form if the flag is set if (autoSubmitSearch && requestedUrl) { if (!isMetadataLoading) { // trigger a validation check on the URL field first then get the result await searchForm.trigger("url"); const isValidUrl = !searchForm.getFieldState("url").invalid; if (isValidUrl) { // Reset the flag first to prevent loops setAutoSubmitSearch(false); // Submit the form with a small delay to ensure UI is ready setTimeout(() => { handleSearchSubmit({ url: requestedUrl }); setRequestedUrl(''); }, 300); } else { // If URL is invalid, just reset the flag setAutoSubmitSearch(false); setRequestedUrl(''); toast.error("Invalid URL", { description: "The provided URL is not valid.", }); } } else { // If metadata is loading, just reset the flag setAutoSubmitSearch(false); setRequestedUrl(''); toast.info("Search in progress", { description: "There's a search in progress, Please try again later.", }); } } else { // If auto-submit is not set, reset the flag setAutoSubmitSearch(false); setRequestedUrl(''); } } handleAutoSubmitRequest(); }, [requestedUrl, autoSubmitSearch, isMetadataLoading]); // useEffect(() => { // console.log("Selected playlist items:", selectedVideos) // }), [selectedVideos] return (
{config.appName} Search
( )} /> {isMetadataLoading && ( )} {!isMetadataLoading && !videoUrl && ( )} {!isMetadataLoading && videoUrl && ( )}
{!isMetadataLoading && videoMetadata && videoMetadata._type === 'video' && ( // === Single Video ===

Metadata

{videoMetadata.title ? videoMetadata.title : 'UNTITLED'}

{videoMetadata.channel || videoMetadata.uploader || 'unknown'}

{videoMetadata.duration_string ? formatDurationString(videoMetadata.duration_string) : 'unknown'} {videoMetadata.view_count ? formatYtStyleCount(videoMetadata.view_count) : 'unknown'} {videoMetadata.like_count ? formatYtStyleCount(videoMetadata.like_count) : 'unknown'}

{videoMetadata.upload_date ? formatReleaseDate(videoMetadata.upload_date) : 'unknown'}

{videoMetadata.resolution && ( {videoMetadata.resolution} )} {videoMetadata.tbr && ( {formatBitrate(videoMetadata.tbr)} )} {videoMetadata.fps && ( {videoMetadata.fps} fps )} {videoMetadata.subtitles && !isObjEmpty(videoMetadata.subtitles) && ( SUB )} {videoMetadata.dynamic_range && videoMetadata.dynamic_range !== 'SDR' && ( {videoMetadata.dynamic_range} )}
Extracted from {videoMetadata.extractor ? videoMetadata.extractor.charAt(0).toUpperCase() + videoMetadata.extractor.slice(1) : 'Unknown'}
{ setActiveDownloadModeTab(tab) setDownloadConfigurationKey('output_format', null); setDownloadConfigurationKey('embed_metadata', null); setDownloadConfigurationKey('embed_thumbnail', null); }} >

Download Options

Selective Combine
{subtitles && !isObjEmpty(subtitles) && ( setSelectedSubtitles(value)} // disabled={selectedFormat?.ext !== 'mp4' && selectedFormat?.ext !== 'mkv' && selectedFormat?.ext !== 'webm'} >

Subtitle Languages

{subtitleLanguages.map((lang) => ( {lang.lang} ))}
)} { setSelectedDownloadFormat(value); // const currentlySelectedFormat = value === 'best' ? videoMetadata?.requested_downloads[0] : allFilteredFormats.find((format) => format.format_id === value); // if (currentlySelectedFormat?.ext !== 'mp4' && currentlySelectedFormat?.ext !== 'mkv' && currentlySelectedFormat?.ext !== 'webm') { // setSelectedSubtitles([]); // } setDownloadConfigurationKey('output_format', null); setDownloadConfigurationKey('embed_metadata', null); setDownloadConfigurationKey('embed_thumbnail', null); }} >

Suggested

{qualityPresetFormats && qualityPresetFormats.length > 0 && ( <>

Quality Presets

{qualityPresetFormats.map((format) => ( ))}
)} {audioOnlyFormats && audioOnlyFormats.length > 0 && ( <>

Audio

{audioOnlyFormats.map((format) => ( ))}
)} {videoOnlyFormats && videoOnlyFormats.length > 0 && ( <>

Video {videoOnlyFormats.every(format => format.acodec === 'none') ? '(no audio)' : ''}

{videoOnlyFormats.map((format) => ( ))}
)} {combinedFormats && combinedFormats.length > 0 && ( <>

Video

{combinedFormats.map((format) => ( ))}
)}
{audioOnlyFormats && audioOnlyFormats.length > 0 && videoOnlyFormats && videoOnlyFormats.length > 0 && subtitles && !isObjEmpty(subtitles) && ( setSelectedSubtitles(value)} >

Subtitle Languages

{subtitleLanguages.map((lang) => ( {lang.lang} ))}
)} { setSelectedCombinableAudioFormat(value); setDownloadConfigurationKey('output_format', null); setDownloadConfigurationKey('embed_metadata', null); setDownloadConfigurationKey('embed_thumbnail', null); }} > {videoOnlyFormats && videoOnlyFormats.length > 0 && audioOnlyFormats && audioOnlyFormats.length > 0 && ( <>

Audio

{audioOnlyFormats.map((format) => ( ))}
)}
{ setSelectedCombinableVideoFormat(value); setDownloadConfigurationKey('output_format', null); setDownloadConfigurationKey('embed_metadata', null); setDownloadConfigurationKey('embed_thumbnail', null); }} > {audioOnlyFormats && audioOnlyFormats.length > 0 && videoOnlyFormats && videoOnlyFormats.length > 0 && ( <>

Video

{videoOnlyFormats.map((format) => ( ))}
)}
{(!videoOnlyFormats || videoOnlyFormats.length === 0 || !audioOnlyFormats || audioOnlyFormats.length === 0) && ( Unable to use Combine Mode! Cannot use combine mode for this video as it does not have both audio and video formats available. Use Selective Mode or try another video. )}
)} {!isMetadataLoading && videoMetadata && videoMetadata._type === 'playlist' && ( // === Playlists ===

Playlist ({videoMetadata.entries[0].n_entries})

{videoMetadata.entries[0].playlist_title ? videoMetadata.entries[0].playlist_title : 'UNTITLED'}

{videoMetadata.entries[0].playlist_channel || videoMetadata.entries[0].playlist_uploader || 'unknown'}

{/* {videoMetadata.entries.map((entry) => entry ? ( ) : null)} */} { setSelectedPlaylistVideoIndex(value); setSelectedDownloadFormat('best'); setSelectedSubtitles([]); setSelectedCombinableVideoFormat(''); setSelectedCombinableAudioFormat(''); resetDownloadConfiguration(); }} > {videoMetadata.entries.map((entry) => entry ? ( ) : null)}
Extracted from {videoMetadata.entries[0].extractor ? videoMetadata.entries[0].extractor.charAt(0).toUpperCase() + videoMetadata.entries[0].extractor.slice(1) : 'Unknown'}
setActiveDownloadModeTab(tab)} >

Download Options

Selective Combine
{subtitles && !isObjEmpty(subtitles) && ( setSelectedSubtitles(value)} disabled={selectedFormat?.ext !== 'mp4' && selectedFormat?.ext !== 'mkv' && selectedFormat?.ext !== 'webm'} >

Subtitle Languages

{subtitleLanguages.map((lang) => ( {lang.lang} ))}
)} { setSelectedDownloadFormat(value); const currentlySelectedFormat = value === 'best' ? videoMetadata?.entries[Number(value) - 1].requested_downloads[0] : allFilteredFormats.find((format) => format.format_id === value); if (currentlySelectedFormat?.ext !== 'mp4' && currentlySelectedFormat?.ext !== 'mkv' && currentlySelectedFormat?.ext !== 'webm') { setSelectedSubtitles([]); } }} >

Suggested

{qualityPresetFormats && qualityPresetFormats.length > 0 && ( <>

Quality Presets

{qualityPresetFormats.map((format) => ( ))}
)} {audioOnlyFormats && audioOnlyFormats.length > 0 && ( <>

Audio

{audioOnlyFormats.map((format) => ( ))}
)} {videoOnlyFormats && videoOnlyFormats.length > 0 && ( <>

Video {videoOnlyFormats.every(format => format.acodec === 'none') ? '(no audio)' : ''}

{videoOnlyFormats.map((format) => ( ))}
)} {combinedFormats && combinedFormats.length > 0 && ( <>

Video

{combinedFormats.map((format) => ( ))}
)}
{audioOnlyFormats && audioOnlyFormats.length > 0 && videoOnlyFormats && videoOnlyFormats.length > 0 && subtitles && !isObjEmpty(subtitles) && ( setSelectedSubtitles(value)} disabled={selectedFormat?.ext !== 'mp4' && selectedFormat?.ext !== 'mkv' && selectedFormat?.ext !== 'webm'} >

Subtitle Languages

{subtitleLanguages.map((lang) => ( {lang.lang} ))}
)} { setSelectedCombinableAudioFormat(value); }} > {videoOnlyFormats && videoOnlyFormats.length > 0 && audioOnlyFormats && audioOnlyFormats.length > 0 && ( <>

Audio

{audioOnlyFormats.map((format) => ( ))}
)}
{ setSelectedCombinableVideoFormat(value); }} > {audioOnlyFormats && audioOnlyFormats.length > 0 && videoOnlyFormats && videoOnlyFormats.length > 0 && ( <>

Video

{videoOnlyFormats.map((format) => ( ))}
)}
{(!videoOnlyFormats || videoOnlyFormats.length === 0 || !audioOnlyFormats || audioOnlyFormats.length === 0) && ( Unable to use Combine Mode! Cannot use combine mode for this video as it does not have both audio and video formats available. Use Selective Mode or try another video. )}
)} {!isMetadataLoading && videoMetadata && selectedDownloadFormat && ( // === Bottom Bar ===
{selectedFormatFileType && (selectedFormatFileType === 'video' || selectedFormatFileType === 'video+audio') && (
{videoMetadata._type === 'video' ? videoMetadata.title : videoMetadata._type === 'playlist' ? videoMetadata.entries[Number(selectedPlaylistVideoIndex) - 1].title : 'Unknown' } {selectedFormatFinalMsg}

Configurations

Configurations Tweak this download's configurations
setActiveDownloadConfigurationTab(tab)} > Options Commands {useCustomCommands ? ( Options Unavailable! You cannot use these options when custom commands are enabled. To use these options, disable custom commands from Settings. ) : null}
{(selectedFormatFileType && (selectedFormatFileType === 'video' || selectedFormatFileType === 'video+audio')) || activeDownloadModeTab === 'combine' ? ( setDownloadConfigurationKey('output_format', value)} disabled={useCustomCommands} >
) : selectedFormatFileType && selectedFormatFileType === 'audio' ? ( setDownloadConfigurationKey('output_format', value)} disabled={useCustomCommands} >
) : ( setDownloadConfigurationKey('output_format', value)} disabled={useCustomCommands} >
)}
setDownloadConfigurationKey('embed_metadata', checked)} disabled={useCustomCommands} />
setDownloadConfigurationKey('embed_thumbnail', checked)} disabled={useCustomCommands} />
{!useCustomCommands ? ( Enable Custom Commands! To run custom commands for downloads, please enable it from the Settings. ) : null}
{customCommands.length === 0 ? (

NO CUSTOM COMMAND TEMPLATE ADDED YET!

) : ( setDownloadConfigurationKey('custom_command', value)} > {customCommands.map((command) => (
))}
)}
)}
); }