Playlist job system (#659)
This commit is contained in:
1 parent
a10f3df298
commit
b1e64427dd
12 files changed
+66
-74
No files matched your search
@@ -16,11 +16,11 @@ function ExecuteJob() as void
|
||||
return
|
||||
end if
|
||||
|
||||
cancallation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
cancellation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
isInnertubeProfile = authToken.profileNode.type = "youtube"
|
||||
if isInnertubeProfile
|
||||
subscriptionStatus = InnertubeService.GetSubscriptionStatusForChannel(ucid, {
|
||||
cancellation: cancallation
|
||||
cancellation: cancellation
|
||||
accessToken: authToken.token
|
||||
onBehalfOfUser: authToken.activeIdentifyToken
|
||||
})
|
||||
@@ -32,7 +32,7 @@ function ExecuteJob() as void
|
||||
channelView.isSubscribed = subscriptionStatus.isSubscribed
|
||||
else
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
subscriptionsRequest = service.GetSubscriptions(cancallation)
|
||||
subscriptionsRequest = service.GetSubscriptions(cancellation)
|
||||
if not subscriptionsRequest.IsSuccess()
|
||||
JobError("Failed to fetch subscriptions: " + subscriptionsRequest.ErrorMessage())
|
||||
return
|
||||
|
||||
@@ -14,13 +14,13 @@ function ExecuteJob() as void
|
||||
return
|
||||
end if
|
||||
|
||||
cancallation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
cancellation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
|
||||
if subscribe
|
||||
response = service.Subscribe(ucid, cancallation)
|
||||
response = service.Subscribe(ucid, cancellation)
|
||||
else
|
||||
response = service.Unsubscribe(ucid, cancallation)
|
||||
response = service.Unsubscribe(ucid, cancellation)
|
||||
end if
|
||||
|
||||
if not response.IsSuccess()
|
||||
|
||||
@@ -14,8 +14,8 @@ function ExecuteJob() as void
|
||||
end if
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
cancallation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
response = service.GetChannel(contentNode.authorId, cancallation)
|
||||
cancellation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
response = service.GetChannel(contentNode.authorId, cancellation)
|
||||
|
||||
if JobIsCancelled()
|
||||
contentNode.loadState = FeedLoadState.None
|
||||
|
||||
+17
-23
@@ -2,19 +2,22 @@ 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
|
||||
@job("PlaylistContentJob")
|
||||
function ExecuteJob() as void
|
||||
input = JobGetInput()
|
||||
contentNode = input.content
|
||||
invidiousNode = input.invidious
|
||||
singlePage = input.singlePage
|
||||
|
||||
if m.top.cancel
|
||||
if JobIsCancelled()
|
||||
contentNode.loadState = FeedLoadState.None
|
||||
return invalid
|
||||
JobCancel()
|
||||
return
|
||||
end if
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
instance = service.GetInstance()
|
||||
cancellation = CancellationUtils.CreateCancellation(JobGetCallbackNode(), "cancel", true)
|
||||
|
||||
while true
|
||||
playlistId = contentNode.playlistId
|
||||
@@ -29,29 +32,26 @@ function PlaylistContentTask(input as object) as object
|
||||
end if
|
||||
end if
|
||||
|
||||
response = service.GetPlaylist(playlistId, index, continuation, m.top.cancellation)
|
||||
response = service.GetPlaylist(playlistId, index, continuation, cancellation)
|
||||
|
||||
if m.top.cancel
|
||||
if JobIsCancelled()
|
||||
contentNode.loadState = FeedLoadState.None
|
||||
return invalid
|
||||
JobCancel()
|
||||
return
|
||||
end if
|
||||
|
||||
metadata = response.Json()
|
||||
|
||||
if not response.IsSuccess() or metadata = invalid
|
||||
contentNode.loadState = FeedLoadState.Error
|
||||
return {
|
||||
success: false
|
||||
error: response.ErrorMessage()
|
||||
}
|
||||
JobError(response.ErrorMessage())
|
||||
return
|
||||
end if
|
||||
|
||||
if metadata.DoesExist("error")
|
||||
contentNode.loadState = FeedLoadState.Error
|
||||
return {
|
||||
success: false
|
||||
error: metadata.error
|
||||
}
|
||||
JobError(metadata.error)
|
||||
return
|
||||
end if
|
||||
|
||||
beforeChildCount = contentNode.getChildCount()
|
||||
@@ -68,18 +68,12 @@ function PlaylistContentTask(input as object) as object
|
||||
|
||||
if noMoreContinuation or noVideosAdded or reachedVideoCount
|
||||
contentNode.loadState = FeedLoadState.Loaded
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
return
|
||||
else
|
||||
contentNode.loadState = FeedLoadState.LoadedPage
|
||||
if singlePage
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
return
|
||||
end if
|
||||
end if
|
||||
end while
|
||||
|
||||
return invalid
|
||||
end function
|
||||
@@ -1,63 +1,58 @@
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/components/JobSystem/Jobs.bs"
|
||||
import "pkg:/components/JobSystem/JobSystem.bs"
|
||||
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/source/utils/Locale.bs"
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
|
||||
function LoadPlaylistPage(invidiousNode as object) as void
|
||||
LoadPlaylist(invidiousNode, true)
|
||||
function LoadPlaylistPage(invidiousNode as object, jobQueue as object) as void
|
||||
LoadPlaylist(invidiousNode, jobQueue, true)
|
||||
end function
|
||||
|
||||
function LoadPlaylistAll(invidiousNode as object) as void
|
||||
LoadPlaylist(invidiousNode, false)
|
||||
function LoadPlaylistAll(invidiousNode as object, jobQueue as object) as void
|
||||
LoadPlaylist(invidiousNode, jobQueue, false)
|
||||
end function
|
||||
|
||||
function LoadPlaylist(invidiousNode as object, singlePage as boolean) as void
|
||||
if m.contentTask <> invalid
|
||||
m.contentTask.cancel = true
|
||||
m.contentTask = invalid
|
||||
m.top.isLoading = false
|
||||
end if
|
||||
|
||||
function LoadPlaylist(invidiousNode as object, jobQueue as object, singlePage as boolean) as void
|
||||
loadState = m.top.loadState
|
||||
if loadState = FeedLoadState.Loading or loadState = FeedLoadState.Loaded
|
||||
return
|
||||
end if
|
||||
|
||||
if m.playlistContentJob <> invalid
|
||||
m.playlistContentJob.cancel = true
|
||||
m.top.isLoading = false
|
||||
end if
|
||||
|
||||
m.top.loadState = FeedLoadState.Loading
|
||||
m.contentTask = AsyncTask.Start(Tasks.PlaylistContentTask, {
|
||||
|
||||
input = {
|
||||
content: m.top
|
||||
invidious: invidiousNode
|
||||
singlePage: singlePage
|
||||
}, OnPlaylistContentTaskResult)
|
||||
}
|
||||
|
||||
callback = JobSystem.CreateCallback(OnPlaylistContentJobDone)
|
||||
JobSystem.QueueJob(jobQueue, Jobs.PlaylistContentJob, input, callback)
|
||||
m.playlistContentJob = callback
|
||||
m.top.isLoading = true
|
||||
end function
|
||||
|
||||
function OnPlaylistContentTaskResult(output as object) as void
|
||||
m.contentTask = invalid
|
||||
function OnPlaylistContentJobDone(event as object) as void
|
||||
callback = event.getRoSGNode()
|
||||
JobSystem.UnobserveCallback(callback)
|
||||
m.playlistContentJob = invalid
|
||||
m.top.isLoading = false
|
||||
|
||||
if output.cancelled
|
||||
if callback.cancel or callback.success
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
LogError(error)
|
||||
playlistId = output.task.input.content.playlistId
|
||||
message = Tr(Locale.Dialogs.FailedToLoadPlaylist).Replace("%1", playlistId) + `\n${error}`
|
||||
DialogUtils.ShowDialogEx({
|
||||
message: message
|
||||
title: Tr(Locale.Dialogs.PlaylistLoadError)
|
||||
large: true
|
||||
})
|
||||
end if
|
||||
message = Tr(Locale.Dialogs.FailedToLoadPlaylist).Replace("%1", m.top.playlistId) + `\n${callback.error}`
|
||||
DialogUtils.ShowDialogEx({
|
||||
message: message
|
||||
title: Tr(Locale.Dialogs.PlaylistLoadError)
|
||||
large: true
|
||||
})
|
||||
end function
|
||||
@@ -61,7 +61,8 @@
|
||||
invidious="bind:../Invidious"
|
||||
notifications="bind:../Notifications"
|
||||
preferences="bind:../Preferences"
|
||||
loungeService="bind:../LoungeService" />
|
||||
loungeService="bind:../LoungeService"
|
||||
jobQueue="bind:/JobQueue" />
|
||||
|
||||
<ApplicationInfo id="ApplicationInfo" />
|
||||
<Preferences id="Preferences" />
|
||||
|
||||
@@ -22,7 +22,8 @@ function InitializeBindings()
|
||||
"invidious": "../Invidious",
|
||||
"notifications": "../Notifications",
|
||||
"preferences": "../Preferences",
|
||||
"loungeService": "../LoungeService"
|
||||
"loungeService": "../LoungeService",
|
||||
"jobQueue": "/JobQueue"
|
||||
},
|
||||
"SearchHistory": {
|
||||
"preferences": "../Preferences"
|
||||
|
||||
@@ -252,8 +252,7 @@ function LoadPlaylistIfNeeded() as void
|
||||
return
|
||||
end if
|
||||
|
||||
' TODO:P1 use a field instead of function call
|
||||
m.top.content@.LoadPlaylistPage(m.top.invidious)
|
||||
m.top.content@.LoadPlaylistPage(m.top.invidious, m.top.jobQueue)
|
||||
end function
|
||||
|
||||
function OnLoadingChanged(event as object)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<field id="isLoading" type="boolean" onChange="OnLoadingChanged" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
<field id="jobQueue" type="node" bind="/JobQueue" />
|
||||
<field id="videoQueue" type="node" bind="/VideoQueue" />
|
||||
<field id="bookmarksService" type="node" bind="/BookmarksService" />
|
||||
<function name="OpenPlaylistChannel" />
|
||||
|
||||
@@ -11,7 +11,7 @@ function ExecuteJob() as void
|
||||
invidiousNode = input.invidious
|
||||
|
||||
callbackNode = JobGetCallbackNode()
|
||||
cancallation = CancellationUtils.CreateCancellation(callbackNode, "cancel", true)
|
||||
cancellation = CancellationUtils.CreateCancellation(callbackNode, "cancel", true)
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
instance = service.GetInstance()
|
||||
@@ -61,7 +61,7 @@ function ExecuteJob() as void
|
||||
|
||||
response = service.MakeRequest(feedSource, {
|
||||
additionalQueryParams: feedSource.state.queryParams
|
||||
cancellation: cancallation
|
||||
cancellation: cancellation
|
||||
})
|
||||
|
||||
if not response.success
|
||||
|
||||
@@ -153,7 +153,7 @@ function OnPlayPlaylist() as void
|
||||
end if
|
||||
|
||||
playlistNode.ObserveFieldScoped("loadState", FuncName(OnPlaylistLoadStateChange))
|
||||
playlistNode@.LoadPlaylistAll(m.top.invidious)
|
||||
playlistNode@.LoadPlaylistAll(m.top.invidious, m.top.jobQueue)
|
||||
end function
|
||||
|
||||
function OnPlaylistLoadStateChange() as void
|
||||
@@ -311,7 +311,7 @@ function OnAddToQueuePlaylist() as void
|
||||
end if
|
||||
|
||||
playlistNode.ObserveFieldScoped("loadState", FuncName(OnPlaylistLoadStateChange))
|
||||
playlistNode@.LoadPlaylistAll(m.top.invidious)
|
||||
playlistNode@.LoadPlaylistAll(m.top.invidious, m.top.jobQueue)
|
||||
end function
|
||||
|
||||
function OnSetQueueAndIndex() as void
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<field id="videoContainer" type="node" />
|
||||
<field id="appController" type="node" />
|
||||
<field id="loungeService" type="node" />
|
||||
<field id="jobQueue" type="node" />
|
||||
|
||||
<!-- Convenience functions to use from context menu -->
|
||||
<function name="FuncPlayVideo" />
|
||||
|
||||
Reference in new issue
Block a user