import React, {useContext} from 'react'; import {deleteVideos, tagFileGroup, untagFileGroup} from "../api"; import {Link, useNavigate, useParams} from "react-router-dom"; import _ from "lodash"; import { APIButton, BackButton, encodeMediaPath, humanFileSize, humanNumber, isoDatetimeToString, PageContainer, PreviewPath, useTitle } from "./Common"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import Container from "semantic-ui-react/dist/commonjs/elements/Container"; import {VideoPlaceholder} from "./Placeholder"; import {useChannel} from "../hooks/customHooks"; import {ThemeContext} from "../contexts/contexts"; import {Button, darkTheme, Header, Icon, Segment, Tab, TabPane} from "./Theme"; import {VideoCard} from "./Videos"; import {TagsSelector} from "../Tags"; import {Label} from "semantic-ui-react"; const MEDIA_PATH = '/media'; function videoFileLink(path, directory = false) { if (path) { const href = directory ? // Add / to end of directory. `${MEDIA_PATH}/${encodeMediaPath(path)}/` : `${MEDIA_PATH}/${encodeMediaPath(path)}`; return
{path}
} else { return 'Unknown' } } export function CaptionTrack({src, ...props}) { if (src.endsWith('.de.vtt')) { return } else if (src.endsWith('.es.vtt')) { return } else if (src.endsWith('.fr.vtt')) { return } else if (src.endsWith('.id.vtt')) { return } else if (src.endsWith('.it.vtt')) { return } else if (src.endsWith('.ja.vtt')) { return } else if (src.endsWith('.pl.vtt')) { return } else if (src.endsWith('.pt.vtt')) { return } else if (src.endsWith('.ro.vtt')) { return } else if (src.endsWith('.ru.vtt')) { return } else if (src.endsWith('.th.vtt')) { return } return } function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) { const {theme} = useContext(ThemeContext); const navigate = useNavigate(); const videoRef = React.useRef(); useTitle(videoFile === null || videoFile === undefined ? null : videoFile.video.title); let video; if (videoFile) { video = videoFile.video; } // Seeks to the `seconds` on video player. const setVideoTime = (seconds) => { videoRef.current.currentTime = seconds; } // Get the Video's channel, fallback to the URL's channel id. const {channelId} = useParams(); const {channel} = useChannel(video && video.channel_id ? video.channel_id : channelId); if (videoFile === null) { return ; } if (videoFile === undefined) { return
Could not find video
; } const handleDeleteVideo = async (video_id) => { await deleteVideos([video_id]) navigate(-1); } let videoUrl = `${MEDIA_PATH}/${encodeMediaPath(video.video_path)}`; let downloadUrl = `/download/${encodeMediaPath(video.video_path)}`; let posterUrl = video.poster_path ? `${MEDIA_PATH}/${encodeMediaPath(video.poster_path)}` : null; const {caption_files} = video; const captionUrls = caption_files && caption_files.length > 0 ? caption_files.filter(i => i['mimetype'] === 'text/vtt').map(i => `${MEDIA_PATH}/${encodeMediaPath(i['path'])}`) : []; let description = 'No description available.'; if (video && video['description']) { // Only replace empty description if there is one available. description = video['description']; description = chaptersInDescription(description, setVideoTime) } let descriptionPane = { menuItem: 'Description', render: () =>
                {description}
            
}; let aboutPane = { menuItem: 'About', render: () =>

Size

{videoFile.size ? humanFileSize(videoFile.size) : 'Unknown'}

Source URL

{video.url ? {video.url} : 'N/A'}

View Count

{video.view_count ? humanNumber(video.view_count) : 'N/A'}

Censored

{video.censored ? 'Yes' : 'No'}

Codec Names

<>{video.codec_names ? video.codec_names.map(i => ) : 'N/A'}
} let captionsPane = { menuItem: 'Captions', render: () =>
{video.caption || 'No captions available.'}
}; const {poster_file, info_json_file} = video; let filesPane = { menuItem: 'Files', render: () =>

Video File

{videoFileLink(video['video_path'])}

Info JSON File

{info_json_file && {info_json_file['path']} }

Caption Files

{caption_files && caption_files.map(i =>

{i['path']}

) }

Poster File

{poster_file && {poster_file['path']} }

Directory

{videoFileLink(videoFile['directory'], true)}
} let tabPanes = [descriptionPane, aboutPane, filesPane, captionsPane]; const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true}; const localAddTag = async (name) => { await tagFileGroup(videoFile, name); await fetchVideo(); } const localRemoveTag = async (name) => { await untagFileGroup(videoFile, name); await fetchVideo(); } let videoSource = ; let prevNextVideosSegment =

No related videos found.

; if (prevFile || nextFile) { prevNextVideosSegment = {prevFile && <>
Older
}
{nextFile && <>
Newer
}
} return <>
{videoFile.title || videoFile.stem || video.video_path}
{video.upload_date &&

{isoDatetimeToString(video.upload_date)}

}

{channel && {channel.name} }

await handleDeleteVideo(video.id)} obeyWROLMode={true} >Delete


{prevNextVideosSegment}
} export default VideoPage; const chapterRegex = new RegExp('^(\\(?(?:((\\d?\\d):)?(?:(\\d?\\d):(\\d\\d)))\\)?)\\s+(.*)$', 'i'); function chaptersInDescription(description, setVideoTime) { if (description && description.length > 0) { try { const lines = _.split(description, '\n'); let newLines = []; for (let i = 0; i <= lines.length; i++) { const line = lines[i]; const match = line ? line.match(chapterRegex) : null; let link; if (match) { // This line in the description starts with a chapter timestamp, parse it and create a link. try { const timestamp = match[1]; const title = match[6]; // Assume 0 if no part of timestamp could be found. const [hour, minute, second] = match.slice(3, 6).map(i => parseInt(i) || 0); // Convert timestamp to seconds. const seconds = (((hour * 60) + minute) * 60) + second; link = <> setVideoTime(seconds)}>{timestamp}  {title} ; } catch (e) { // Report an error while creating timestamp link. console.error(e); } // Use the link if we could create it, otherwise fallback to the original `line`. newLines = [...newLines, link || line]; } else if (line !== undefined) { // Line does not start with a timestamp. newLines = [...newLines, line]; } } // Map all lines and links with a break between. return <> {newLines.map((i, idx) =>
{i}
)} ; } catch (e) { // Some error happened while parsing description. Report it but don't fail. console.error(e); } } // Error occurred, or no description, don't fail. return description; }