Skip to content

Commit 11b4fe6

Browse files
committed
Fix is with Youtube summary
1 parent 84e6cf2 commit 11b4fe6

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

routes/queue.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ def play_next_in_queue():
125125
# Add type-specific fields
126126
if next_item.type == "summary":
127127
response["week_year"] = next_item.week_year
128+
logger.info(
129+
f"Playing next item (summary): {next_item.title} - week_year: {next_item.week_year}"
130+
)
128131
else:
129132
response["youtube_id"] = next_item.youtube_id
133+
logger.info(
134+
f"Playing next item (youtube): {next_item.title} - video_id: {next_item.youtube_id}"
135+
)
130136

131137
return JSONResponse(response)
132138
except Exception as e:

routes/stream.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ def stream_video(request: StreamRequest):
110110

111111
logger.info(f"🎬 /stream requested for video: {video_id}")
112112

113+
# Validate video ID
114+
if not video_id or video_id.strip() == "":
115+
logger.error("Received empty video_id in /stream request")
116+
raise HTTPException(
117+
status_code=400,
118+
detail="Invalid request: video_id is required and cannot be empty",
119+
)
120+
113121
# Fetch video metadata and save to database
114122
try:
115123
metadata = get_video_metadata(video_id)

services/database.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,16 @@ def get_queue() -> List[QueueItem]:
370370
""")
371371

372372
rows = cursor.fetchall()
373-
return [QueueItem.from_db_row(row) for row in rows]
373+
items = [QueueItem.from_db_row(row) for row in rows]
374+
375+
# Log queue items for debugging
376+
for item in items:
377+
logger.debug(
378+
f"Queue item #{item.id}: type={item.type}, "
379+
f"week_year={item.week_year}, title={item.title}"
380+
)
381+
382+
return items
374383

375384

376385
def get_next_in_queue() -> Optional[QueueItem]:
@@ -630,7 +639,8 @@ def add_summary_to_queue(week_year: str) -> int:
630639

631640
record_id = cursor.lastrowid
632641
logger.info(
633-
f"Added summary to queue (position {next_position}): {summary.title}"
642+
f"Added summary to queue (position {next_position}): {summary.title} "
643+
f"[type=summary, week_year={week_year}]"
634644
)
635645
return record_id
636646

services/models.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class QueueItem:
6262
@classmethod
6363
def from_db_row(cls, row) -> "QueueItem":
6464
"""Create instance from database row."""
65+
# Get type from row, defaulting to 'youtube' only if None
66+
# This preserves explicit 'summary' types while handling backward compatibility
67+
item_type = row["type"] if row["type"] is not None else "youtube"
68+
6569
return cls(
6670
id=row["id"],
6771
youtube_id=row["youtube_id"],
@@ -70,7 +74,7 @@ def from_db_row(cls, row) -> "QueueItem":
7074
thumbnail_url=row["thumbnail_url"],
7175
position=row["position"],
7276
created_at=row["created_at"],
73-
type=row["type"] or "youtube",
77+
type=item_type,
7478
week_year=row["week_year"],
7579
)
7680

@@ -86,7 +90,9 @@ def to_dict(self) -> dict:
8690
"created_at": self.created_at,
8791
"type": self.type,
8892
}
89-
if self.week_year:
93+
# Always include week_year for summary items (even if None)
94+
# This ensures the frontend can properly identify summary types
95+
if self.type == "summary":
9096
result["week_year"] = self.week_year
9197
return result
9298

0 commit comments

Comments
 (0)