121 lines
4.7 KiB
Plaintext
121 lines
4.7 KiB
Plaintext
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
|
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
|
import "pkg:/components/Services/LoungeService/LoungeConstants.bs"
|
|
import "pkg:/components/VideoQueue/Notifications/VideoQueueNotificationUtils.bs"
|
|
|
|
namespace LoungeVideoQueue
|
|
function SetPlaylist(videoQueueNode as object, invService as object, playlistData as object)
|
|
HandleLoungePlaylist(videoQueueNode, invService, playlistData)
|
|
end function
|
|
|
|
function UpdatePlaylist(videoQueueNode as object, invService as object, playlistData as object)
|
|
HandleLoungePlaylist(videoQueueNode, invService, playlistData)
|
|
end function
|
|
|
|
function HandleLoungePlaylist(videoQueueNode as object, invService as object, playlistData as object) as void
|
|
videoIds = playlistData[FIELD_VIDEO_IDS]
|
|
if StringUtils.IsNullOrEmpty(videoIds)
|
|
videoQueueNode.clearQueue = true
|
|
return
|
|
end if
|
|
|
|
videoIds = videoIds.Split(",")
|
|
queueContent = videoQueueNode.content
|
|
currentQueueNodes = queueContent.getChildren(-1, 0)
|
|
queueNodesDict = {}
|
|
for each node in currentQueueNodes
|
|
queueNodesDict[node.id] = node
|
|
end for
|
|
|
|
instance = invalid
|
|
newQueueNodes = []
|
|
for each vId in videoIds
|
|
if queueNodesDict.DoesExist(vId)
|
|
newQueueNodes.Push(queueNodesDict[vId])
|
|
else
|
|
payload = {
|
|
"type": "video"
|
|
"videoId": vId
|
|
}
|
|
|
|
if instance = invalid
|
|
instance = invService.GetInstance()
|
|
end if
|
|
|
|
contentNode = InvidiousContent.ToVideoContentNode(invalid, payload, instance)
|
|
newQueueNodes.Push(contentNode)
|
|
end if
|
|
end for
|
|
|
|
index = -1
|
|
currentIndex = playlistData[FIELD_CURRENT_INDEX]
|
|
if IsString(currentIndex)
|
|
currentIndex = CInt(Val(currentIndex))
|
|
index = currentIndex
|
|
else
|
|
index = videoQueueNode.index
|
|
end if
|
|
|
|
videoQueueNode.setQueueAndIndex = {
|
|
videoNodes: newQueueNodes
|
|
index: index
|
|
}
|
|
|
|
videoId = playlistData[FIELD_VIDEO_ID]
|
|
timestamp = playlistData[FIELD_CURRENT_TIME]
|
|
|
|
if not StringUtils.IsNullOrEmpty(videoId)
|
|
if not StringUtils.IsNullOrEmpty(timestamp)
|
|
timestamp = CInt(Val(timestamp))
|
|
if timestamp > 0
|
|
node = newQueueNodes[index]
|
|
node.timestamp = timestamp
|
|
end if
|
|
end if
|
|
|
|
videoQueueNode.play = true
|
|
end if
|
|
|
|
if StringUtils.IsNullOrEmpty(videoId)
|
|
' TODO:P1 - Handle the case where a video is removed from the queue
|
|
' with an index lower than the current index. In this case, the
|
|
' video queue index is not updated, and we end up highlighting the wrong
|
|
' video in the queue (the next video in the queue is highlighted instead of
|
|
' the video that was previously highlighted). This also leads to skipping
|
|
' a video that's supposed to play next.
|
|
' When a video is removed from the queue:
|
|
' - There's no videoId
|
|
' - There's no currentIndex
|
|
' - eventDetails is of the form {"eventType":"VIDEO_REMOVED","videoId":"<videoId>"}
|
|
eventDetails = playlistData[FIELD_EVENT_DETAILS]
|
|
if IsString(eventDetails)
|
|
eventDetails = ParseJson(eventDetails)
|
|
end if
|
|
if eventDetails <> invalid and eventDetails["eventType"] = "VIDEO_ADDED"
|
|
eventVideoId = eventDetails[FIELD_VIDEO_ID]
|
|
if not StringUtils.IsNullOrEmpty(eventVideoId)
|
|
preferences = videoQueueNode.preferences
|
|
queueNotifications = preferences["misc.queue_notifications"]
|
|
if queueNotifications
|
|
payload = {
|
|
"type": "video"
|
|
"videoId": eventVideoId
|
|
}
|
|
|
|
if instance = invalid
|
|
instance = invService.GetInstance()
|
|
end if
|
|
|
|
node = InvidiousContent.ToVideoContentNode(invalid, payload, instance)
|
|
|
|
notifications = videoQueueNode.notifications
|
|
hintVisible = videoQueueNode.player = invalid or not videoQueueNode.videoContainer.fullscreen
|
|
VideoQueue.ShowNotifcation(notifications, node, hintVisible)
|
|
end if
|
|
end if
|
|
end if
|
|
end if
|
|
end function
|
|
|
|
end namespace
|