goon/app/models/playback_event.py
jtrzupek ad43f4f20d
Some checks are pending
Backend tests / test (push) Waiting to run
fix(watchporn): re-resolve stale CDN URL in-player, drop WebView page fallback
The zload CDN URL (remote_control.php) is a valid faststart progressive mp4 that
ExoPlayer plays fine when fresh: 206, no IP/referer binding, ~2h token TTL,
verified from a residential IP. Real-device failures (player_error/gone
telemetry) come from the static URL going stale: a rotated or dead CDN node, or
an expired token.

Instead of falling back to the tube page in a WebView (removed, it papered over
the real issue), PlayerScreen now re-resolves the scene fresh via the backend on
initial-load error for backend-native KVS tubes (watchporn). That yields a live
node plus a fresh token and stays on the native direct stream (0 VPS bandwidth).
For these origins a CDN 'gone' (404) means stale URL, not deleted, so we
re-resolve on gone too; a genuinely deleted post raises HosterDead (410) and
falls through to the normal fallback chain.

Also: add playback_events.error_detail (raw ExoPlayer message) to pin down the
exact failure of tubes we cannot reproduce on the emulator. Keep FLAG_SECURE on
release builds only (!__DEV__) so debug builds stay screenshottable for local UI
verification.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 01:18:08 +02:00

48 lines
2.3 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)
# Surowa treść błędu z native playera (ExoPlayer message, ucięta) — dokładna
# diagnostyka realnych padów niereprodukowalnych na emulatorze.
error_detail: Mapped[str | None] = mapped_column(String(512), 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
)