2025-11-07-codemcp-modify-playlist-import-to-append-and-filter.md 1.9 KB

2025-11-07 CodeMCP: Modify Playlist Import to Append and Filter

User Request

regarding the playlist import functionality, rather than parsing the json content and replacing the in-memory playlist data, I want to: filter out any playlist items that are already marked as "done", add them to the end of the playlists without overriding the items that are already there, and not add any that are already currently in a playlist (that is already the current behaviour for adding an individual video).

Changes Made

Modified validateAndImportPlaylists() in popup/popup.js

  1. Added filtering logic to exclude videos marked as "done":

    if (video.status === "done") {
     return false;
    }
    
  2. Changed the final call from this.updatePlaylists(validPlaylists) to this.appendToPlaylists(validPlaylists)

Replaced updatePlaylists() with appendToPlaylists() in popup/popup.js

Created a new method that:

  1. Creates a copy of current playlists
  2. Iterates through imported playlists and videos
  3. Uses PlaylistUtils.findPlaylist() to check if each video already exists in any playlist
  4. Only adds videos that don't already exist (deduplication)
  5. Appends videos to the end of their respective playlists
  6. Shows user feedback with counts of added and skipped videos

Key implementation details:

  • Uses the existing PlaylistUtils.findPlaylist() utility which checks videos by their YouTube video ID
  • Maintains the same duplicate-checking behavior as adding individual videos
  • Creates new playlists if they don't exist yet
  • Provides informative user feedback: "Import complete! Added X video(s), skipped Y duplicate(s)."

Behavior Summary

The import functionality now:

  1. ✅ Filters out videos marked as "done"
  2. ✅ Appends videos to end of playlists (doesn't replace existing items)
  3. ✅ Skips duplicates using the same logic as adding individual videos
  4. ✅ Provides clear feedback about what was added/skipped