feat(main): main

This commit is contained in:
2026-03-09 13:29:23 -04:00
parent f14454b4c8
commit b1a93161c0
22 changed files with 719 additions and 192 deletions

View File

@@ -16,6 +16,7 @@ class ChannelSchema(Schema):
scheduling_mode: str
library_id: int
owner_user_id: int
fallback_collection_id: Optional[int] = None
class ChannelCreateSchema(Schema):
name: str
@@ -24,6 +25,7 @@ class ChannelCreateSchema(Schema):
description: Optional[str] = None
library_id: int
owner_user_id: int # Mock Auth User
fallback_collection_id: Optional[int] = None
class ChannelUpdateSchema(Schema):
name: Optional[str] = None
@@ -32,6 +34,7 @@ class ChannelUpdateSchema(Schema):
scheduling_mode: Optional[str] = None
visibility: Optional[str] = None
is_active: Optional[bool] = None
fallback_collection_id: Optional[int] = None
class ChannelSourceRuleSchema(Schema):
id: int
@@ -103,7 +106,11 @@ class AiringSchema(Schema):
@router.get("/", response=List[ChannelSchema])
def list_channels(request):
return Channel.objects.all()
from django.db.models import F
return Channel.objects.order_by(
F('channel_number').asc(nulls_last=True)
)
@router.get("/{channel_id}", response=ChannelSchema)
def get_channel(request, channel_id: int):
@@ -120,7 +127,8 @@ def create_channel(request, payload: ChannelCreateSchema):
name=payload.name,
slug=payload.slug,
channel_number=payload.channel_number,
description=payload.description
description=payload.description,
fallback_collection_id=payload.fallback_collection_id
)
return 201, channel

View File

@@ -1,9 +1,10 @@
from ninja import Router, Schema
from typing import List, Optional
from core.models import Library, AppUser
from core.models import Library, AppUser, MediaCollection
from django.shortcuts import get_object_or_404
router = Router(tags=["library"])
collections_router = Router(tags=["collections"])
class LibrarySchema(Schema):
id: int
@@ -18,6 +19,12 @@ class LibraryCreateSchema(Schema):
visibility: Optional[str] = 'private'
owner_user_id: int # In a real app with auth, this would come from request.user
class MediaCollectionSchema(Schema):
id: int
name: str
library_id: int
collection_type: str
@router.get("/", response=List[LibrarySchema])
def list_libraries(request):
return Library.objects.all()
@@ -36,3 +43,8 @@ def create_library(request, payload: LibraryCreateSchema):
visibility=payload.visibility
)
return 201, library
@collections_router.get("/", response=List[MediaCollectionSchema])
def list_collections(request):
"""List all MediaCollections across all libraries."""
return MediaCollection.objects.select_related('library').all()

View File

@@ -176,3 +176,21 @@ def download_item(request, item_id: int):
except Exception as exc:
from ninja.errors import HttpError
raise HttpError(500, f"Download failed: {exc}")
@router.get("/{item_id}/progress", response=dict)
def download_progress(request, item_id: int):
"""
Return the current download progress string (e.g. '45.1%') from the yt-dlp hook.
"""
from django.core.cache import cache
item = get_object_or_404(MediaItem, id=item_id)
if not item.youtube_video_id:
from ninja.errors import HttpError
raise HttpError(400, "MediaItem is not a YouTube video.")
if item.cached_file_path:
return {"status": "finished", "progress": "100%"}
pct = cache.get(f"yt_progress_{item.youtube_video_id}")
return {"status": "downloading" if pct else "unknown", "progress": pct or "0%"}