86 lines
2.6 KiB
Plaintext
86 lines
2.6 KiB
Plaintext
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
|
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
|
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
|
|
|
@asynctask
|
|
function PlaylistContentTask(input as object) as object
|
|
contentNode = input.content
|
|
invidiousNode = input.invidious
|
|
singlePage = input.singlePage
|
|
|
|
if m.top.cancel
|
|
contentNode.loadState = FeedLoadState.None
|
|
return invalid
|
|
end if
|
|
|
|
service = new Invidious.InvidiousService(invidiousNode)
|
|
instance = service.GetInstance()
|
|
|
|
while true
|
|
playlistId = contentNode.playlistId
|
|
index = contentNode.getChildCount()
|
|
continuation = contentNode.continuation
|
|
hadContinuation = not StringUtils.IsNullOrEmpty(continuation)
|
|
|
|
if playlistId.StartsWith("RD") and not hadContinuation
|
|
videoId = contentNode.videoId
|
|
if not StringUtils.IsNullOrEmpty(videoId)
|
|
continuation = videoId
|
|
end if
|
|
end if
|
|
|
|
response = service.GetPlaylist(playlistId, index, continuation, m.top.cancellation)
|
|
|
|
if m.top.cancel
|
|
contentNode.loadState = FeedLoadState.None
|
|
return invalid
|
|
end if
|
|
|
|
metadata = response.Json()
|
|
|
|
if not response.IsSuccess() or metadata = invalid
|
|
contentNode.loadState = FeedLoadState.Error
|
|
return {
|
|
success: false
|
|
error: response.ErrorMessage()
|
|
}
|
|
end if
|
|
|
|
if metadata.DoesExist("error")
|
|
contentNode.loadState = FeedLoadState.Error
|
|
return {
|
|
success: false
|
|
error: metadata.error
|
|
}
|
|
end if
|
|
|
|
beforeChildCount = contentNode.getChildCount()
|
|
InvidiousContent.ToPlaylistContentNode(contentNode, metadata, instance)
|
|
afterChildCount = contentNode.getChildCount()
|
|
|
|
videoCount = ValidInt(metadata.videoCount)
|
|
|
|
hasContinuation = not StringUtils.IsNullOrEmpty(metadata.continuation)
|
|
|
|
noMoreContinuation = hadContinuation and not hasContinuation
|
|
noVideosAdded = afterChildCount = beforeChildCount
|
|
reachedVideoCount = videoCount <> -1 and afterChildCount >= videoCount
|
|
|
|
if noMoreContinuation or noVideosAdded or reachedVideoCount
|
|
contentNode.loadState = FeedLoadState.Loaded
|
|
return {
|
|
success: true
|
|
}
|
|
else
|
|
contentNode.loadState = FeedLoadState.LoadedPage
|
|
if singlePage
|
|
return {
|
|
success: true
|
|
}
|
|
end if
|
|
end if
|
|
end while
|
|
|
|
return invalid
|
|
end function
|