Detecting more video caption files, indexing them. Only WebVTT captions are displayed on VideoPage. Creating Files tab on VideoPage which displays all files found for the video.

This commit is contained in:
Roland 2022-11-30 18:26:38 -07:00
parent 9c3809d751
commit 20860fdae8
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
7 changed files with 81 additions and 39 deletions

View file

@ -413,9 +413,9 @@ function ChannelPage({create, header}) {
<Button color='blue' onClick={handleRefreshChannel}>
Refresh
</Button>
<Button onClick={() => navigate(`/videos/channel/${channel.id}/video`)}>
Videos
</Button>
<Link to={`/videos/channel/${channel.id}/video`}>
<Button>Videos</Button>
</Link>
</>
}
</Container>

View file

@ -37,9 +37,11 @@ export function ThemeWrapper({children, ...props}) {
}
// Properties to manipulate elements with theme.
// Example <p {...s}>This paragraph changes style</p>
// Invert when Semantic supports it. Example: <Menu {...i}>
const [i, setI] = useState({});
// Invert style when Semantic does not support it. Example: <p {...s}>This paragraph changes style</p>
const [s, setS] = useState({});
// Invert text when Semantic does not support it.
const [t, setT] = useState({});
const [inverted, setInverted] = useState('');
@ -55,7 +57,7 @@ export function ThemeWrapper({children, ...props}) {
setT({style: {color: '#dddddd'}});
setInverted('inverted');
setTheme(darkTheme);
document.body.style.background = '#1B1C1D';
document.body.style.background = '#171616';
if (save) {
saveTheme(darkTheme);
}
@ -130,8 +132,8 @@ export function ThemeWrapper({children, ...props}) {
const themeValue = {
i, // Used for Semantic elements which support "inverted".
t, // Used to invert text.
s, // Used to invert the style some elements.
t, // Used to invert text.
inverted, // Used to add "invert" to className.
theme,
savedTheme,
@ -256,6 +258,7 @@ export function Statistic(props) {
export function StatisticGroup(props) {
const {i} = useContext(ThemeContext);
props = {...i, ...props};
props['style'] = {...props['style'], marginLeft: 0, marginRight: 0};
return <STATISTIC_GROUP {...props}/>
}

View file

@ -2,7 +2,7 @@ import React, {useContext, useState} from 'react';
import {deleteVideos} from "../api";
import {Link, useNavigate, useParams} from "react-router-dom";
import _ from "lodash";
import {API_URI, humanFileSize, humanNumber, PageContainer, secondsToTimestamp, uploadDate, useTitle} from "./Common";
import {humanFileSize, humanNumber, PageContainer, uploadDate, useTitle} from "./Common";
import {Confirm} from "semantic-ui-react";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import Container from "semantic-ui-react/dist/commonjs/elements/Container";
@ -15,6 +15,20 @@ import {VideoCard} from "./Videos";
const MEDIA_PATH = '/media';
function videoFileLink(video, name, directory = false) {
const path = video[name];
if (path) {
const href = directory ?
`${MEDIA_PATH}/${encodeURIComponent(path)}/` :
`${MEDIA_PATH}/${encodeURIComponent(path)}`;
return <a href={href}>
<pre>{path}</pre>
</a>
} else {
return 'Unknown'
}
}
function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
const {theme} = useContext(ThemeContext);
@ -59,11 +73,14 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
let posterUrl = video.poster_path ? `${MEDIA_PATH}/${encodeURIComponent(video.poster_path)}` : null;
let captionsUrl = video.caption_path ? `${MEDIA_PATH}/${encodeURIComponent(video.caption_path)}` : null;
let vttCaptions = video.caption_path.endsWith('.vtt');
let description = 'No description available.';
let viewCount = video.view_count;
if (video.info_json) {
if (video.info_json && video.info_json['description']) {
// Only replace empty description if there is one available.
description = video.info_json['description'];
description = chaptersInDescription(description, setVideoTime)
viewCount = viewCount || video.info_json['view_count'];
}
@ -86,7 +103,7 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
let descriptionPane = {
menuItem: 'Description', render: () => <TabPane>
<pre className="wrap-text">
{description ? chaptersInDescription(description, setVideoTime) : 'No description'}
{description}
</pre>
</TabPane>
};
@ -104,12 +121,6 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
<h3>Censored</h3>
<p>{video.censored ? 'Yes' : 'No'}</p>
<h3>File Name</h3>
<pre style={{backgroundColor: '#ccc', padding: '0.4em'}}>{video.video_path}</pre>
<h3>File Modification Time</h3>
<p>{video.modification_datetime ? secondsToTimestamp(video.modification_datetime) : null}</p>
</TabPane>
}
@ -119,7 +130,26 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
</TabPane>
};
let tabPanes = [descriptionPane, aboutPane, captionsPane];
let filesPane = {
menuItem: 'Files', render: () => <TabPane>
<h3>Video File</h3>
{videoFileLink(video, 'video_path')}
<h4>Info JSON File</h4>
{videoFileLink(video, 'info_json_path')}
<h4>Caption File</h4>
{videoFileLink(video, 'caption_path')}
<h4>Poster File</h4>
{videoFileLink(video, 'poster_path')}
<h4>Directory</h4>
{videoFileLink(video, 'directory', true)}
</TabPane>
}
let tabPanes = [descriptionPane, aboutPane, filesPane, captionsPane];
const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true};
return (<>
@ -142,7 +172,9 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
ref={videoRef}
>
<source src={videoUrl} type="video/mp4"/>
<track kind="captions" label="English captions" src={captionsUrl} srcLang="en" default/>
{/* Only WebVTT captions can be displayed. */}
{vttCaptions &&
<track kind="captions" label="English" src={captionsUrl} srcLang="en" default/>}
</video>
<Container style={{marginTop: '1em'}}>
@ -181,16 +213,18 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
<Tab menu={tabMenu} panes={tabPanes}/>
<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>
<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>
</Container>
</>)
}

View file

@ -1,4 +1,4 @@
import {Header, Progress, Statistic, StatisticGroup} from "../Theme";
import {Header, Progress, Segment, Statistic, StatisticGroup} from "../Theme";
import React, {useContext} from "react";
import {humanBandwidth, humanFileSize, LoadStatistic, useTitle} from "../Common";
import {Divider, Responsive} from "semantic-ui-react";
@ -196,8 +196,6 @@ export function Status() {
<LoadStatistic label='15 Minute Load' value={minute_15} cores={cores}/>
</StatisticGroup>
<Divider/>
<Header as='h1'>Network Bandwidth</Header>
{bandwidth ?
bandwidth.map(i => <BandwidthProgressGroup key={i['name']} bandwidth={i}/>) :

View file

@ -118,11 +118,16 @@ class VideoIndexer(Indexer, ABC):
a = cls.get_title(file)
c = cls.get_description(file)
# Detect the associated caption file.
caption_path = file.path.with_suffix('.en.vtt')
# Detect the associated caption files.
d = None
if caption_path.is_file():
d = read_captions(caption_path)
if (en_vtt := file.path.with_suffix('.en.vtt')).is_file():
d = read_captions(en_vtt)
elif (vtt := file.path.with_suffix('.vtt')).is_file():
d = read_captions(vtt)
elif (en_srt := file.path.with_suffix('.en.srt')).is_file():
d = read_captions(en_srt)
elif (srt := file.path.with_suffix('.srt')).is_file():
d = read_captions(srt)
elif EXTRACT_SUBTITLES:
d = extract_captions(file.path) or ''

View file

@ -245,11 +245,13 @@ class Video(ModelHelper, Base):
censored=self.censored,
channel=self.channel,
channel_id=self.channel_id,
directory=self.video_path.parent if self.video_path else None,
modification_datetime=self.modification_datetime,
duration=self.duration,
favorite=self.favorite,
id=self.id,
info_json=info_json,
info_json_path=self.info_json_path,
poster_path=self.poster_path,
size=self.size,
source_id=self.source_id,

View file

@ -98,11 +98,11 @@ class File(ModelHelper, Base):
# Get the indexer on a separate line for debugging.
indexer = self.indexer
# Only read the contents of the file once.
self.a_text, self.b_text, self.c_text, self.d_text = indexer.create_index(self)
self.a_text = truncate_object_bytes(self.a_text, MAX_TEXT_FILE_BYTES)
self.b_text = truncate_object_bytes(self.b_text, MAX_TEXT_FILE_BYTES)
self.c_text = truncate_object_bytes(self.c_text, MAX_TEXT_FILE_BYTES)
self.d_text = truncate_object_bytes(self.d_text, MAX_TEXT_FILE_BYTES)
a_text, b_text, c_text, d_text = indexer.create_index(self)
self.a_text = truncate_object_bytes(a_text, MAX_TEXT_FILE_BYTES)
self.b_text = truncate_object_bytes(b_text, MAX_TEXT_FILE_BYTES)
self.c_text = truncate_object_bytes(c_text, MAX_TEXT_FILE_BYTES)
self.d_text = truncate_object_bytes(d_text, MAX_TEXT_FILE_BYTES)
self.indexed = True
except Exception as e: