style: apply ruff format across backend + scripts (line-length 100)
Mechanical, whole-tree `ruff format` pass — no behaviour change. Recorded in .git-blame-ignore-revs (next commit) so git blame skips it.
This commit is contained in:
+11
-19
@@ -1,6 +1,7 @@
|
||||
"""Video ingestion: free RSS detection, recent-first (and deep) backfill from the
|
||||
uploads playlist, and enrichment via videos.list (duration, stats, category, Shorts
|
||||
and livestream classification)."""
|
||||
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
@@ -16,9 +17,7 @@ from app.titles import normalize_title
|
||||
from app.youtube.client import YouTubeClient, best_thumbnail
|
||||
from app.youtube.shorts import make_client, probe_is_short
|
||||
|
||||
_DURATION_RE = re.compile(
|
||||
r"P(?:(\d+)D)?T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?", re.IGNORECASE
|
||||
)
|
||||
_DURATION_RE = re.compile(r"P(?:(\d+)D)?T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?", re.IGNORECASE)
|
||||
|
||||
|
||||
def _now() -> datetime:
|
||||
@@ -177,9 +176,7 @@ def backfill_channel_deep(
|
||||
data = yt.get_playlist_items(channel.uploads_playlist_id, page_token)
|
||||
rows = [
|
||||
s
|
||||
for s in (
|
||||
stub_from_playlist_item(it, channel.id) for it in data.get("items", [])
|
||||
)
|
||||
for s in (stub_from_playlist_item(it, channel.id) for it in data.get("items", []))
|
||||
if s is not None
|
||||
]
|
||||
total += insert_stubs(db, rows)
|
||||
@@ -201,11 +198,7 @@ def reconcile_full_history(db: Session) -> int:
|
||||
deep-requested, so the demand-driven deep job never ran). Without this such a channel
|
||||
sits in 'needs full history' forever despite having every video. Idempotent, no API
|
||||
quota; returns the number of channels flipped."""
|
||||
stored = (
|
||||
select(func.count(Video.id))
|
||||
.where(Video.channel_id == Channel.id)
|
||||
.scalar_subquery()
|
||||
)
|
||||
stored = select(func.count(Video.id)).where(Video.channel_id == Channel.id).scalar_subquery()
|
||||
result = db.execute(
|
||||
update(Channel)
|
||||
.where(
|
||||
@@ -263,9 +256,7 @@ def apply_video_details(video: Video, item: dict) -> None:
|
||||
tags = snippet.get("tags")
|
||||
video.keywords = " ".join(tags) if tags else None
|
||||
video.topic_categories = topics.get("topicCategories")
|
||||
video.default_language = snippet.get("defaultLanguage") or snippet.get(
|
||||
"defaultAudioLanguage"
|
||||
)
|
||||
video.default_language = snippet.get("defaultLanguage") or snippet.get("defaultAudioLanguage")
|
||||
video.live_status = _live_status(snippet, live)
|
||||
# status part: used by the maintenance/validation job to judge playability.
|
||||
if status:
|
||||
@@ -309,9 +300,7 @@ def _mark_enriched(video: Video) -> None:
|
||||
def enrich_pending(db: Session, yt: YouTubeClient, limit: int | None = None) -> int:
|
||||
limit = limit or sysconfig.get_int(db, "enrich_batch_size")
|
||||
videos = (
|
||||
db.execute(select(Video).where(Video.enriched_at.is_(None)).limit(limit))
|
||||
.scalars()
|
||||
.all()
|
||||
db.execute(select(Video).where(Video.enriched_at.is_(None)).limit(limit)).scalars().all()
|
||||
)
|
||||
return _apply_video_batch(db, yt, list(videos), _mark_enriched)
|
||||
|
||||
@@ -377,12 +366,14 @@ def run_shorts_classification(db: Session, limit: int | None = None) -> dict:
|
||||
# 2) Probe the remaining candidates.
|
||||
candidates = (
|
||||
db.execute(
|
||||
select(Video).where(
|
||||
select(Video)
|
||||
.where(
|
||||
Video.shorts_probed.is_(False),
|
||||
Video.enriched_at.is_not(None),
|
||||
Video.duration_seconds <= probe_max,
|
||||
Video.live_status == "none",
|
||||
).limit(limit)
|
||||
)
|
||||
.limit(limit)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
@@ -393,6 +384,7 @@ def run_shorts_classification(db: Session, limit: int | None = None) -> dict:
|
||||
probed = 0
|
||||
shorts = 0
|
||||
with make_client() as client:
|
||||
|
||||
def work(video: Video):
|
||||
return video, probe_is_short(client, video.id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user