Fix: replace search.list with uploads playlist to reliably find recent videos#6
Merged
Merged
Conversation
…t videos search.list is unreliable for channel upload discovery — it can silently omit recently-uploaded videos and YouTube Shorts due to indexing delays, and it costs 100 quota units per call. The correct approach is to use the channel's uploads playlist via playlistItems.list (1 quota unit), which reflects new uploads immediately and includes all video types (Shorts, regular uploads, premieres). The uploads playlist ID is derived from the channel ID by replacing the 'UC' prefix with 'UU' — a stable YouTube channel ID convention. Changes: - utils/youtube_api.py: Replace search().list() call in search_recent with playlistItems().list() using the derived uploads playlist ID. Filter results client-side by published_after (playlist is newest- first so we can break early). Also validates that channel_id starts with 'UC'. - tests/test_youtube_api.py: Rewrite fake service infrastructure for playlistItems API shape. Add tests for UC channel ID validation and the early-stop date filtering behaviour. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…hack The UC->UU channel ID prefix swap is not universally reliable — GitHub's channel (UC7c3Kb6jYCRj4JOHHZTxKsA) does not expose a UU-prefixed uploads playlist, causing a 404 from the playlistItems API. The correct approach is to call channels.list with part=contentDetails and read contentDetails.relatedPlaylists.uploads. The result is cached on the YouTubeClient instance to avoid a redundant API call on each run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates YouTube video discovery to use the channel uploads playlist instead of search.list, aiming to make recent video digests more reliable and quota-efficient.
Changes:
- Adds uploads playlist resolution via
channels.listand usesplaylistItems.listfor recent videos. - Updates YouTube API tests and cog flow test fixtures for the new API shape.
- Updates config/setup examples for the YouTube channel ID.
Show a summary per file
| File | Description |
|---|---|
utils/youtube_api.py |
Replaces YouTube search API usage with uploads playlist retrieval and client-side publish-date filtering. |
tests/test_youtube_api.py |
Updates fake YouTube service helpers and tests for playlist-based discovery. |
tests/test_cog_flows.py |
Updates the YouTube channel ID used by the cog flow test fixture. |
SETUP.md |
Updates setup documentation channel ID examples. |
config/config.yaml |
Updates the configured GitHub YouTube channel ID. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
SETUP.md:154
- This example channel ID also uses the new
...KsQvalue, which conflicts with the...KsAchannel ID referenced in the PR description. The note is meant to help users identify the correct YouTube ID format, so carrying the inconsistent value here can reinforce the wrong configuration.
> **Note:** YouTube channel IDs look like `UC7c3Kb6jYCRj4JOHHZTxKsQ`.
utils/youtube_api.py:127
- The PR description says
search_recentadds UC-prefix validation, but this path still sends anychannel_iddirectly tochannels.list. If a user configures an uploads playlist ID (UU...) or a handle by mistake, the code spends an API call and reports only "channel not found" instead of the intended validation error.
uploads_playlist_id = self._get_uploads_playlist_id(channel_id)
- Files reviewed: 5/5 changed files
- Comments generated: 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
/youtubedigestcommand (and the weekly background task) returned no videos even when videos existed on the channel. The root cause was usingsearch.listto discover channel uploads:search.listhas unpredictable indexing delays that can silently omit videos uploaded in the past few daysFix
Replace
search.listwith the channel's uploads playlist (playlistItems.list):The uploads playlist ID is derived from the channel ID by replacing the
UCprefix withUU— a stable YouTube channel ID convention (UC7c3Kb6jYCRj4JOHHZTxKsA→UU7c3Kb6jYCRj4JOHHZTxKsA).The playlist is ordered newest-first, so we can break early once we hit a video older than the 7-day window.
Changes
utils/youtube_api.py: Replacesearch().list()withplaylistItems().list()insearch_recent. AddUC-prefix validation for channel IDs. Filter byvideoPublishedAtclient-side.tests/test_youtube_api.py: Full rewrite of fake service infrastructure for the new API shape. New tests for UC channel ID validation and date-window early-stop behaviour. 20 tests total, all pass.Testing