myYouTube/frontend/src/components/Player.tsx
vrubelroman fe16c08daa Implement Phase 6: MeTube download integration
- MeTubeClient encapsulates all MeTube HTTP/Socket.IO calls (verified against
  the real MeTube source: /add returns no job id, GET /history gives a queue
  snapshot for reconciliation, filenames arrive already relative, percent is
  a 0-100 float)
- download_jobs table + service: request/dedup active downloads, apply live
  Socket.IO events (added/updated/completed/canceled/cleared) matched by
  canonical YouTube URL, safe relative-path -> public media URL construction
- Reconciliation on startup against MeTube's live queue/done state (section 19):
  non-terminal jobs recovered where possible, else marked "unknown"; already
  completed jobs are left untouched
- POST/GET /api/videos/{id}/download(-status), recheck-local; feed/video
  detail now report real local availability instead of a stub
- Frontend: download button with live status polling (queued/downloading %/
  postprocessing/completed/failed+retry), local <video> playback with
  YouTube fallback on playback error
- health.py now delegates to MeTubeClient (single place for MeTube calls)

26 new backend tests (63 total). Verified live: Socket.IO connects
successfully to the real MeTube instance on deploy.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:56:17 +00:00

60 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import type { FeedVideoDto } from '../api/client'
import { recheckLocal } from '../api/client'
interface Props {
video: FeedVideoDto
}
function Player({ video }: Props) {
const [localFailed, setLocalFailed] = useState(false)
const queryClient = useQueryClient()
const recheckMutation = useMutation({
mutationFn: () => recheckLocal(video.youtube_video_id),
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['video', video.youtube_video_id] })
queryClient.invalidateQueries({ queryKey: ['download-status', video.youtube_video_id] })
},
})
const useLocal = video.local.available && !!video.local.media_url && !localFailed
if (useLocal) {
return (
<>
<div className="player-wrapper">
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
<video
controls
src={video.local.media_url!}
onError={() => {
setLocalFailed(true)
recheckMutation.mutate()
}}
/>
</div>
<div className="video-page-source">● Локальная копия · mediaVM</div>
</>
)
}
return (
<>
<div className="player-wrapper">
<iframe
src={`https://www.youtube-nocookie.com/embed/${video.youtube_video_id}`}
title={video.title}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
/>
</div>
<div className="video-page-source">
{localFailed ? 'Локальная копия недоступна. Переключено на YouTube.' : 'Источник: YouTube'}
</div>
</>
)
}
export default Player