Skip to content

Commit

Permalink
Video queue view
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Oct 4, 2024
1 parent 042d48c commit ec073e2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions playlet-lib/src/components/VideoQueue/VideoQueueView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function LoadVideoDetailsIfNeeded() as void
m.loadDetailsTask = AsyncTask.Start(Tasks.VideoQueueViewContentTask, {
videoNodes: m.videosDetailsToLoad
invidious: m.top.invidious
preferences: m.top.preferences
index: indexInLoadingArray
})
end function
Expand Down
1 change: 1 addition & 0 deletions playlet-lib/src/components/VideoQueue/VideoQueueView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<field id="videoQueue" type="node" />
<field id="appController" type="node" />
<field id="invidious" type="node" />
<field id="preferences" type="node" />
<function name="Show" />
</interface>

Expand Down
18 changes: 14 additions & 4 deletions playlet-lib/src/components/VideoQueue/VideoQueueViewContentTask.bs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "pkg:/components/Services/Innertube/InnertubeService.bs"
import "pkg:/components/Services/Invidious/InvidiousService.bs"
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
import "pkg:/source/services/HttpClient.bs"
Expand All @@ -7,12 +8,15 @@ import "pkg:/source/utils/MathUtils.bs"
function VideoQueueViewContentTask(input as object) as object
videoNodes = input.videoNodes
invidiousNode = input.invidious
preferencesNode = input.preferences
service = new Invidious.InvidiousService(invidiousNode)
instance = service.GetInstance()
cancellation = m.top.cancellation

index = MathUtils.Clamp(input.index - 2, 0, videoNodes.Count() - 1)

backend = preferencesNode["playback.backend"]

requestOptions = {
cacheSeconds: 8640000 ' 100 days
cancellation: cancellation
Expand All @@ -24,7 +28,7 @@ function VideoQueueViewContentTask(input as object) as object
' Need to change it to load on demand using render tracking
for i = index to videoNodes.Count() - 1
videoNode = videoNodes[i]
if not LoadVideoDetail(videoNode, service, instance, requestOptions)
if not LoadVideoDetail(videoNode, service, instance, requestOptions, backend)
' Sleep for a bit to avoid creating too much traffic
sleep(500)
end if
Expand All @@ -36,7 +40,7 @@ function VideoQueueViewContentTask(input as object) as object

for i = index - 1 to 0 step -1
videoNode = videoNodes[i]
if not LoadVideoDetail(videoNode, service, instance, requestOptions)
if not LoadVideoDetail(videoNode, service, instance, requestOptions, backend)
' Sleep for a bit to avoid creating too much traffic
sleep(1000)
end if
Expand All @@ -50,9 +54,15 @@ function VideoQueueViewContentTask(input as object) as object
end function

' Returns true if the video was loaded from cache.
function LoadVideoDetail(videoNode as object, service as object, instance as string, requestOptions as object) as boolean
function LoadVideoDetail(videoNode as object, service as object, instance as string, requestOptions as object, backend as string) as boolean
videoId = videoNode.videoId
response = service.GetVideoMetadata(videoId, requestOptions)

if backend = "playlet"
response = InnertubeService.GetVideoMetadata(videoId, requestOptions)
else
response = service.GetVideoMetadata(videoId, requestOptions)
end if

metadata = response.Json()

if not response.IsSuccess() or metadata = invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace VideoQueueViewUtils
videoQueueView.videoQueue = videoQueue
videoQueueView.appController = appController
videoQueueView.invidious = videoQueue.invidious
videoQueueView.preferences = videoQueue.preferences
appController@.PushScreen(videoQueueView)

content = videoQueue.content
Expand Down

0 comments on commit ec073e2

Please sign in to comment.