2026-04-14 15:00:49 -06:00
|
|
|
import React, {useContext, useEffect, useState} from 'react';
|
2026-02-23 17:29:09 -07:00
|
|
|
import {useHotkeys} from 'react-hotkeys-hook';
|
2026-05-03 18:50:22 -06:00
|
|
|
import {deleteFileGroups, downloadVideoMetadata, tagFileGroup, untagFileGroup} from "../api";
|
2025-12-07 11:54:20 -07:00
|
|
|
import {Link, useNavigate, useParams} from "react-router";
|
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,
|
2026-03-28 14:19:09 -06:00
|
|
|
DirectoryLink,
|
2023-03-29 13:46:39 -06:00
|
|
|
encodeMediaPath,
|
2023-02-17 16:30:25 -07:00
|
|
|
humanFileSize,
|
2024-11-02 15:14:02 -06:00
|
|
|
humanNumber,
|
|
|
|
|
isoDatetimeToAgoPopup,
|
2024-02-27 18:54:14 -07:00
|
|
|
MultilineText,
|
2023-02-17 16:30:25 -07:00
|
|
|
PageContainer,
|
|
|
|
|
PreviewPath,
|
2026-03-08 09:22:50 -06:00
|
|
|
useMediaSession,
|
2023-02-17 16:30:25 -07:00
|
|
|
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";
|
2026-03-21 16:50:27 -06:00
|
|
|
import {useChannel, useVideoCaptions, useVideoExtras} from "../hooks/customHooks";
|
2022-10-25 15:25:44 -06:00
|
|
|
import {ThemeContext} from "../contexts/contexts";
|
2026-03-21 16:50:27 -06:00
|
|
|
import {Button, darkTheme, Header, Icon, Loader, Segment, Tab} 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";
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
import {AddToPlaylistButton} from "./AddToPlaylist";
|
2026-04-14 15:00:49 -06:00
|
|
|
import {Comment, CommentGroup, Input, Label, Transition} from "semantic-ui-react";
|
2026-05-03 17:28:06 -06:00
|
|
|
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
const MEDIA_PATH = '/media';
|
|
|
|
|
|
|
|
|
|
|
2022-11-30 18:26:38 -07:00
|
|
|
|
2026-07-16 17:43:40 -06:00
|
|
|
// YouTube auto-generated captions (downloaded via yt-dlp) stamp every cue with `align:start position:0%`,
|
|
|
|
|
// which pins the text to the bottom-left of the player and makes it hard to read. Detect that signature and
|
|
|
|
|
// reset those cues to the browser's centered default. This mutates only the in-memory VTTCue objects the
|
|
|
|
|
// browser parsed; the .vtt file on disk is never modified. Cues that were deliberately positioned (anything
|
2026-07-16 17:51:37 -06:00
|
|
|
// other than the auto-caption signature) are left untouched. YouTube auto-captions never set `line`, so we
|
|
|
|
|
// require `line === 'auto'` too; that leaves a deliberately placed cue (e.g. `line:0` for top-edge) alone even
|
|
|
|
|
// if it happens to also be `align:start position:0%`.
|
2026-07-16 17:43:40 -06:00
|
|
|
export function centerAutoCaptions(track) {
|
|
|
|
|
if (!track || !track.cues) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
let changed = 0;
|
|
|
|
|
for (const cue of track.cues) {
|
2026-07-16 17:51:37 -06:00
|
|
|
if (cue.align === 'start' && cue.position === 0 && cue.line === 'auto') {
|
2026-07-16 17:43:40 -06:00
|
|
|
cue.align = 'center';
|
|
|
|
|
cue.position = 'auto';
|
|
|
|
|
changed++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleCaptionTrackLoad(event) {
|
|
|
|
|
const track = event.target.track;
|
|
|
|
|
if (!track) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (track.cues && track.cues.length > 0) {
|
|
|
|
|
centerAutoCaptions(track);
|
|
|
|
|
} else {
|
|
|
|
|
// A non-default track has mode 'disabled' at load time, so its cues are not parsed yet. Normalize
|
2026-07-16 17:51:37 -06:00
|
|
|
// them once the browser populates the cue list (when the user selects the track and playback advances
|
|
|
|
|
// into a cue). Only detach after cues actually exist, in case a cuechange fires before they load.
|
2026-07-16 17:43:40 -06:00
|
|
|
const onCueChange = () => {
|
2026-07-16 17:51:37 -06:00
|
|
|
if (track.cues && track.cues.length > 0) {
|
|
|
|
|
centerAutoCaptions(track);
|
|
|
|
|
track.removeEventListener('cuechange', onCueChange);
|
|
|
|
|
}
|
2026-07-16 17:43:40 -06:00
|
|
|
};
|
|
|
|
|
track.addEventListener('cuechange', onCueChange);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 22:36:27 -06:00
|
|
|
export function CaptionTrack({src, ...props}) {
|
2026-07-16 17:43:40 -06:00
|
|
|
// Center YouTube auto-generated captions once the browser parses the cues (see centerAutoCaptions).
|
|
|
|
|
props = {onLoad: handleCaptionTrackLoad, ...props};
|
2023-08-03 22:36:27 -06:00
|
|
|
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 () => {
|
2026-03-19 15:02:32 -06:00
|
|
|
await downloadVideoMetadata(videoUrl);
|
2024-02-20 13:47:12 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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'/>;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
const dateElm = <div {...t}>{isoDatetimeToAgoPopup(timestamp * 1000)}</div>;
|
2024-02-27 18:54:14 -07:00
|
|
|
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');
|
|
|
|
|
|
2024-10-15 17:02:59 -06:00
|
|
|
// Comments are in an array, convert it to a dict, grouped by their parent.
|
|
|
|
|
const groupedByParent = {};
|
2024-02-20 13:47:12 -07:00
|
|
|
comments.forEach(obj => {
|
2024-10-15 17:02:59 -06:00
|
|
|
if (!groupedByParent[obj.parent]) {
|
|
|
|
|
groupedByParent[obj.parent] = [];
|
2024-02-20 13:47:12 -07:00
|
|
|
}
|
2024-10-15 17:02:59 -06:00
|
|
|
groupedByParent[obj.parent].push(obj);
|
|
|
|
|
})
|
|
|
|
|
// Sort replies to each parent by the time they were created.
|
|
|
|
|
comments.forEach(obj => {
|
|
|
|
|
const children = groupedByParent[obj.parent];
|
|
|
|
|
groupedByParent[obj.parent] = _.sortBy(children, ['timestamp']);
|
2024-02-20 13:47:12 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return <CommentGroup>
|
2024-10-15 17:02:59 -06:00
|
|
|
{rootComments.map((i, key) => <VideoComment key={key} comment={i} children={groupedByParent[i.id]}/>)}
|
2024-02-20 13:47:12 -07:00
|
|
|
</CommentGroup>
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 17:29:09 -07:00
|
|
|
// Generate a video page URL for a file object.
|
|
|
|
|
function getVideoLink(file) {
|
|
|
|
|
if (!file || !file.video) return null;
|
2026-03-20 15:38:32 -06:00
|
|
|
return `/videos/${file.id}`;
|
2026-02-23 17:29:09 -07:00
|
|
|
}
|
|
|
|
|
|
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();
|
2026-05-03 17:28:06 -06:00
|
|
|
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
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);
|
2026-03-21 16:50:27 -06:00
|
|
|
const {comments} = useVideoExtras(videoFile?.id);
|
|
|
|
|
const {captions, captionsLoading, fetchCaptions} = useVideoCaptions(videoFile?.id);
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2026-03-08 09:22:50 -06:00
|
|
|
const mediaTitle = videoFile ? (videoFile.title || videoFile.stem || videoFile.name) : null;
|
|
|
|
|
const mediaArtworkUrl = video && video.poster_path ? `${MEDIA_PATH}/${encodeMediaPath(video.poster_path)}` : null;
|
|
|
|
|
useMediaSession(mediaTitle, channel ? channel.name : null, mediaArtworkUrl);
|
|
|
|
|
|
2026-02-23 17:29:09 -07:00
|
|
|
// Keyboard shortcuts for video player controls
|
|
|
|
|
// k: Play/pause
|
|
|
|
|
useHotkeys('k', () => {
|
|
|
|
|
if (videoRef.current) {
|
|
|
|
|
if (videoRef.current.paused) {
|
|
|
|
|
videoRef.current.play();
|
|
|
|
|
} else {
|
|
|
|
|
videoRef.current.pause();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false});
|
|
|
|
|
|
|
|
|
|
// j: Jump back 15 seconds
|
|
|
|
|
useHotkeys('j', () => {
|
|
|
|
|
if (videoRef.current) {
|
|
|
|
|
videoRef.current.currentTime = Math.max(0, videoRef.current.currentTime - 15);
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false});
|
|
|
|
|
|
|
|
|
|
// l: Jump forward 30 seconds
|
|
|
|
|
useHotkeys('l', () => {
|
|
|
|
|
if (videoRef.current) {
|
|
|
|
|
videoRef.current.currentTime = Math.min(
|
|
|
|
|
videoRef.current.duration || Infinity,
|
|
|
|
|
videoRef.current.currentTime + 30
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false});
|
|
|
|
|
|
|
|
|
|
// n: Navigate to newer video
|
|
|
|
|
useHotkeys('n', () => {
|
|
|
|
|
const link = getVideoLink(nextFile);
|
|
|
|
|
if (link) {
|
|
|
|
|
navigate(link);
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false}, [nextFile, navigate]);
|
|
|
|
|
|
|
|
|
|
// p: Navigate to older video
|
|
|
|
|
useHotkeys('p', () => {
|
|
|
|
|
const link = getVideoLink(prevFile);
|
|
|
|
|
if (link) {
|
|
|
|
|
navigate(link);
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false}, [prevFile, navigate]);
|
|
|
|
|
|
2026-03-27 17:59:36 -06:00
|
|
|
// f: Toggle fullscreen
|
|
|
|
|
useHotkeys('f', () => {
|
|
|
|
|
if (videoRef.current) {
|
|
|
|
|
if (document.fullscreenElement) {
|
|
|
|
|
document.exitFullscreen();
|
|
|
|
|
} else {
|
|
|
|
|
videoRef.current.requestFullscreen();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false});
|
|
|
|
|
|
2026-04-14 15:00:49 -06:00
|
|
|
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]);
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2026-05-03 18:50:22 -06:00
|
|
|
const handleDeleteVideo = async (fileGroupId, force = false) => {
|
|
|
|
|
const result = await deleteFileGroups([fileGroupId], force);
|
2026-05-03 17:28:06 -06:00
|
|
|
if (result && result.tagged) {
|
|
|
|
|
setTaggedFileGroups(result.file_groups);
|
|
|
|
|
return;
|
|
|
|
|
}
|
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 () => {
|
2026-03-19 15:02:32 -06:00
|
|
|
await downloadVideoMetadata(videoFile.url);
|
2024-02-20 13:47:12 -07:00
|
|
|
};
|
|
|
|
|
|
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 = {
|
2025-12-07 11:32:07 -07:00
|
|
|
menuItem: 'Description', render: () => <Tab.Pane>
|
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>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Tab.Pane>
|
2021-11-01 16:42:52 -06:00
|
|
|
};
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const captionsPane = {
|
2026-03-21 16:50:27 -06:00
|
|
|
menuItem: 'Captions', render: () => <CaptionsPane
|
|
|
|
|
captions={captions}
|
|
|
|
|
captionsLoading={captionsLoading}
|
|
|
|
|
fetchCaptions={fetchCaptions}
|
|
|
|
|
setVideoTime={setVideoTime}
|
|
|
|
|
/>
|
2022-01-25 10:16:29 -07:00
|
|
|
};
|
|
|
|
|
|
2026-02-08 10:29:08 -07:00
|
|
|
const getFile = (suffix) => videoFile.files.find(i => i.path.toLowerCase().endsWith(suffix));
|
2026-03-28 14:19:09 -06:00
|
|
|
const fileSize = (file) => file && file.size
|
|
|
|
|
? <span style={{marginLeft: '1em', color: 'grey'}}>({humanFileSize(file.size)})</span>
|
|
|
|
|
: null;
|
2026-02-08 10:29:08 -07:00
|
|
|
|
2025-01-26 12:44:16 -07:00
|
|
|
const {poster_file, info_json_file} = video;
|
2026-03-28 14:19:09 -06:00
|
|
|
const videoPathFile = videoFile.files.find(i => i.path === video['video_path']);
|
2026-02-08 10:29:08 -07:00
|
|
|
const ffprobeJsonFile = getFile('.ffprobe.json');
|
2026-03-28 14:19:09 -06:00
|
|
|
const tableStyle = {width: '100%', borderCollapse: 'separate', borderSpacing: '0 0.7em'};
|
|
|
|
|
const labelStyle = {whiteSpace: 'nowrap', paddingRight: '1.5em', verticalAlign: 'top'};
|
2023-08-26 20:28:34 -06:00
|
|
|
const filesPane = {
|
2025-12-07 11:32:07 -07:00
|
|
|
menuItem: 'Files', render: () => <Tab.Pane>
|
2026-03-28 14:19:09 -06:00
|
|
|
<table style={tableStyle}>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
2026-04-14 15:00:49 -06:00
|
|
|
<td style={labelStyle}><strong>{isAudio ? 'Audio File' : 'Video File'}</strong></td>
|
2026-03-28 14:19:09 -06:00
|
|
|
<td>
|
|
|
|
|
{video['video_path']
|
2026-04-14 15:00:49 -06:00
|
|
|
? <><PreviewPath path={video['video_path']} mimetype={isAudio ? 'audio/*' : 'video/*'} taggable={false}>
|
2026-03-28 14:19:09 -06:00
|
|
|
{video['video_path']}
|
|
|
|
|
</PreviewPath>{fileSize(videoPathFile)}</>
|
|
|
|
|
: 'Unknown'}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
<td style={labelStyle}><strong>Caption Files</strong></td>
|
|
|
|
|
<td>
|
|
|
|
|
{caption_files
|
|
|
|
|
? caption_files.map(i => <div key={i['path']} style={{marginBottom: '0.3em'}}>
|
|
|
|
|
<PreviewPath {...i} taggable={false}>{i['path']}</PreviewPath>
|
|
|
|
|
{fileSize(i)}
|
|
|
|
|
</div>)
|
|
|
|
|
: 'No caption files'}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
<td style={labelStyle}><strong>Poster File</strong></td>
|
|
|
|
|
<td>
|
|
|
|
|
{poster_file
|
|
|
|
|
? <><PreviewPath path={poster_file['path']} mimetype={poster_file['mimetype']}
|
|
|
|
|
taggable={false}>
|
|
|
|
|
{poster_file['path']}
|
|
|
|
|
</PreviewPath>{fileSize(poster_file)}</>
|
|
|
|
|
: 'No poster file'}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
<td style={labelStyle}><strong>Info JSON File</strong></td>
|
|
|
|
|
<td>
|
|
|
|
|
{info_json_file
|
|
|
|
|
? <><PreviewPath path={info_json_file['path']} mimetype={info_json_file['mimetype']}
|
|
|
|
|
taggable={false}>
|
|
|
|
|
{info_json_file['path']}
|
|
|
|
|
</PreviewPath>{fileSize(info_json_file)}</>
|
|
|
|
|
: 'No yt-dlp info json file'}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
<td style={labelStyle}><strong>ffprobe JSON File</strong></td>
|
|
|
|
|
<td>
|
|
|
|
|
{ffprobeJsonFile
|
|
|
|
|
? <><PreviewPath path={ffprobeJsonFile['path']} mimetype={ffprobeJsonFile['mimetype']}
|
|
|
|
|
taggable={false}>
|
|
|
|
|
{ffprobeJsonFile['path']}
|
|
|
|
|
</PreviewPath>{fileSize(ffprobeJsonFile)}</>
|
|
|
|
|
: 'No ffprobe json file'}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
<td style={labelStyle}><strong>Directory</strong></td>
|
|
|
|
|
<td><DirectoryLink path={videoFile['directory']}/></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Tab.Pane>
|
2022-11-30 18:26:38 -07:00
|
|
|
}
|
|
|
|
|
|
2024-02-20 13:47:12 -07:00
|
|
|
const commentsPane = {
|
2025-12-07 11:32:07 -07:00
|
|
|
menuItem: 'Comments', render: () => <Tab.Pane>
|
2024-02-20 13:47:12 -07:00
|
|
|
<Header as='h3'>Top Comments</Header>
|
|
|
|
|
<Comments comments={comments} video={videoFile}/>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Tab.Pane>,
|
2024-02-20 13:47:12 -07:00
|
|
|
};
|
|
|
|
|
|
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>
|
2024-11-02 15:14:02 -06:00
|
|
|
<p>{videoFile.censored ? 'Yes' : 'No'}</p>
|
2024-06-17 14:48:43 -06:00
|
|
|
</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}/>;
|
2026-04-14 15:00:49 -06:00
|
|
|
const isAudio = videoFile.mimetype && videoFile.mimetype.startsWith('audio/');
|
2023-07-27 15:53:47 -06:00
|
|
|
|
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>
|
|
|
|
|
|
2026-04-14 15:00:49 -06:00
|
|
|
{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
|
2024-10-15 17:02:59 -06:00
|
|
|
className='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}/>)}
|
2026-04-14 15:00:49 -06:00
|
|
|
</video>}
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
<Container style={{marginTop: '1em'}}>
|
|
|
|
|
<Segment>
|
|
|
|
|
|
2023-09-07 13:00:54 -06:00
|
|
|
<Header as='h2'>{title}</Header>
|
2024-10-08 17:15:48 -06:00
|
|
|
{videoFile.published_datetime && <h3>{isoDatetimeToAgoPopup(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'
|
2026-03-20 15:38:32 -06:00
|
|
|
onClick={async () => await handleDeleteVideo(videoFile.id)}
|
2023-07-21 15:14:09 -06:00
|
|
|
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>
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
<AddToPlaylistButton fileGroupId={videoFile.id}/>
|
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>
|
2026-05-03 17:28:06 -06:00
|
|
|
<TaggedDeleteConfirmModal
|
|
|
|
|
open={taggedFileGroups !== null}
|
|
|
|
|
taggedFileGroups={taggedFileGroups}
|
|
|
|
|
onCancel={() => setTaggedFileGroups(null)}
|
|
|
|
|
onConfirm={async () => {
|
|
|
|
|
setTaggedFileGroups(null);
|
|
|
|
|
await handleDeleteVideo(videoFile.id, true);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2023-02-17 16:09:24 -07:00
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-21 16:50:27 -06:00
|
|
|
function formatCaptionTimestamp(totalSeconds) {
|
|
|
|
|
totalSeconds = Math.floor(totalSeconds);
|
|
|
|
|
const hours = Math.floor(totalSeconds / 3600);
|
|
|
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
|
|
|
const seconds = totalSeconds % 60;
|
|
|
|
|
const pad2 = (n) => String(n).padStart(2, '0');
|
|
|
|
|
if (hours > 0) {
|
|
|
|
|
return `${hours}:${pad2(minutes)}:${pad2(seconds)}`;
|
|
|
|
|
}
|
|
|
|
|
return `${minutes}:${pad2(seconds)}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CaptionsPane({captions, captionsLoading, fetchCaptions, setVideoTime}) {
|
|
|
|
|
const [filter, setFilter] = useState('');
|
|
|
|
|
|
|
|
|
|
// Trigger fetch on first render of this pane.
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
fetchCaptions();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (captionsLoading) {
|
|
|
|
|
return <Tab.Pane><Loader active/></Tab.Pane>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!captions || captions.length === 0) {
|
|
|
|
|
return <Tab.Pane>No captions available.</Tab.Pane>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let filtered = captions;
|
|
|
|
|
if (filter.trim()) {
|
|
|
|
|
const words = filter.toLowerCase().split(/\s+/).filter(Boolean);
|
|
|
|
|
filtered = captions.filter(chunk => {
|
|
|
|
|
const text = chunk.text.toLowerCase();
|
|
|
|
|
return words.every(word => text.includes(word));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <Tab.Pane>
|
|
|
|
|
<Input
|
|
|
|
|
fluid
|
|
|
|
|
icon='filter'
|
|
|
|
|
placeholder='Filter captions...'
|
|
|
|
|
value={filter}
|
|
|
|
|
onChange={(e, {value}) => setFilter(value)}
|
|
|
|
|
style={{marginBottom: '1em'}}
|
|
|
|
|
/>
|
|
|
|
|
<div style={{maxHeight: '400px', overflowY: 'auto'}}>
|
|
|
|
|
{filtered.map((chunk, idx) => (
|
|
|
|
|
<div key={idx} style={{display: 'flex', gap: '1em', marginBottom: '0.4em'}}>
|
|
|
|
|
<a href='#'
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setVideoTime(chunk.start_seconds);
|
|
|
|
|
}}
|
|
|
|
|
style={{whiteSpace: 'nowrap', fontFamily: 'monospace'}}
|
|
|
|
|
>
|
|
|
|
|
{formatCaptionTimestamp(chunk.start_seconds)}
|
|
|
|
|
</a>
|
|
|
|
|
<span>{chunk.text}</span>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</Tab.Pane>;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|