2023-07-21 15:14:09 -06:00
|
|
|
import React, {useContext} from 'react';
|
2024-02-20 13:47:12 -07:00
|
|
|
import {deleteVideos, downloadVideoMetadata, tagFileGroup, untagFileGroup} from "../api";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {Link, useNavigate, useParams} from "react-router-dom";
|
2022-11-15 15:03:12 -07:00
|
|
|
import _ from "lodash";
|
2023-02-17 16:30:25 -07:00
|
|
|
import {
|
2023-07-21 15:14:09 -06:00
|
|
|
APIButton,
|
2023-02-17 16:30:25 -07:00
|
|
|
BackButton,
|
2023-03-29 13:46:39 -06:00
|
|
|
encodeMediaPath,
|
2024-02-20 13:47:12 -07:00
|
|
|
getParentDirectory,
|
2023-02-17 16:30:25 -07:00
|
|
|
humanFileSize,
|
2024-10-02 21:59:33 -06:00
|
|
|
humanNumber, isoDatetimeToElapsedPopup,
|
2023-02-17 16:30:25 -07:00
|
|
|
isoDatetimeToString,
|
2024-02-27 18:54:14 -07:00
|
|
|
MultilineText,
|
2023-02-17 16:30:25 -07:00
|
|
|
PageContainer,
|
|
|
|
|
PreviewPath,
|
|
|
|
|
useTitle
|
|
|
|
|
} from "./Common";
|
2021-11-01 16:42:52 -06:00
|
|
|
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
2022-01-31 09:32:06 -07:00
|
|
|
import Container from "semantic-ui-react/dist/commonjs/elements/Container";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {VideoPlaceholder} from "./Placeholder";
|
|
|
|
|
import {useChannel} from "../hooks/customHooks";
|
2022-10-25 15:25:44 -06:00
|
|
|
import {ThemeContext} from "../contexts/contexts";
|
|
|
|
|
import {Button, darkTheme, Header, Icon, Segment, Tab, TabPane} from "./Theme";
|
2022-11-04 09:58:38 -06:00
|
|
|
import {VideoCard} from "./Videos";
|
2023-04-05 14:48:13 -06:00
|
|
|
import {TagsSelector} from "../Tags";
|
2024-02-20 13:47:12 -07:00
|
|
|
import {Comment, CommentGroup, Label} from "semantic-ui-react";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
const MEDIA_PATH = '/media';
|
|
|
|
|
|
|
|
|
|
|
2022-12-19 10:40:01 -07:00
|
|
|
function videoFileLink(path, directory = false) {
|
2022-11-30 18:26:38 -07:00
|
|
|
if (path) {
|
|
|
|
|
const href = directory ?
|
2023-03-24 08:58:18 -06:00
|
|
|
// Add / to end of directory.
|
2023-03-29 13:46:39 -06:00
|
|
|
`${MEDIA_PATH}/${encodeMediaPath(path)}/` :
|
|
|
|
|
`${MEDIA_PATH}/${encodeMediaPath(path)}`;
|
2022-12-19 10:40:01 -07:00
|
|
|
return <a href={href} target='_blank' rel='noopener noreferrer'>
|
2022-11-30 18:26:38 -07:00
|
|
|
<pre>{path}</pre>
|
|
|
|
|
</a>
|
|
|
|
|
} else {
|
|
|
|
|
return 'Unknown'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:36:27 -06:00
|
|
|
export function CaptionTrack({src, ...props}) {
|
|
|
|
|
if (src.endsWith('.de.vtt')) {
|
|
|
|
|
return <track kind="captions" label="German" src={src} srcLang="de" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.es.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Spanish" src={src} srcLang="es" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.fr.vtt')) {
|
|
|
|
|
return <track kind="captions" label="French" src={src} srcLang="fr" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.id.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Indonesian" src={src} srcLang="id" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.it.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Italian" src={src} srcLang="it" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.ja.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Japanese" src={src} srcLang="ja" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.pl.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Polish" src={src} srcLang="pl" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.pt.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Portuguese" src={src} srcLang="pt" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.ro.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Romanian" src={src} srcLang="ro" {...props}/>
|
2023-08-17 19:31:21 -06:00
|
|
|
} else if (src.endsWith('.ru.vtt')) {
|
2023-08-03 22:36:27 -06:00
|
|
|
return <track kind="captions" label="Russian" src={src} srcLang="ru" {...props}/>
|
|
|
|
|
} else if (src.endsWith('.th.vtt')) {
|
|
|
|
|
return <track kind="captions" label="Thai" src={src} srcLang="th" {...props}/>
|
|
|
|
|
}
|
|
|
|
|
return <track kind="captions" label="English" src={src} srcLang="en" default {...props}/>
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const NoComments = ({video}) => {
|
|
|
|
|
const videoUrl = video.url;
|
|
|
|
|
|
|
|
|
|
const handleRefresh = async () => {
|
|
|
|
|
const destination = getParentDirectory(video.primary_path);
|
|
|
|
|
await downloadVideoMetadata(videoUrl, destination);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (videoUrl) {
|
|
|
|
|
return <React.Fragment>
|
|
|
|
|
<p>No comments have been been downloaded. Refresh the video?</p>
|
|
|
|
|
|
|
|
|
|
<APIButton
|
|
|
|
|
color='blue'
|
|
|
|
|
size='large'
|
|
|
|
|
onClick={handleRefresh}
|
|
|
|
|
>Refresh</APIButton>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
} else {
|
|
|
|
|
return <React.Fragment>
|
|
|
|
|
<p>No comment have been downloaded. WROLPi does not know the URL of this video, so it cannot download
|
|
|
|
|
the comments.</p>
|
|
|
|
|
|
|
|
|
|
<big>Try finding and downloading the video again.</big>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VideoComment = ({comment, children}) => {
|
|
|
|
|
const {t} = React.useContext(ThemeContext);
|
|
|
|
|
|
2024-02-27 18:54:14 -07:00
|
|
|
const {is_favorited, like_count, author, timestamp, text, author_is_uploader} = comment;
|
|
|
|
|
|
|
|
|
|
// Author comments and favorited comments are important.
|
|
|
|
|
let specialIcon = null;
|
|
|
|
|
if (author_is_uploader) {
|
|
|
|
|
specialIcon = <Icon name='star' color='green'/>;
|
|
|
|
|
} else if (is_favorited) {
|
|
|
|
|
specialIcon = <Icon name='heart' color='red'/>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dateElm = <div {...t}>{isoDatetimeToString(timestamp * 1000)}</div>;
|
|
|
|
|
const likesElm = like_count && <div {...t}>
|
2024-08-22 21:18:42 -06:00
|
|
|
<Icon name='thumbs up'/>{humanNumber(comment['like_count'])}
|
2024-02-27 18:54:14 -07:00
|
|
|
</div>;
|
2024-02-20 13:47:12 -07:00
|
|
|
|
|
|
|
|
return <Comment>
|
|
|
|
|
<Comment.Content>
|
2024-02-27 18:54:14 -07:00
|
|
|
<Comment.Author as='a'>
|
|
|
|
|
<span {...t}>{specialIcon}{author}</span>
|
|
|
|
|
</Comment.Author>
|
2024-02-20 13:47:12 -07:00
|
|
|
<Comment.Metadata>
|
2024-02-27 18:54:14 -07:00
|
|
|
{dateElm}
|
|
|
|
|
{likesElm}
|
2024-02-20 13:47:12 -07:00
|
|
|
</Comment.Metadata>
|
2024-02-27 18:54:14 -07:00
|
|
|
<Comment.Text {...t}>
|
|
|
|
|
<MultilineText text={text} style={{marginLeft: '0.5em'}}/>
|
|
|
|
|
</Comment.Text>
|
2024-02-20 13:47:12 -07:00
|
|
|
</Comment.Content>
|
|
|
|
|
{children && !_.isEmpty(children) &&
|
|
|
|
|
<CommentGroup>
|
|
|
|
|
{children.map((i, key) => <VideoComment key={key} comment={i}/>)}
|
|
|
|
|
</CommentGroup>
|
|
|
|
|
}
|
|
|
|
|
</Comment>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Comments = ({comments, video}) => {
|
|
|
|
|
if (!comments || _.isEmpty(comments)) {
|
|
|
|
|
return <NoComments video={video}/>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comments.sort((a, b) => {
|
|
|
|
|
// Treat undefined like_count as 0
|
|
|
|
|
const likeA = a.like_count ?? 0;
|
|
|
|
|
const likeB = b.like_count ?? 0;
|
|
|
|
|
|
|
|
|
|
// For descending order
|
|
|
|
|
return likeB - likeA;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const rootComments = comments.filter(i => i['parent'] === 'root');
|
|
|
|
|
|
|
|
|
|
const sortedByParent = {};
|
|
|
|
|
comments.forEach(obj => {
|
|
|
|
|
if (!sortedByParent[obj.parent]) {
|
|
|
|
|
sortedByParent[obj.parent] = [];
|
|
|
|
|
}
|
|
|
|
|
sortedByParent[obj.parent].push(obj);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return <CommentGroup>
|
|
|
|
|
{rootComments.map((i, key) => <VideoComment key={key} comment={i} children={sortedByParent[i.id]}/>)}
|
|
|
|
|
</CommentGroup>
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-24 08:58:18 -06:00
|
|
|
function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
2022-08-06 05:22:07 +00:00
|
|
|
const {theme} = useContext(ThemeContext);
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
2022-11-15 15:03:12 -07:00
|
|
|
const videoRef = React.useRef();
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2023-10-24 10:20:06 -06:00
|
|
|
useTitle(videoFile ? videoFile.title ? videoFile.title : videoFile.name : null);
|
2022-08-06 05:22:07 +00:00
|
|
|
let video;
|
|
|
|
|
if (videoFile) {
|
|
|
|
|
video = videoFile.video;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-15 15:03:12 -07:00
|
|
|
// Seeks to the `seconds` on video player.
|
|
|
|
|
const setVideoTime = (seconds) => {
|
|
|
|
|
videoRef.current.currentTime = seconds;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
// 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 <VideoPlaceholder/>;
|
|
|
|
|
}
|
|
|
|
|
if (videoFile === undefined) {
|
2022-09-28 09:38:05 -06:00
|
|
|
return <PageContainer><Header as='h4'>Could not find video</Header></PageContainer>;
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDeleteVideo = async (video_id) => {
|
2023-07-21 15:14:09 -06:00
|
|
|
await deleteVideos([video_id])
|
2022-08-06 05:22:07 +00:00
|
|
|
navigate(-1);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const handleRefresh = async () => {
|
|
|
|
|
const destination = getParentDirectory(videoFile.primary_path);
|
|
|
|
|
await downloadVideoMetadata(videoFile.url, destination);
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-29 13:46:39 -06:00
|
|
|
let videoUrl = `${MEDIA_PATH}/${encodeMediaPath(video.video_path)}`;
|
|
|
|
|
let downloadUrl = `/download/${encodeMediaPath(video.video_path)}`;
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2023-03-29 13:46:39 -06:00
|
|
|
let posterUrl = video.poster_path ? `${MEDIA_PATH}/${encodeMediaPath(video.poster_path)}` : null;
|
2023-04-02 16:30:01 -06:00
|
|
|
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'])}`)
|
|
|
|
|
: [];
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
let description = 'No description available.';
|
2023-03-24 08:58:18 -06:00
|
|
|
if (video && video['description']) {
|
2022-11-30 18:26:38 -07:00
|
|
|
// Only replace empty description if there is one available.
|
2023-03-24 08:58:18 -06:00
|
|
|
description = video['description'];
|
2023-09-07 13:00:54 -06:00
|
|
|
description = formatVideoDescription(description, setVideoTime)
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const descriptionPane = {
|
2022-08-06 05:22:07 +00:00
|
|
|
menuItem: 'Description', render: () => <TabPane>
|
2021-11-01 16:42:52 -06:00
|
|
|
<pre className="wrap-text">
|
2022-11-30 18:26:38 -07:00
|
|
|
{description}
|
2021-11-01 16:42:52 -06:00
|
|
|
</pre>
|
2022-08-06 05:22:07 +00:00
|
|
|
</TabPane>
|
2021-11-01 16:42:52 -06:00
|
|
|
};
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const captionsPane = {
|
2022-08-06 05:22:07 +00:00
|
|
|
menuItem: 'Captions', render: () => <TabPane>
|
2023-01-04 11:16:40 -07:00
|
|
|
<pre>{video.caption || 'No captions available.'}</pre>
|
2022-08-06 05:22:07 +00:00
|
|
|
</TabPane>
|
2022-01-25 10:16:29 -07:00
|
|
|
};
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const {poster_file, info_json_file, comments} = video;
|
2023-08-26 20:28:34 -06:00
|
|
|
const filesPane = {
|
2022-11-30 18:26:38 -07:00
|
|
|
menuItem: 'Files', render: () => <TabPane>
|
|
|
|
|
<h3>Video File</h3>
|
2022-12-19 10:40:01 -07:00
|
|
|
{videoFileLink(video['video_path'])}
|
2022-11-30 18:26:38 -07:00
|
|
|
|
|
|
|
|
<h4>Info JSON File</h4>
|
2023-03-24 08:58:18 -06:00
|
|
|
{info_json_file &&
|
2023-08-26 20:28:34 -06:00
|
|
|
<PreviewPath path={info_json_file['path']} mimetype={info_json_file['mimetype']} taggable={false}>
|
|
|
|
|
{info_json_file['path']}
|
|
|
|
|
</PreviewPath>
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
2022-11-30 18:26:38 -07:00
|
|
|
|
2023-03-24 08:58:18 -06:00
|
|
|
<h4>Caption Files</h4>
|
|
|
|
|
{caption_files &&
|
2023-08-26 20:28:34 -06:00
|
|
|
caption_files.map(i => <p key={i['path']}><PreviewPath {...i} taggable={false}>
|
|
|
|
|
{i['path']}
|
|
|
|
|
</PreviewPath></p>)
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
2022-11-30 18:26:38 -07:00
|
|
|
|
|
|
|
|
<h4>Poster File</h4>
|
2023-03-24 08:58:18 -06:00
|
|
|
{poster_file &&
|
2023-08-26 20:28:34 -06:00
|
|
|
<PreviewPath path={poster_file['path']} mimetype={poster_file['mimetype']} taggable={false}>
|
|
|
|
|
{poster_file['path']}
|
|
|
|
|
</PreviewPath>
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
2022-11-30 18:26:38 -07:00
|
|
|
|
|
|
|
|
<h4>Directory</h4>
|
2022-12-19 10:40:01 -07:00
|
|
|
{videoFileLink(videoFile['directory'], true)}
|
2022-11-30 18:26:38 -07:00
|
|
|
</TabPane>
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const commentsPane = {
|
|
|
|
|
menuItem: 'Comments', render: () => <TabPane>
|
|
|
|
|
<Header as='h3'>Top Comments</Header>
|
|
|
|
|
<Comments comments={comments} video={videoFile}/>
|
|
|
|
|
</TabPane>,
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-20 15:13:18 -07:00
|
|
|
const tabPanes = [commentsPane, descriptionPane, filesPane, captionsPane];
|
2022-08-06 05:22:07 +00:00
|
|
|
const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true};
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2024-02-20 15:13:18 -07:00
|
|
|
const aboutSegment = <Segment>
|
|
|
|
|
<Header as='h2'>About Video</Header>
|
|
|
|
|
|
2024-06-17 14:48:43 -06:00
|
|
|
<Grid columns={2}>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<h3>Size</h3>
|
|
|
|
|
<p>{videoFile.size ? humanFileSize(videoFile.size) : 'Unknown'}</p>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<h3>View Count</h3>
|
|
|
|
|
<p>{video.view_count ? humanNumber(video.view_count) : 'N/A'}</p>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<h3>Codec Names</h3>
|
|
|
|
|
<>{video.codec_names ? video.codec_names.map(i => <Label key={i}>{i}</Label>) : 'N/A'}</>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<h3>Censored</h3>
|
|
|
|
|
<p>{video.censored ? 'Yes' : 'No'}</p>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
<Grid.Row columns={1}>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<h3>Source URL</h3>
|
|
|
|
|
<p>{videoFile.url ? <a href={videoFile.url}>{videoFile.url}</a> : 'N/A'}</p>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
2024-02-20 15:13:18 -07:00
|
|
|
</Segment>;
|
|
|
|
|
|
2023-04-02 16:30:01 -06:00
|
|
|
const localAddTag = async (name) => {
|
2023-05-29 18:04:03 -06:00
|
|
|
await tagFileGroup(videoFile, name);
|
2023-04-02 16:30:01 -06:00
|
|
|
await fetchVideo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const localRemoveTag = async (name) => {
|
2023-05-29 18:04:03 -06:00
|
|
|
await untagFileGroup(videoFile, name);
|
2023-04-02 16:30:01 -06:00
|
|
|
await fetchVideo();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 15:53:47 -06:00
|
|
|
let videoSource = <source src={videoUrl}/>;
|
|
|
|
|
|
2023-08-17 19:31:21 -06:00
|
|
|
let prevNextVideosSegment = <Segment><p>No related videos found.</p></Segment>;
|
|
|
|
|
if (prevFile || nextFile) {
|
|
|
|
|
prevNextVideosSegment = <Segment>
|
|
|
|
|
<Grid columns={2} stackable>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column textAlign='left'>
|
|
|
|
|
{prevFile && <><Header as='h3'>Older</Header><VideoCard file={prevFile}/></>}
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column textAlign='left'>
|
|
|
|
|
{nextFile && <><Header as='h3'>Newer</Header><VideoCard file={nextFile}/></>}
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Segment>
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-07 13:00:54 -06:00
|
|
|
let title = video.video_path;
|
|
|
|
|
if (videoFile.title) {
|
|
|
|
|
title = hashtagLinks(videoFile.title);
|
|
|
|
|
} else if (videoFile.stem) {
|
|
|
|
|
title = videoFile.stem;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-17 16:09:24 -07:00
|
|
|
return <>
|
2022-11-30 19:31:18 -07:00
|
|
|
<Container style={{margin: '1em'}}>
|
|
|
|
|
<BackButton/>
|
2022-08-06 05:22:07 +00:00
|
|
|
</Container>
|
|
|
|
|
|
|
|
|
|
<video controls
|
2024-08-02 11:56:06 -06:00
|
|
|
class='video-player'
|
2022-08-06 05:22:07 +00:00
|
|
|
autoPlay={props.autoplay !== undefined ? props.autoplay : true}
|
|
|
|
|
poster={posterUrl}
|
|
|
|
|
id="player"
|
|
|
|
|
playsInline={true}
|
|
|
|
|
style={{maxWidth: '100%'}}
|
2022-11-15 15:03:12 -07:00
|
|
|
ref={videoRef}
|
2022-08-06 05:22:07 +00:00
|
|
|
>
|
2023-07-27 15:53:47 -06:00
|
|
|
{videoSource}
|
2022-11-30 18:26:38 -07:00
|
|
|
{/* Only WebVTT captions can be displayed. */}
|
2023-08-03 22:36:27 -06:00
|
|
|
{captionUrls.map(i => <CaptionTrack key={i} src={i}/>)}
|
2022-08-06 05:22:07 +00:00
|
|
|
</video>
|
|
|
|
|
|
|
|
|
|
<Container style={{marginTop: '1em'}}>
|
|
|
|
|
<Segment>
|
|
|
|
|
|
2023-09-07 13:00:54 -06:00
|
|
|
<Header as='h2'>{title}</Header>
|
2024-10-02 21:59:33 -06:00
|
|
|
{videoFile.published_datetime && <h3>{isoDatetimeToElapsedPopup(videoFile.published_datetime)}</h3>}
|
2022-08-06 05:22:07 +00:00
|
|
|
<h3>
|
|
|
|
|
{channel && <Link to={`/videos/channel/${channel.id}/video`}>
|
|
|
|
|
{channel.name}
|
|
|
|
|
</Link>}
|
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
|
|
<p>
|
2023-07-21 15:14:09 -06:00
|
|
|
<Button as='a' href={downloadUrl}>
|
|
|
|
|
<Icon name='download'/>
|
|
|
|
|
Download
|
|
|
|
|
</Button>
|
|
|
|
|
<APIButton
|
2022-08-06 05:22:07 +00:00
|
|
|
color='red'
|
2023-07-21 15:14:09 -06:00
|
|
|
confirmContent='Are you sure you want to delete this video? All files related to this video will be deleted. It will not be downloaded again!'
|
2022-08-06 05:22:07 +00:00
|
|
|
confirmButton='Delete'
|
2023-07-21 15:14:09 -06:00
|
|
|
onClick={async () => await handleDeleteVideo(video.id)}
|
|
|
|
|
obeyWROLMode={true}
|
|
|
|
|
>Delete</APIButton>
|
2024-02-20 13:47:12 -07:00
|
|
|
<APIButton
|
|
|
|
|
color='blue'
|
|
|
|
|
onClick={handleRefresh}
|
2024-02-20 15:15:23 -07:00
|
|
|
obeyWROLMode={true}
|
|
|
|
|
disabled={!videoFile.url}
|
2024-02-20 13:47:12 -07:00
|
|
|
>Refresh</APIButton>
|
2022-08-06 05:22:07 +00:00
|
|
|
</p>
|
2023-03-24 08:58:18 -06:00
|
|
|
</Segment>
|
|
|
|
|
|
|
|
|
|
<Segment>
|
2023-04-05 14:48:13 -06:00
|
|
|
<TagsSelector selectedTagNames={videoFile['tags']} onAdd={localAddTag} onRemove={localRemoveTag}/>
|
2022-08-06 05:22:07 +00:00
|
|
|
</Segment>
|
|
|
|
|
|
2024-02-20 15:13:18 -07:00
|
|
|
{aboutSegment}
|
|
|
|
|
|
2024-06-17 14:48:43 -06:00
|
|
|
<Tab menu={tabMenu} panes={tabPanes}/>
|
|
|
|
|
|
2023-08-17 19:31:21 -06:00
|
|
|
{prevNextVideosSegment}
|
2022-08-06 05:22:07 +00:00
|
|
|
</Container>
|
2023-02-17 16:09:24 -07:00
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default VideoPage;
|
2022-11-15 15:03:12 -07:00
|
|
|
|
2023-10-31 10:20:45 -06:00
|
|
|
const chapterRegex = new RegExp('^(\\(?(?:((\\d?\\d):)?(?:(\\d?\\d):(\\d\\d)))\\)?)\.?\\s+(.*)$', 'i');
|
2022-11-15 15:03:12 -07:00
|
|
|
|
2023-09-07 13:00:54 -06:00
|
|
|
function formatVideoDescription(description, setVideoTime) {
|
|
|
|
|
// Convert timestamps to links which change the video's playback location. Change hashtags to search links.
|
2022-11-15 15:03:12 -07:00
|
|
|
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) {
|
2022-11-16 12:50:38 -07:00
|
|
|
// This line in the description starts with a chapter timestamp, parse it and create a link.
|
2022-11-15 15:03:12 -07:00
|
|
|
try {
|
|
|
|
|
const timestamp = match[1];
|
|
|
|
|
const title = match[6];
|
2022-11-16 12:50:38 -07:00
|
|
|
// Assume 0 if no part of timestamp could be found.
|
2022-11-15 15:03:12 -07:00
|
|
|
const [hour, minute, second] = match.slice(3, 6).map(i => parseInt(i) || 0);
|
2022-11-16 12:50:38 -07:00
|
|
|
// Convert timestamp to seconds.
|
2022-11-15 15:03:12 -07:00
|
|
|
const seconds = (((hour * 60) + minute) * 60) + second;
|
|
|
|
|
link = <>
|
|
|
|
|
<a href='#' onClick={() => setVideoTime(seconds)}>{timestamp}</a>
|
|
|
|
|
{title}
|
|
|
|
|
</>;
|
|
|
|
|
} catch (e) {
|
2022-11-16 12:50:38 -07:00
|
|
|
// Report an error while creating timestamp link.
|
2022-11-15 15:03:12 -07:00
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 12:50:38 -07:00
|
|
|
// Use the link if we could create it, otherwise fallback to the original `line`.
|
2023-09-07 13:00:54 -06:00
|
|
|
newLines = [...newLines, link || hashtagLinks(line)];
|
2022-11-15 15:03:12 -07:00
|
|
|
} else if (line !== undefined) {
|
2022-11-16 12:50:38 -07:00
|
|
|
// Line does not start with a timestamp.
|
2023-09-07 13:00:54 -06:00
|
|
|
newLines = [...newLines, hashtagLinks(line)];
|
2022-11-15 15:03:12 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-11-16 12:50:38 -07:00
|
|
|
// Map all lines and links with a break between.
|
2022-11-15 15:03:12 -07:00
|
|
|
return <>
|
|
|
|
|
{newLines.map((i, idx) => <div key={idx}>{i}<br/></div>)}
|
|
|
|
|
</>;
|
|
|
|
|
} catch (e) {
|
2022-11-16 12:50:38 -07:00
|
|
|
// Some error happened while parsing description. Report it but don't fail.
|
2022-11-15 15:03:12 -07:00
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-16 12:50:38 -07:00
|
|
|
// Error occurred, or no description, don't fail.
|
2022-11-15 15:03:12 -07:00
|
|
|
return description;
|
2023-09-07 13:00:54 -06:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const hashtagRegex = /(#+[_a-zA-Z0-9]+)/ig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hashtagLinks(text) {
|
|
|
|
|
// Converts a string into a div which has hashtags converted to search links.
|
|
|
|
|
// Example: Some text <a href="/search?q=#hashtag">#hashtag</a> the rest of the text
|
|
|
|
|
if (text && text.length > 0) {
|
|
|
|
|
const parts = text.split(hashtagRegex);
|
|
|
|
|
let newParts = '';
|
|
|
|
|
for (let i = 0; i < parts.length; i++) {
|
|
|
|
|
let part = parts[i];
|
|
|
|
|
part = part.startsWith('#') ?
|
|
|
|
|
// Part is a hashtag.
|
|
|
|
|
<a key={i} href={`/search?q=${encodeURIComponent(part)}`} target="_self">{part}</a>
|
|
|
|
|
// Part is not a hashtag.
|
|
|
|
|
: <span key={i}>{part}</span>;
|
|
|
|
|
newParts = [...newParts, part];
|
|
|
|
|
}
|
|
|
|
|
return <React.Fragment>{newParts}</React.Fragment>;
|
|
|
|
|
}
|
|
|
|
|
return text;
|
2022-11-15 15:03:12 -07:00
|
|
|
}
|