|
|
@@ -898,7 +898,7 @@ document.addEventListener("alpine:init", () => {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // Validate each video in the playlist
|
|
|
+ // Validate each video in the playlist and filter out done videos
|
|
|
const validVideos = videos.filter((video) => {
|
|
|
if (!video || typeof video !== "object") {
|
|
|
console.error(`Invalid video object in '${playlistName}'`);
|
|
|
@@ -917,6 +917,10 @@ document.addEventListener("alpine:init", () => {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if (video.status === "done") {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
});
|
|
|
|
|
|
@@ -939,18 +943,40 @@ document.addEventListener("alpine:init", () => {
|
|
|
}
|
|
|
|
|
|
// Update storage and state
|
|
|
- this.updatePlaylists(validPlaylists);
|
|
|
+ this.appendToPlaylists(validPlaylists);
|
|
|
},
|
|
|
|
|
|
- async updatePlaylists(playlists) {
|
|
|
+ async appendToPlaylists(importedPlaylists) {
|
|
|
try {
|
|
|
- await browser.storage.local.set({ playlists });
|
|
|
- this.playlists = playlists;
|
|
|
+ const currentPlaylists = JSON.parse(JSON.stringify(this.playlists));
|
|
|
+ let addedCount = 0;
|
|
|
+ let skippedCount = 0;
|
|
|
+
|
|
|
+ for (const [playlistName, importedVideos] of Object.entries(importedPlaylists)) {
|
|
|
+ if (!currentPlaylists[playlistName]) {
|
|
|
+ currentPlaylists[playlistName] = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const video of importedVideos) {
|
|
|
+ const alreadyExists = PlaylistUtils.findPlaylist(currentPlaylists, video.url);
|
|
|
+
|
|
|
+ if (!alreadyExists) {
|
|
|
+ currentPlaylists[playlistName].push(video);
|
|
|
+ addedCount++;
|
|
|
+ } else {
|
|
|
+ skippedCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await browser.storage.local.set({ playlists: currentPlaylists });
|
|
|
+ this.playlists = currentPlaylists;
|
|
|
this.updatePlaylistsForDisplay();
|
|
|
this.updateCurrentPlaylistVideos();
|
|
|
- alert("Playlists imported successfully!");
|
|
|
+
|
|
|
+ alert(`Import complete! Added ${addedCount} video(s), skipped ${skippedCount} duplicate(s).`);
|
|
|
} catch (error) {
|
|
|
- console.error("Error updating playlists:", error);
|
|
|
+ console.error("Error appending playlists:", error);
|
|
|
alert("Error importing playlists: " + error.message);
|
|
|
}
|
|
|
},
|