Fix a bug where playlists with small number of videos has duplicates
This commit is contained in:
1 parent
30ea007502
commit
7c1aa80819
3 files changed
+30
-8
No files matched your search
@@ -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
|
- A few issues related to Playlet backend feeds and caching
|
||||||
- An error when Invidious doesn't return valid video metadata
|
- 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
|
## [0.37.0] - 2025-05-16
|
||||||
|
|
||||||
|
|||||||
@@ -54,18 +54,19 @@ function PlaylistContentTask(input as object) as object
|
|||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
beforeChildCount = contentNode.getChildCount()
|
||||||
InvidiousContent.ToPlaylistContentNode(contentNode, metadata, instance)
|
InvidiousContent.ToPlaylistContentNode(contentNode, metadata, instance)
|
||||||
childCount = contentNode.getChildCount()
|
afterChildCount = contentNode.getChildCount()
|
||||||
|
|
||||||
videoCount = ValidInt(metadata.videoCount)
|
videoCount = ValidInt(metadata.videoCount)
|
||||||
|
|
||||||
hasContinuation = not StringUtils.IsNullOrEmpty(metadata.continuation)
|
hasContinuation = not StringUtils.IsNullOrEmpty(metadata.continuation)
|
||||||
|
|
||||||
noMoreContinuation = hadContinuation and not hasContinuation
|
noMoreContinuation = hadContinuation and not hasContinuation
|
||||||
noVideosReturned = metadata.videos.Count() = 0
|
noVideosAdded = afterChildCount = beforeChildCount
|
||||||
reachedVideoCount = videoCount <> -1 and childCount >= videoCount
|
reachedVideoCount = videoCount <> -1 and afterChildCount >= videoCount
|
||||||
|
|
||||||
if noMoreContinuation or noVideosReturned or reachedVideoCount
|
if noMoreContinuation or noVideosAdded or reachedVideoCount
|
||||||
contentNode.loadState = FeedLoadState.Loaded
|
contentNode.loadState = FeedLoadState.Loaded
|
||||||
return {
|
return {
|
||||||
success: true
|
success: true
|
||||||
|
|||||||
@@ -80,19 +80,38 @@ namespace InvidiousContent
|
|||||||
SetIfExists(node, "statsText", item, "statsText")
|
SetIfExists(node, "statsText", item, "statsText")
|
||||||
SetIfExists(node, "lines", item, "lines")
|
SetIfExists(node, "lines", item, "lines")
|
||||||
|
|
||||||
if item.videos <> invalid
|
if IsArray(item.videos) and item.videos.Count() > 0
|
||||||
childCount = node.getChildCount()
|
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 = []
|
newNodes = []
|
||||||
for each video in item.videos
|
for each video in item.videos
|
||||||
' TODO:P1 sometimes we're parsing "recommended playlists" that
|
' Sometimes we're parsing "recommended playlists" that show up
|
||||||
' show up in the end of the playlist. We should ignore them,
|
' in the end of the playlist. In this context they are ignored.
|
||||||
' until the parsing is fixed.
|
|
||||||
if ValidString(video.type) = "playlist"
|
if ValidString(video.type) = "playlist"
|
||||||
continue for
|
continue for
|
||||||
end if
|
end if
|
||||||
video.type = "video"
|
video.type = "video"
|
||||||
videoNode = ToVideoContentNode(invalid, video, instance)
|
videoNode = ToVideoContentNode(invalid, video, instance)
|
||||||
if videoNode <> invalid
|
if videoNode <> invalid
|
||||||
|
if not videosHasIndex
|
||||||
|
if videoIds[video.videoId] = true
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
index = video.index
|
index = video.index
|
||||||
if index <> invalid and index > -1 and index < childCount
|
if index <> invalid and index > -1 and index < childCount
|
||||||
node.replaceChild(videoNode, index)
|
node.replaceChild(videoNode, index)
|
||||||
@@ -101,6 +120,7 @@ namespace InvidiousContent
|
|||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
end for
|
end for
|
||||||
|
|
||||||
if newNodes.Count() > 0
|
if newNodes.Count() > 0
|
||||||
node.appendChildren(newNodes)
|
node.appendChildren(newNodes)
|
||||||
end if
|
end if
|
||||||
|
|||||||
Reference in new issue
Block a user