import React, {useContext, useEffect, useState} from 'react'; import {Link, Route, Routes, useParams} from "react-router-dom"; import { APIButton, CardLink, CardPoster, defaultSearchOrder, defaultVideoOrder, Duration, encodeMediaPath, ErrorMessage, FileIcon, findPosterPath, isoDatetimeToString, mimetypeColor, PageContainer, PreviewLink, scrollToTop, SearchInput, SortButton, TabLinks, textEllipsis, useTitle } from "./Common" import VideoPage from "./VideoPlayer"; import { CardContent, CardDescription, CardHeader, Container, Image, PlaceholderHeader, PlaceholderLine, StatisticLabel, StatisticValue, TableCell } from "semantic-ui-react"; import {ChannelsPage, EditChannel, NewChannel} from "./Channels"; import {useChannel, useQuery, useSearchVideos, useVideo, useVideoStatistics} from "../hooks/customHooks"; import {FileRowTagIcon, FilesView} from "./Files"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import Icon from "semantic-ui-react/dist/commonjs/elements/Icon"; import {Button, Card, Header, Loader, Placeholder, Segment, Statistic, StatisticGroup} from "./Theme"; import {deleteVideos} from "../api"; import {Media, ThemeContext} from "../contexts/contexts"; import _ from "lodash"; export function VideoWrapper() { const {videoId} = useParams(); const {videoFile, prevFile, nextFile, fetchVideo} = useVideo(videoId); // Scroll to the top when videoId changes. useEffect(scrollToTop, [videoId]); return } function VideosPage() { const {channelId} = useParams(); const {searchParams} = useQuery(); const [selectedVideos, setSelectedVideos] = useState([]); let searchOrder = defaultVideoOrder; if (searchParams.get('order')) { // Use whatever order the user specified. searchOrder = searchParams.get('order'); } else if (searchParams.get('q')) { // User used a search_str searchOrder = defaultSearchOrder; } const {searchStr, setSearchStr, videos, activePage, setPage, totalPages, fetchVideos} = useSearchVideos(null, channelId, searchOrder); const {channel} = useChannel(channelId); let title = 'Videos'; if (channel && channel.name) { title = `${channel.name} Videos`; } useTitle(title); let videoOrders = [ {value: 'published_datetime', text: 'Published Date', short: 'P.Date'}, {value: 'length', text: 'Length'}, {value: 'size', text: 'Size'}, {value: 'view_count', text: 'Views'}, {value: 'viewed', text: 'Recently Viewed', short: 'R.Viewed'}, ] if (searchStr) { videoOrders = [{value: 'rank', text: 'Search'}, ...videoOrders]; } let header; if (channel && channel.name) { const editLink = `/videos/channel/${channelId}/edit`; header = <>
{channel.name}
; } else if (channelId) { header = ; } const onSelect = (path, checked) => { const newSelectedVideos = checked && path ? [...selectedVideos, path] : selectedVideos.filter(i => i !== path); console.debug(`Selected Videos: ${newSelectedVideos}`); setSelectedVideos(newSelectedVideos); } const onDelete = async () => { const videoIds = videos.filter(i => selectedVideos.indexOf(i['primary_path']) >= 0).map(i => i['video']['id']); await deleteVideos(videoIds); await fetchVideos(); setSelectedVideos([]); } const invertSelection = async () => { const newSelectedVideos = videos.map(video => video['key']).filter(i => selectedVideos.indexOf(i) < 0); setSelectedVideos(newSelectedVideos); } const clearSelection = async (e) => { if (e) e.preventDefault(); setSelectedVideos([]); } const selectElm =
Delete
; const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView( videos, activePage, totalPages, selectElm, selectedVideos, onSelect, setPage, !!searchStr, ); const searchInput = ; return <> {header} {selectButton} {viewButton} {limitDropdown} {tagQuerySelector} {searchInput} {selectButton} {viewButton} {limitDropdown} {tagQuerySelector} {searchInput} {body} {paginator} } function VideosStatistics() { useTitle('Video Statistics'); const {statistics} = useVideoStatistics(); if (statistics === null) { // Request is pending. return } else if (statistics === undefined) { return Unable to fetch Video Statistics } const {videos, historical, channels} = statistics; const videoNames = [ {key: 'videos', label: 'Videos'}, {key: 'sum_size', label: 'Total Size'}, {key: 'max_size', label: 'Largest Video'}, {key: 'week', label: 'Downloads Past Week'}, {key: 'month', label: 'Downloads Past Month'}, {key: 'year', label: 'Downloads Past Year'}, {key: 'sum_duration', label: 'Total Duration'}, ]; const historicalNames = [ {key: 'average_count', label: 'Average Monthly Downloads'}, {key: 'average_size', label: 'Average Monthly Usage'}, ]; const channelNames = [ {key: 'channels', label: 'Channels'}, ]; const buildSegment = (title, names, stats) => { return
{title}
{names.map( ({key, label}) => {stats[key]} {label} )}
} return <> {buildSegment('Videos', videoNames, videos)} {buildSegment('Historical Video', historicalNames, historical)} {buildSegment('Channels', channelNames, channels)} } export function VideosRoute(props) { const links = [ {text: 'Videos', to: '/videos', key: 'videos', end: true}, {text: 'Channels', to: '/videos/channel', key: 'channel'}, {text: 'Statistics', to: '/videos/statistics', key: 'statistics'}, ]; return }/> }/> }/> }/> }/> }/> } export function VideoCard({file}) { const {video} = file; const {s} = useContext(ThemeContext); // Default to video FilePreview for lone video files. let video_url; const published_datetime = isoDatetimeToString(file.published_datetime); // A video may not have a channel. const channel = video.channel ? video.channel : null; let channel_url = null; if (channel) { // Link to Video in the Channel if possible. channel_url = `/videos/channel/${channel.id}/video`; video_url = `/videos/channel/${channel.id}/video/${video.id}`; } else if (file.files.length > 1) { // No Channel, but the video has multiple files (subtitles, etc.). Use the full VideoPage. video_url = `/videos/video/${video.id}` } let poster = ; let header = {file.title || file.name || video.stem || video.name}; if (video_url) { // Link to Channel-Video page or Video page. header = {header}; } else { // Video is just a lone video file. header = {header} ; } const color = mimetypeColor(file.mimetype); return {poster} {header} {channel && {channel.name} }

{published_datetime}

} export function VideoRowCells({file}) { const {video} = file; let video_url = `/videos/video/${video.id}`; const poster_path = findPosterPath(file); const poster_url = poster_path ? `/media/${encodeMediaPath(poster_path)}` : null; let poster; if (poster_url) { poster = } else { poster = ; } // Fragment for SelectableRow return
{poster}
{textEllipsis(file.title || video.stem || video.video_path)}
}