Initial commit: Phase 1 – Projektstruktur, DB-Schema, Core-API
- FastAPI-Backend mit vollständiger ABS v2.x API-Kompatibilität - SQLAlchemy-Models: User, Library, LibraryItem, BookFile, Chapter, Podcast, PodcastEpisode, MediaProgress, Bookmark, PlaybackSession - Auth: JWT-Login (/login, /logout, /api/authorize) - Library + Items Endpoints inkl. camelCase ABS-Response-Format - HLS-Streaming via FFmpeg (POST /api/items/:id/play, Session-Sync) - Me/Progress Endpoints + Lesezeichen - User-Management + Server-Settings (Admin) - Library-Scanner (MP3/WAV Discovery, Hintergrund-Task) - File Watcher (watchdog, 30s Debounce) - Matching-Skelett (MusicBrainz, OpenLibrary, Google Books – Phase 5) - Docker-Setup: backend (Python 3.12+FFmpeg), frontend (React/Vite), nginx Reverse-Proxy auf Port 3000 - setup.sh: Installiert Docker auf Debian/Ubuntu, richtet .env ein Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
12
backend/app/models/__init__.py
Normal file
12
backend/app/models/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from .user import User
|
||||
from .library import Library
|
||||
from .media_item import LibraryItem, BookFile, Chapter
|
||||
from .podcast import Podcast, PodcastEpisode
|
||||
from .progress import MediaProgress, Bookmark
|
||||
from .session import PlaybackSession, ServerSetting, ScanJob
|
||||
|
||||
__all__ = [
|
||||
"User", "Library", "LibraryItem", "BookFile", "Chapter",
|
||||
"Podcast", "PodcastEpisode", "MediaProgress", "Bookmark",
|
||||
"PlaybackSession", "ServerSetting", "ScanJob",
|
||||
]
|
||||
21
backend/app/models/library.py
Normal file
21
backend/app/models/library.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, DateTime
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.dialects.sqlite import JSON
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class Library(Base):
|
||||
__tablename__ = "libraries"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
display_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
# ABS-Format: [{"id": "...", "fullPath": "/audiofiles/..."}]
|
||||
folders: Mapped[list] = mapped_column(JSON, default=list)
|
||||
# "book" oder "podcast"
|
||||
media_type: Mapped[str] = mapped_column(String(20), default="book")
|
||||
settings: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
76
backend/app/models/media_item.py
Normal file
76
backend/app/models/media_item.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Integer, Float, Boolean, DateTime, Text, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.dialects.sqlite import JSON
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class LibraryItem(Base):
|
||||
__tablename__ = "library_items"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
library_id: Mapped[str] = mapped_column(String(36), ForeignKey("libraries.id", ondelete="CASCADE"), nullable=False)
|
||||
media_type: Mapped[str] = mapped_column(String(20), default="book") # "book" / "podcast"
|
||||
path: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
ino: Mapped[str | None] = mapped_column(String(100), nullable=True) # ABS inode-Feld
|
||||
|
||||
# Metadaten
|
||||
title: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
subtitle: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
author: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
narrator: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
publisher: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
publish_year: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
series: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
series_sequence: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
cover_path: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
language: Mapped[str | None] = mapped_column(String(10), nullable=True)
|
||||
genres: Mapped[list] = mapped_column(JSON, default=list)
|
||||
tags: Mapped[list] = mapped_column(JSON, default=list)
|
||||
explicit: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
abridged: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
# Datei-Infos
|
||||
duration_seconds: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
size_bytes: Mapped[int] = mapped_column(Integer, default=0)
|
||||
num_files: Mapped[int] = mapped_column(Integer, default=0)
|
||||
|
||||
# Matching
|
||||
matched_source: Mapped[str] = mapped_column(String(50), default="none")
|
||||
matched_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
match_confidence: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
match_locked: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
# Status
|
||||
is_missing: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
is_invalid: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
added_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
|
||||
class BookFile(Base):
|
||||
__tablename__ = "book_files"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
library_item_id: Mapped[str] = mapped_column(String(36), ForeignKey("library_items.id", ondelete="CASCADE"), nullable=False)
|
||||
filename: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
path: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
format: Mapped[str] = mapped_column(String(10), nullable=False) # mp3 / wav
|
||||
size_bytes: Mapped[int] = mapped_column(Integer, default=0)
|
||||
duration_seconds: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
track_index: Mapped[int] = mapped_column(Integer, default=0)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
|
||||
class Chapter(Base):
|
||||
__tablename__ = "chapters"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
library_item_id: Mapped[str] = mapped_column(String(36), ForeignKey("library_items.id", ondelete="CASCADE"), nullable=False)
|
||||
chapter_index: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
title: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
start_seconds: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
end_seconds: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
40
backend/app/models/podcast.py
Normal file
40
backend/app/models/podcast.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Integer, Float, Boolean, DateTime, Text, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.dialects.sqlite import JSON
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class Podcast(Base):
|
||||
__tablename__ = "podcasts"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
library_item_id: Mapped[str] = mapped_column(String(36), ForeignKey("library_items.id", ondelete="CASCADE"), unique=True, nullable=False)
|
||||
feed_url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
feed_type: Mapped[str] = mapped_column(String(10), default="rss")
|
||||
feed_last_checked: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
update_interval_hours: Mapped[int] = mapped_column(Integer, default=24)
|
||||
author: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
categories: Mapped[list] = mapped_column(JSON, default=list)
|
||||
explicit: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
language: Mapped[str | None] = mapped_column(String(10), nullable=True)
|
||||
|
||||
|
||||
class PodcastEpisode(Base):
|
||||
__tablename__ = "podcast_episodes"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
podcast_id: Mapped[str] = mapped_column(String(36), ForeignKey("podcasts.id", ondelete="CASCADE"), nullable=False)
|
||||
episode_number: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||
season_number: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||
title: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
pub_date: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
duration_seconds: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
path: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
size_bytes: Mapped[int] = mapped_column(Integer, default=0)
|
||||
feed_episode_id: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
feed_episode_url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
explicit: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
32
backend/app/models/progress.py
Normal file
32
backend/app/models/progress.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Float, Boolean, DateTime, Text, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class MediaProgress(Base):
|
||||
__tablename__ = "media_progress"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
user_id: Mapped[str] = mapped_column(String(36), ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
library_item_id: Mapped[str] = mapped_column(String(36), ForeignKey("library_items.id", ondelete="CASCADE"), nullable=False)
|
||||
episode_id: Mapped[str | None] = mapped_column(String(36), nullable=True)
|
||||
duration: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
current_time: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
is_finished: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
hide_from_continue_listening: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
last_update: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
|
||||
|
||||
class Bookmark(Base):
|
||||
__tablename__ = "bookmarks"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
user_id: Mapped[str] = mapped_column(String(36), ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
library_item_id: Mapped[str] = mapped_column(String(36), ForeignKey("library_items.id", ondelete="CASCADE"), nullable=False)
|
||||
time_seconds: Mapped[float] = mapped_column(Float, nullable=False)
|
||||
title: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
46
backend/app/models/session.py
Normal file
46
backend/app/models/session.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Float, Boolean, DateTime, Text, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.dialects.sqlite import JSON
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class PlaybackSession(Base):
|
||||
__tablename__ = "playback_sessions"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
user_id: Mapped[str] = mapped_column(String(36), ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
library_item_id: Mapped[str] = mapped_column(String(36), ForeignKey("library_items.id", ondelete="CASCADE"), nullable=False)
|
||||
episode_id: Mapped[str | None] = mapped_column(String(36), nullable=True)
|
||||
media_type: Mapped[str] = mapped_column(String(20), default="book")
|
||||
current_time: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
duration: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
device_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
device_info: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
media_player: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
||||
started_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
hls_session_path: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
|
||||
class ServerSetting(Base):
|
||||
__tablename__ = "server_settings"
|
||||
|
||||
key: Mapped[str] = mapped_column(String(100), primary_key=True)
|
||||
value: Mapped[dict | list | str | bool | int | float | None] = mapped_column(JSON, nullable=True)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
|
||||
class ScanJob(Base):
|
||||
__tablename__ = "scan_jobs"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
library_id: Mapped[str] = mapped_column(String(36), ForeignKey("libraries.id", ondelete="CASCADE"), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(20), default="queued") # queued/running/done/error
|
||||
progress: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
items_found: Mapped[int] = mapped_column(default=0)
|
||||
started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
log: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
22
backend/app/models/user.py
Normal file
22
backend/app/models/user.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Boolean, DateTime, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.dialects.sqlite import JSON
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
username: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
|
||||
email: Mapped[str] = mapped_column(String(255), nullable=True)
|
||||
password_hash: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
is_admin: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
token: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
settings: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
last_seen: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
Reference in New Issue
Block a user