feat(stream): implement stream processing service with routes for managing streaming URLs; add support for concurrent processing and metadata extraction

This commit is contained in:
JSC
2025-07-06 16:57:33 +02:00
parent 61db6c56dc
commit 4f18f3e64e
11 changed files with 786 additions and 14 deletions

View File

@@ -36,6 +36,9 @@ class Sound(db.Model):
# Basic sound information
name: Mapped[str] = mapped_column(String(255), nullable=False)
filename: Mapped[str] = mapped_column(String(500), nullable=False)
thumbnail: Mapped[str | None] = mapped_column(
String(500), nullable=True
) # Thumbnail filename
duration: Mapped[int] = mapped_column(Integer, nullable=False)
size: Mapped[int] = mapped_column(Integer, nullable=False) # Size in bytes
hash: Mapped[str] = mapped_column(String(64), nullable=False) # SHA256 hash
@@ -114,6 +117,7 @@ class Sound(db.Model):
"type": self.type,
"name": self.name,
"filename": self.filename,
"thumbnail": self.thumbnail,
"duration": self.duration,
"size": self.size,
"hash": self.hash,
@@ -217,6 +221,7 @@ class Sound(db.Model):
duration: float,
size: int,
hash_value: str,
thumbnail: Optional[str] = None,
is_music: bool = False,
is_deletable: bool = True,
commit: bool = True,
@@ -230,6 +235,7 @@ class Sound(db.Model):
type=sound_type,
name=name,
filename=filename,
thumbnail=thumbnail,
duration=duration,
size=size,
hash=hash_value,

View File

@@ -4,7 +4,7 @@ from datetime import datetime
from typing import TYPE_CHECKING, Optional
from zoneinfo import ZoneInfo
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import db
@@ -33,6 +33,7 @@ class Stream(db.Model):
status: Mapped[str] = mapped_column(
String(50), nullable=False, default="pending"
)
error: Mapped[str | None] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(
DateTime,
default=lambda: datetime.now(tz=ZoneInfo("UTC")),
@@ -48,6 +49,13 @@ class Stream(db.Model):
# Relationships
sound: Mapped["Sound"] = relationship("Sound", back_populates="streams")
# Constraints
__table_args__ = (
UniqueConstraint(
"service", "service_id", name="unique_service_stream"
),
)
def __repr__(self) -> str:
"""String representation of the stream."""
return f"<Stream(id={self.id}, service='{self.service}', service_id='{self.service_id}', sound_id={self.sound_id})>"
@@ -66,6 +74,7 @@ class Stream(db.Model):
"album": self.album,
"genre": self.genre,
"status": self.status,
"error": self.error,
"created_at": (
self.created_at.isoformat() if self.created_at else None
),