Nowy wertykal krotkich pionowych klipow tworcow, osobno od scen: inne kolumny (tworca, audio, lajki, nisze), inny cykl zycia, inna taksonomia, brak filtra 60 s. Tabele `clips` (unikalne source+source_id) i `clip_tags` z indeksem (tag, clip_id) pod skan po tagu od losowego uuid w przyszlym feedzie. Zrodlo nr 1: RedGifs, oficjalne API v2 z tokenem tymczasowym (zwiazany z IP i UA, na 401 odnowienie). Globalne `order=latest` bez search_text daje ~100 na strone, kazde zapytanie widzi maks. 10 000 wynikow, wiec katalog chodzi sie po niszach (skrypt backfillu). Pliki media.redgifs.com sa publiczne i bez podpisu (206 z VPS-a i z telefonu), do bazy wchodzi gotowy adres. Scheduler: job clips-latest co godzine (5 stron), zatrzymuje sie na stronie bez nowych. Reaper (HEAD, 403/404/410 -> dead_at) jako skrypt, upsert odzywia klip, ktory zrodlo znow podaje. API: GET /clips i /clips/stats do pilota; wlasciwy feed, pamiec widzianych i telemetria to etap 3. Sprawdzone tego dnia i odlozone: nsfwswipe (lustro v.redd.it, bez audio, stoi od 19.08), Pornhub Shorties (zrodlo nr 2, HLS z tokenem 2 h, Referer na segmentach, 0/110 performerow z kanonu).
70 lines
3.3 KiB
Python
70 lines
3.3 KiB
Python
"""Klipy do feedu Swipe: tabele `clips` i `clip_tags`.
|
|
|
|
Osobny wertykał (krótkie pionowe wideo twórców z RedGifs / Pornhub Shorties), nie sceny.
|
|
Uzasadnienie w docstringu `app/models/clip.py`.
|
|
|
|
Revision ID: 0036_clips
|
|
Revises: 0035_scenes_duration_idx
|
|
Create Date: 2026-09-14
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision = "0036_clips"
|
|
down_revision: str | None = "0035_scenes_duration_idx"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"clips",
|
|
sa.Column("id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.Column("source", sa.String(16), nullable=False),
|
|
sa.Column("source_id", sa.String(64), nullable=False),
|
|
sa.Column("title", sa.Text(), nullable=True),
|
|
sa.Column("creator", sa.String(128), nullable=True),
|
|
sa.Column("creator_verified", sa.Boolean(), nullable=False, server_default=sa.false()),
|
|
sa.Column("duration_sec", sa.Float(), nullable=True),
|
|
sa.Column("width", sa.Integer(), nullable=True),
|
|
sa.Column("height", sa.Integer(), nullable=True),
|
|
sa.Column("has_audio", sa.Boolean(), nullable=False, server_default=sa.false()),
|
|
sa.Column("content_type", sa.String(32), nullable=True),
|
|
sa.Column("niches", postgresql.ARRAY(sa.String(64)), nullable=False, server_default="{}"),
|
|
sa.Column("hd_url", sa.Text(), nullable=True),
|
|
sa.Column("sd_url", sa.Text(), nullable=True),
|
|
sa.Column("poster_url", sa.Text(), nullable=True),
|
|
sa.Column("thumb_url", sa.Text(), nullable=True),
|
|
sa.Column("hls", sa.Boolean(), nullable=False, server_default=sa.false()),
|
|
sa.Column("likes", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.Column("views", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.Column("published_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("dead_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("dead_reason", sa.String(128), nullable=True),
|
|
sa.PrimaryKeyConstraint("id", name="pk_clips"),
|
|
sa.UniqueConstraint("source", "source_id", name="uq_clips_source_source_id"),
|
|
)
|
|
op.create_index("ix_clips_published_at", "clips", ["published_at"])
|
|
op.create_index("ix_clips_creator", "clips", ["creator"])
|
|
|
|
op.create_table(
|
|
"clip_tags",
|
|
sa.Column("clip_id", postgresql.UUID(as_uuid=True), nullable=False),
|
|
sa.Column("tag", sa.String(64), nullable=False),
|
|
sa.ForeignKeyConstraint(["clip_id"], ["clips.id"], name="fk_clip_tags_clip_id_clips", ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("clip_id", "tag", name="pk_clip_tags"),
|
|
)
|
|
op.create_index("ix_clip_tags_tag_clip", "clip_tags", ["tag", "clip_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_clip_tags_tag_clip", table_name="clip_tags")
|
|
op.drop_table("clip_tags")
|
|
op.drop_index("ix_clips_creator", table_name="clips")
|
|
op.drop_index("ix_clips_published_at", table_name="clips")
|
|
op.drop_table("clips")
|