Rates each source on three axes the user asked for: - freshness: how recently/often new content arrives (newest age + 7d volume) - richness: metadata coverage (thumbnail/tags/performers/description/studio/duration) - plays: does it actually play — from real playback telemetry when available, else a proxy from the resolve mechanism. 0★ = offline (gates the overall stars, so a fresh+rich source that doesn't play still ranks bottom — the hqfap/4k69 case) Backend: - playback_events: fire-and-forget telemetry POST from the app per playback attempt (origin + success/error + time-to-first-frame), append-only, 30d retention - source_stats: per-origin computed scores, refreshed by a scheduler job (6h); /sources joins it and sorts by stars - models + local migration 0025; new GOON_SCHED_SOURCE_STATS_HOURS setting Mobile: - Sites rows show ★ rating; tap the stars for a breakdown (axes + metadata %, plus whether "plays" is measured or estimated) - PlayerScreen reports playback success/failure per source (native path only — symmetric, conservative); origin threaded through Scene/Movie play callsites Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
2.1 KiB
Python
45 lines
2.1 KiB
Python
"""Playback telemetry — fire-and-forget ping z apki po każdej próbie odtwarzania.
|
|
|
|
Po co: ranking źródeł (Sites screen) potrzebuje realnego sygnału "czy to gra".
|
|
Świeżość i bogactwo metadanych liczymy z DB, ale "szybkość działania" znał tylko
|
|
telefon (resolve hosterów/WebView dzieje się phone-side). Bez tego sygnału źródło
|
|
może wyglądać świeżo i bogato, a serwować stub (problem hqfap/4k69).
|
|
|
|
Append-only, agregowane przez `run_source_stats` (okno 7d → health score per origin).
|
|
Retencja: stats-job kasuje wpisy starsze niż 30 dni. Brak FK na scene (scene_id
|
|
informacyjne, scena może zniknąć przez dedup/merge).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Index, Integer, String, func
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class PlaybackEvent(Base):
|
|
__tablename__ = "playback_events"
|
|
__table_args__ = (
|
|
Index("ix_playback_events_origin_created", "origin", "created_at"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
# 'tube:<sitetag>' — zgodne z playback_sources.origin (join po origin).
|
|
origin: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
scene_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True)
|
|
# 'success' = wideo realnie ruszyło; 'error' = resolve/player padł.
|
|
status: Mapped[str] = mapped_column(String(16), nullable=False)
|
|
# np. 'no_source', 'resolve_failed', 'player_error', 'timeout' (tylko gdy error).
|
|
error_kind: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
# time-to-first-frame [ms] — "szybkość" (tylko przy success; None gdy nie zmierzono).
|
|
ttff_ms: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
device_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
|
)
|