Skip to content

Commit

Permalink
* Update playlist import to only add duplicate playlist items sometimes
Browse files Browse the repository at this point in the history
Either when existing playlist or incoming playlist has duplicate items
  • Loading branch information
PikachuEXE committed Oct 3, 2024
1 parent 26684b4 commit f3c6291
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/renderer/components/data-settings/data-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ export default defineComponent({
// to the app, so we'll only grab the data we need here.

const playlistObject = {}
const videoIdToBeAddedSet = new Set()

Object.keys(playlistData).forEach((key) => {
if ([requiredKeys, optionalKeys, ignoredKeys].every((ks) => !ks.includes(key))) {
Expand All @@ -888,6 +889,7 @@ export default defineComponent({

if (videoObjectHasAllRequiredKeys) {
videoArray.push(video)
videoIdToBeAddedSet.add(video.videoId)
}
})

Expand Down Expand Up @@ -916,20 +918,33 @@ export default defineComponent({
return
}

const duplicateVideoPresentInToBeAdded = playlistObject.videos.length > videoIdToBeAddedSet.size
const existingVideoIdSet = existingPlaylist.videos.reduce((video) => videoIdToBeAddedSet.add(video.videoId), new Set())
const duplicateVideoPresentInExistingPlaylist = existingPlaylist.videos.length > existingVideoIdSet.size
const shouldAddDuplicateVideos = duplicateVideoPresentInToBeAdded || duplicateVideoPresentInExistingPlaylist

playlistObject.videos.forEach((video) => {
let videoExists = false
if (video.playlistItemId != null) {
// Find by `playlistItemId` if present
videoExists = existingPlaylist.videos.some((x) => {
// Allow duplicate (by videoId) videos to be added
return x.videoId === video.videoId && x.playlistItemId === video.playlistItemId
})
if (shouldAddDuplicateVideos) {
if (video.playlistItemId != null) {
// Find by `playlistItemId` if present
videoExists = existingPlaylist.videos.some((x) => {
// Allow duplicate (by videoId) videos to be added
return x.videoId === video.videoId && x.playlistItemId === video.playlistItemId
})
} else {
// Older playlist exports have no `playlistItemId` but have `timeAdded`
// Which might be duplicate for copied playlists with duplicate `videoId`
videoExists = existingPlaylist.videos.some((x) => {
// Allow duplicate (by videoId) videos to be added
return x.videoId === video.videoId && x.timeAdded === video.timeAdded
})
}
} else {
// Older playlist exports have no `playlistItemId` but have `timeAdded`
// Which might be duplicate for copied playlists with duplicate `videoId`
// Find by `playlistItemId` if present
videoExists = existingPlaylist.videos.some((x) => {
// Allow duplicate (by videoId) videos to be added
return x.videoId === video.videoId && x.timeAdded === video.timeAdded
return x.videoId === video.videoId
})
}

Expand Down

0 comments on commit f3c6291

Please sign in to comment.