refactor: Remove unused playlist routes and related logic; clean up sound and stream models
This commit is contained in:
@@ -4,7 +4,14 @@ from datetime import datetime
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy import (
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import db
|
||||
@@ -51,9 +58,7 @@ class Stream(db.Model):
|
||||
|
||||
# Constraints
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"service", "service_id", name="unique_service_stream"
|
||||
),
|
||||
UniqueConstraint("service", "service_id", name="unique_service_stream"),
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
@@ -117,70 +122,3 @@ class Stream(db.Model):
|
||||
db.session.commit()
|
||||
|
||||
return stream
|
||||
|
||||
@classmethod
|
||||
def find_by_service_and_id(
|
||||
cls, service: str, service_id: str
|
||||
) -> Optional["Stream"]:
|
||||
"""Find stream by service and service_id."""
|
||||
return cls.query.filter_by(
|
||||
service=service, service_id=service_id
|
||||
).first()
|
||||
|
||||
@classmethod
|
||||
def find_by_sound(cls, sound_id: int) -> list["Stream"]:
|
||||
"""Find all streams for a specific sound."""
|
||||
return cls.query.filter_by(sound_id=sound_id).all()
|
||||
|
||||
@classmethod
|
||||
def find_by_service(cls, service: str) -> list["Stream"]:
|
||||
"""Find all streams for a specific service."""
|
||||
return cls.query.filter_by(service=service).all()
|
||||
|
||||
@classmethod
|
||||
def find_by_status(cls, status: str) -> list["Stream"]:
|
||||
"""Find all streams with a specific status."""
|
||||
return cls.query.filter_by(status=status).all()
|
||||
|
||||
@classmethod
|
||||
def find_active_streams(cls) -> list["Stream"]:
|
||||
"""Find all active streams."""
|
||||
return cls.query.filter_by(status="active").all()
|
||||
|
||||
def update_metadata(
|
||||
self,
|
||||
title: Optional[str] = None,
|
||||
track: Optional[str] = None,
|
||||
artist: Optional[str] = None,
|
||||
album: Optional[str] = None,
|
||||
genre: Optional[str] = None,
|
||||
commit: bool = True,
|
||||
) -> None:
|
||||
"""Update stream metadata."""
|
||||
if title is not None:
|
||||
self.title = title
|
||||
if track is not None:
|
||||
self.track = track
|
||||
if artist is not None:
|
||||
self.artist = artist
|
||||
if album is not None:
|
||||
self.album = album
|
||||
if genre is not None:
|
||||
self.genre = genre
|
||||
|
||||
if commit:
|
||||
db.session.commit()
|
||||
|
||||
def set_status(self, status: str, commit: bool = True) -> None:
|
||||
"""Update stream status."""
|
||||
self.status = status
|
||||
if commit:
|
||||
db.session.commit()
|
||||
|
||||
def is_active(self) -> bool:
|
||||
"""Check if stream is active."""
|
||||
return self.status == "active"
|
||||
|
||||
def get_display_name(self) -> str:
|
||||
"""Get a display name for the stream (title or track or service_id)."""
|
||||
return self.title or self.track or self.service_id
|
||||
|
||||
Reference in New Issue
Block a user