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