feat(main): main

This commit is contained in:
2026-03-09 08:26:45 -04:00
parent f37382d2b8
commit f14454b4c8
12 changed files with 598 additions and 62 deletions

View File

@@ -39,11 +39,13 @@ class ChannelSourceRuleSchema(Schema):
source_name: str
rule_mode: str
weight: float
schedule_block_label: Optional[str] = None
class ChannelSourceAssignSchema(Schema):
source_id: int
rule_mode: str = 'allow' # allow | prefer | avoid | block
weight: float = 1.0
schedule_block_label: Optional[str] = None
class AiringSchema(Schema):
id: int
@@ -58,7 +60,21 @@ class AiringSchema(Schema):
def from_airing(airing) -> 'AiringSchema':
media_path = None
if airing.media_item:
raw_path = airing.media_item.cached_file_path or airing.media_item.file_path
item = airing.media_item
# 1. Determine if this item is from a YouTube source
is_youtube = False
if item.media_source and item.media_source.source_type in ['youtube', 'youtube_channel', 'youtube_playlist']:
is_youtube = True
# 2. Strict signaling: If YouTube, we MUST have it downloaded
if is_youtube:
raw_path = item.cached_file_path
# If cached_file_path is None, raw_path is None, and media_path remains None
else:
# Fallback for generic local files/links
raw_path = item.cached_file_path or item.file_path
if raw_path:
if raw_path.startswith("http://") or raw_path.startswith("https://"):
media_path = raw_path
@@ -133,6 +149,7 @@ def list_channel_sources(request, channel_id: int):
source_name=r.media_source.name,
rule_mode=r.rule_mode,
weight=float(r.weight),
schedule_block_label=r.schedule_block_label,
)
for r in rules
]
@@ -146,6 +163,7 @@ def assign_source_to_channel(request, channel_id: int, payload: ChannelSourceAss
media_source=source,
rule_mode=payload.rule_mode,
weight=payload.weight,
schedule_block_label=payload.schedule_block_label,
)
return 201, ChannelSourceRuleSchema(
id=rule.id,
@@ -153,6 +171,7 @@ def assign_source_to_channel(request, channel_id: int, payload: ChannelSourceAss
source_name=source.name,
rule_mode=rule.rule_mode,
weight=float(rule.weight),
schedule_block_label=rule.schedule_block_label,
)
@router.delete("/{channel_id}/sources/{rule_id}", response={204: None})