Skip to content

fix: remove a deleted video's leftover entry from a playlist - #24

Merged
eukosh merged 3 commits into
mainfrom
fix/playlist-remove-deleted-video
Oct 25, 2026
Merged

eukosh merged 3 commits into
mainfrom
fix/playlist-remove-deleted-video

Conversation

@eukosh

@eukosh eukosh commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Once a video is deleted, YouTube rejects playlistItems.list(videoId=…) with 404 videoNotFound, but the playlist keeps a "Deleted video" entry with that ID. ytk playlist remove used that filter, so it couldn't remove the leftover entry.

 remove_from_playlist(playlist, video)
   _occurrences(playlist, video, deleted_video=True)
     list(videoId=video)
+    on videoNotFound:
+      read the whole playlist (part=contentDetails, up to 5,000 entries)
+      past 5,000 entries: error instead of a partial search
+      keep entries whose contentDetails.videoId == video
   delete each entry

move_in_playlist uses the same lookup without the fallback, so a deleted video still fails at once with not_found and doesn't spend quota reading the playlist. Any other error, such as playlistNotFound, raises as before. YouTube answers videoNotFound for unknown IDs too, so a mistyped ID also reads the playlist and removes nothing. The help and MCP description of remove say so, and that it costs 1 more unit per 50 entries.

Evidence

  • Before: found while recording the ytk video. Removing deleted video 7A22uuMVA6w from a playlist failed with {"error": {"type": "not_found", "message": "Video not found."}}, while ytk playlist items still listed it as "Deleted video". I checked the API live: the videoId filter returns 404 videoNotFound for deleted IDs and for IDs that never existed alike. The new test failed with NotFound: Video not found.
    After: test_remove_from_playlist_finds_a_deleted_video_by_reading_the_playlist passes: it removes both entries across two pages, skips an entry with no video ID, and pins each page's request (no videoId filter). New tests also cover a video in no entry (removes 0), a scan that hits the cap (error, nothing deleted), other 404s (no scan) and move (no scan). uv run pytest: 421 passed, 2 live skipped. ruff check and ruff format --check are clean. Two Fable 5.1 (high) review rounds; their points are applied.

Merge Danger

Door: two-way

Blast Radius: small

It only changes playlist remove when YouTube answers videoNotFound, which used to be an error. On a long playlist that path reads up to 100 pages (100 units).

🤖 Generated with Claude Code

eukosh and others added 3 commits October 25, 2026 18:18
YouTube rejects the playlistItems videoId filter with videoNotFound once a
video is deleted, though the playlist keeps its entry. Removing then falls
back to reading the whole playlist. Moving still fails fast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reading the playlist now stops with an error at YouTube's 5,000-entry cap
instead of reporting nothing removed, requests contentDetails rather than the
larger snippet, and the help names unknown IDs as costing the same scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eukosh
eukosh merged commit 8fad97a into main Oct 25, 2026
7 checks passed
@eukosh
eukosh deleted the fix/playlist-remove-deleted-video branch October 25, 2026 19:07
eukosh pushed a commit that referenced this pull request Oct 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.7.3](v0.7.2...v0.7.3)
(2026-10-25)


### Fixed

* remove a deleted video's leftover entry from a playlist
([#24](#24))
([8fad97a](8fad97a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant