diff --git a/CHANGELOG.md b/CHANGELOG.md index cabe2178..eeb9bc85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A few issues related to Playlet backend feeds and caching - An error when Invidious doesn't return valid video metadata +- A bug where playlists with small number of videos has duplicates ## [0.37.0] - 2025-05-16 diff --git a/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs b/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs index c9fbc1f0..6fe63f35 100644 --- a/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs +++ b/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs @@ -54,18 +54,19 @@ function PlaylistContentTask(input as object) as object } end if + beforeChildCount = contentNode.getChildCount() InvidiousContent.ToPlaylistContentNode(contentNode, metadata, instance) - childCount = contentNode.getChildCount() + afterChildCount = contentNode.getChildCount() videoCount = ValidInt(metadata.videoCount) hasContinuation = not StringUtils.IsNullOrEmpty(metadata.continuation) noMoreContinuation = hadContinuation and not hasContinuation - noVideosReturned = metadata.videos.Count() = 0 - reachedVideoCount = videoCount <> -1 and childCount >= videoCount + noVideosAdded = afterChildCount = beforeChildCount + reachedVideoCount = videoCount <> -1 and afterChildCount >= videoCount - if noMoreContinuation or noVideosReturned or reachedVideoCount + if noMoreContinuation or noVideosAdded or reachedVideoCount contentNode.loadState = FeedLoadState.Loaded return { success: true diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs index a9d257d9..03d2a37f 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs @@ -80,19 +80,38 @@ namespace InvidiousContent SetIfExists(node, "statsText", item, "statsText") SetIfExists(node, "lines", item, "lines") - if item.videos <> invalid + if IsArray(item.videos) and item.videos.Count() > 0 childCount = node.getChildCount() + + ' Innertube's TV client doesn't return the index for videos in playlists. + ' So we rely on video ids to detect duplicates. + videosHasIndex = IsInt(item.videos[0].index) + + videoIds = invalid + if not videosHasIndex + videoIds = {} + childVideos = node.getChildren(-1, 0) + for each child in childVideos + videoIds[child.videoId] = true + end for + end if + newNodes = [] for each video in item.videos - ' TODO:P1 sometimes we're parsing "recommended playlists" that - ' show up in the end of the playlist. We should ignore them, - ' until the parsing is fixed. + ' Sometimes we're parsing "recommended playlists" that show up + ' in the end of the playlist. In this context they are ignored. if ValidString(video.type) = "playlist" continue for end if video.type = "video" videoNode = ToVideoContentNode(invalid, video, instance) if videoNode <> invalid + if not videosHasIndex + if videoIds[video.videoId] = true + continue for + end if + end if + index = video.index if index <> invalid and index > -1 and index < childCount node.replaceChild(videoNode, index) @@ -101,6 +120,7 @@ namespace InvidiousContent end if end if end for + if newNodes.Count() > 0 node.appendChildren(newNodes) end if