Ship zombie reconcile, S3 covers, session end/drill-down, rooms ops, and refresh README for production. Co-authored-by: Cursor <cursoragent@cursor.com>
108 lines
2.9 KiB
Python
108 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
import re
|
|
from datetime import datetime
|
|
from typing import Any, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
def extract_room_id(url_or_id: str) -> str:
|
|
text = (url_or_id or "").strip()
|
|
if not text:
|
|
return ""
|
|
if re.fullmatch(r"\d{6,}", text):
|
|
return text
|
|
m = re.search(r"live\.douyin\.com/([A-Za-z0-9_\-]+)", text)
|
|
if m:
|
|
return m.group(1).split("?")[0]
|
|
m = re.search(r"/(\d{8,})", text)
|
|
return m.group(1) if m else ""
|
|
|
|
|
|
def normalize_room_url(url_or_id: str) -> str:
|
|
rid = extract_room_id(url_or_id)
|
|
if rid:
|
|
return f"https://live.douyin.com/{rid}"
|
|
text = (url_or_id or "").strip()
|
|
if text.startswith("http"):
|
|
return text.split("?")[0].rstrip("/")
|
|
return text
|
|
|
|
|
|
def push_date_from_ts(ts: float) -> str:
|
|
return datetime.fromtimestamp(ts).strftime("%Y-%m-%d")
|
|
|
|
|
|
class RoomCreate(BaseModel):
|
|
url: str
|
|
note: str = ""
|
|
enabled: bool = True
|
|
tags: str = ""
|
|
|
|
|
|
class RoomBatchCreate(BaseModel):
|
|
urls: str = Field(..., description="多行直播间 URL / 房间号,每行一个")
|
|
note: str = ""
|
|
enabled: bool = True
|
|
tags: str = ""
|
|
|
|
|
|
class RoomUpdate(BaseModel):
|
|
url: Optional[str] = None
|
|
note: Optional[str] = None
|
|
enabled: Optional[bool] = None
|
|
tags: Optional[str] = None
|
|
|
|
|
|
class RoomBulkAction(BaseModel):
|
|
action: str = Field(..., description="enable|disable|delete|set_tags|add_tags|remove_tags|check_queue")
|
|
ids: list[str]
|
|
tags: str = ""
|
|
|
|
|
|
class BlacklistCreate(BaseModel):
|
|
value: str = Field(..., description="房间号、URL 或关键词")
|
|
reason: str = ""
|
|
|
|
|
|
class SettingsUpdate(BaseModel):
|
|
max_concurrency: Optional[int] = None
|
|
min_request_gap_sec: Optional[float] = None
|
|
request_jitter_sec: Optional[float] = None
|
|
offline_interval_sec: Optional[float] = None
|
|
live_interval_sec: Optional[float] = None
|
|
error_backoff_base_sec: Optional[float] = None
|
|
error_backoff_max_sec: Optional[float] = None
|
|
global_pause_on_risk_sec: Optional[float] = None
|
|
capture_cover_on_start: Optional[bool] = None
|
|
monitor_enabled: Optional[bool] = None
|
|
dy_cookie: Optional[str] = None
|
|
http_proxy: Optional[str] = None
|
|
notify_webhook_url: Optional[str] = None
|
|
notify_on_live: Optional[bool] = None
|
|
notify_on_offline: Optional[bool] = None
|
|
notify_on_risk: Optional[bool] = None
|
|
quiet_hours_enabled: Optional[bool] = None
|
|
quiet_hours_start: Optional[int] = None
|
|
quiet_hours_end: Optional[int] = None
|
|
priority_interval_sec: Optional[float] = None
|
|
|
|
|
|
class PurgeEventsBody(BaseModel):
|
|
older_than_days: float = 7
|
|
kind: str = ""
|
|
|
|
|
|
class MonitorStatus(BaseModel):
|
|
running: bool
|
|
monitor_enabled: bool
|
|
checked_total: int = 0
|
|
live_count: int = 0
|
|
room_count: int = 0
|
|
blacklist_count: int = 0
|
|
risk_paused_until: float = 0
|
|
last_error: str = ""
|
|
last_check_at: float = 0
|
|
config: dict[str, Any] = Field(default_factory=dict)
|