Files
KiraTV/backend/models/provider.py
T
joaquin cccdf9f137 feat: multi-domain failover for provider accounts
Each ProviderAccount can now have multiple base URLs (provider_urls table).
On stream failure, BroadcastGroup cycles to the next domain immediately
with no wait; backs off only after all domains have been tried once.
Background health checker pings every domain every 5 min via player_api.php
and updates status/response_ms. Admin UI shows domain list with color-coded
status badges and a "Verificar todos" button per provider.
2026-05-18 00:11:06 +02:00

42 lines
2.1 KiB
Python

from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text, ForeignKey, func
from sqlalchemy.orm import relationship
from ..database import Base
class ProviderAccount(Base):
__tablename__ = "provider_accounts"
id = Column(Integer, primary_key=True, index=True)
name = Column(String(100), nullable=False)
base_url = Column(String(500), nullable=False)
username = Column(String(200), nullable=False)
password = Column(String(200), nullable=False)
max_connections = Column(Integer, default=1, nullable=False)
is_active = Column(Boolean, default=True, nullable=False)
last_sync_at = Column(DateTime(timezone=True), nullable=True)
expiry_date = Column(DateTime(timezone=True), nullable=True)
# 0 = disabled; 6/12/24 = sync every N hours automatically
auto_sync_hours = Column(Integer, default=0, nullable=False)
# JSON: {"live": ["cat_id", ...], "movie": [...], "series": [...]}
last_sync_categories = Column(Text, nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
channel_maps = relationship("ChannelProviderMap", back_populates="provider_account", cascade="all, delete-orphan")
extra_urls = relationship("ProviderUrl", back_populates="provider_account", cascade="all, delete-orphan", order_by="ProviderUrl.priority")
class ProviderUrl(Base):
__tablename__ = "provider_urls"
id = Column(Integer, primary_key=True, index=True)
provider_account_id = Column(Integer, ForeignKey("provider_accounts.id", ondelete="CASCADE"), nullable=False, index=True)
url = Column(String(500), nullable=False)
priority = Column(Integer, default=0, nullable=False) # 0=primary, higher=lower priority
is_active = Column(Boolean, default=True, nullable=False)
status = Column(String(20), default="unknown", nullable=False) # unknown|ok|error|timeout
response_ms = Column(Integer, nullable=True)
last_checked_at = Column(DateTime(timezone=True), nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
provider_account = relationship("ProviderAccount", back_populates="extra_urls")