65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""
|
|
Playlist subscription model
|
|
"""
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
from typing import Optional, List
|
|
|
|
from sqlalchemy import Column, String, Integer, DateTime, Boolean, Text, Index
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from ..core.database import Base
|
|
|
|
|
|
class PlaylistSubscription(Base):
|
|
"""Playlist subscription model"""
|
|
|
|
__tablename__ = "playlists"
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
url = Column(String, nullable=False, unique=True)
|
|
title = Column(String, nullable=True)
|
|
|
|
# Configuration
|
|
check_interval = Column(Integer, default=60, nullable=False) # minutes
|
|
last_checked = Column(DateTime, nullable=True)
|
|
start_point = Column(String, nullable=True) # video_id or index
|
|
quality = Column(String, default="best", nullable=False)
|
|
format = Column(String, default="mp4", nullable=False)
|
|
folder = Column(String, nullable=True)
|
|
enabled = Column(Boolean, default=True, nullable=False)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime, default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), nullable=False)
|
|
|
|
# Relationships
|
|
videos = relationship("VideoRecord", back_populates="playlist", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<PlaylistSubscription(id='{self.id}', title='{self.title}', url='{self.url}')>"
|
|
|
|
@property
|
|
def is_enabled(self) -> bool:
|
|
"""Check if playlist is enabled for monitoring"""
|
|
return self.enabled
|
|
|
|
def should_check(self) -> bool:
|
|
"""Check if playlist should be checked based on interval"""
|
|
if not self.enabled:
|
|
return False
|
|
|
|
if self.last_checked is None:
|
|
return True
|
|
|
|
import datetime as dt
|
|
time_since_last_check = dt.datetime.utcnow() - self.last_checked
|
|
return time_since_last_check.total_seconds() / 60 >= self.check_interval
|
|
|
|
|
|
# Create indexes for better query performance
|
|
Index("idx_playlists_enabled", PlaylistSubscription.enabled)
|
|
Index("idx_playlists_last_checked", PlaylistSubscription.last_checked) |