diff --git a/CHANGELOG.md b/CHANGELOG.md index 63dc1a44..6713ab13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Medium video quality in the settings (For most videos, this is 360p) +- Invidious watch history feed ### Fixed diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs index 54cb7c32..940bbfcf 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs @@ -1,4 +1,7 @@ +import "pkg:/components/Dialog/DialogUtils.bs" +import "pkg:/components/Services/Invidious/InvidiousUnregisterTokenTask.bs" import "pkg:/components/VideoFeed/PaginationType.bs" +import "pkg:/source/asyncTask/asyncTask.bs" import "pkg:/source/services/HttpClient.bs" import "pkg:/source/utils/CryptoUtils.bs" import "pkg:/source/utils/Logging.bs" @@ -22,7 +25,7 @@ namespace Invidious const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions" - const AUTH_SCOPES = "GET:feed,GET:playlists*,POST:tokens/*,POST:history*,:subscriptions*" + const AUTH_SCOPES = "GET:feed,GET:playlists*,POST:tokens/*,:history*,:subscriptions*" const AUTH_PLAYLISTS = "/api/v1/auth/playlists" const AUTH_SUBSCRIPTIONS = "/api/v1/auth/subscriptions" @@ -50,7 +53,8 @@ namespace Invidious ChannelInfoHandler: m.ChannelInfoHandler, ChannelVideosHandler: m.ChannelVideosHandler, ChannelPlaylistsHandler: m.ChannelPlaylistsHandler, - ChannelRelatedChannelsHandler: m.ChannelRelatedChannelsHandler + ChannelRelatedChannelsHandler: m.ChannelRelatedChannelsHandler, + WatchHistoryHandler: m.WatchHistoryHandler } end function @@ -403,6 +407,31 @@ namespace Invidious } end function + function WatchHistoryHandler(m as object, feedSource as object, response as object) as object + m.DeleteExpiredToken(response) + + if response.StatusCode() <> 200 + return invalid + end if + + json = response.Json() + if json = invalid + return invalid + end if + + videos = [] + for each item in json + videos.push({ + "type": "video", + "videoId": item + }) + end for + + return { + items: videos + } + end function + function DeleteExpiredToken(response as object) if response.StatusCode() = 403 LogWarn(`Invidious instance responded with 403: ${response.Text()}`) @@ -422,12 +451,18 @@ namespace Invidious return invalid end if if not m.VerifyTokenScope(authToken.token) - ' TODO:P1 automatically logging out the user is not a good experience - ' We can at least show a message to the user on why they are logged out - ' TODO:P2 right now we're probably in a UI thread, and we can't unregister the token - ' So we're just going to ignore it for now - ' m.UnregisterToken(authToken) + ' Right now we're probably in a UI thread, and we can't unregister the token + ' Without a Task + StartAsyncTask(InvidiousUnregisterTokenTask, { + invidious: m.node, + authToken: authToken + }) RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN) + message = `It looks like you are logged in to Invidious, but your access token does not have the required permissions. +For that reason, we have logged you out. Please log in again. +This can happen when Playlet is updated with new features. +We apologize for the inconvenience.` + DialogUtils.ShowDialog(message, "User logged out") return invalid end if return authToken diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs index 6efc5617..6c921978 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs @@ -128,7 +128,11 @@ namespace InvidiousContent function VideoSetThumbnail(node as object, videoItem as object, instance as dynamic, quality = "medium" as string) as boolean videoThumbnails = videoItem.videoThumbnails if videoThumbnails = invalid or videoThumbnails.Count() = 0 - node.thumbnail = "pkg:/images/thumbnail-missing.jpg" + if StringUtils.IsNullOrEmpty(instance) + node.thumbnail = "pkg:/images/thumbnail-missing.jpg" + else + node.thumbnail = `${instance}/vi/${videoItem.videoId}/mqdefault.jpg` + end if return false end if url = invalid diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousUnregisterTokenTask.bs b/playlet-lib/src/components/Services/Invidious/InvidiousUnregisterTokenTask.bs new file mode 100644 index 00000000..9322e594 --- /dev/null +++ b/playlet-lib/src/components/Services/Invidious/InvidiousUnregisterTokenTask.bs @@ -0,0 +1,12 @@ +import "InvidiousService.bs" + +@asynctask +function InvidiousUnregisterTokenTask(input as object) as object + invidiousNode = input.invidious + authToken = input.authToken + + service = new Invidious.InvidiousService(invidiousNode) + service.UnregisterToken(authToken) + + return invalid +end function diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs index b7ed50e7..099eaeec 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs @@ -25,6 +25,7 @@ namespace Http response = context.response task = context.server.task playQueue = task.playQueue + invidiousNode = task.invidious payload = request.Json() if payload = invalid @@ -39,7 +40,10 @@ namespace Http return true end if - contentNode = InvidiousContent.ToRowCellContentNode(payload, invalid) + service = new Invidious.InvidiousService(invidiousNode) + instance = service.GetInstance() + + contentNode = InvidiousContent.ToRowCellContentNode(payload, instance) playQueue@.AddToQueue(contentNode) queue = playQueue@.GetQueue() @@ -53,6 +57,7 @@ namespace Http response = context.response task = context.server.task playQueue = task.playQueue + invidiousNode = task.invidious payload = request.Json() if payload = invalid @@ -71,7 +76,10 @@ namespace Http payload.timestamp = payload.timestamp.toInt() end if - contentNode = InvidiousContent.ToRowCellContentNode(payload, invalid) + service = new Invidious.InvidiousService(invidiousNode) + instance = service.GetInstance() + + contentNode = InvidiousContent.ToRowCellContentNode(payload, instance) playlistIndex = IsInt(payload.playlistIndex) ? payload.playlistIndex : -1 if contentNode.type = "playlist" and playlistIndex = -1 playlistIndex = 0 diff --git a/playlet-lib/src/config/default_home_layout.yaml b/playlet-lib/src/config/default_home_layout.yaml index 7c7f53e8..36f52a7f 100644 --- a/playlet-lib/src/config/default_home_layout.yaml +++ b/playlet-lib/src/config/default_home_layout.yaml @@ -72,3 +72,10 @@ title: Playlists apiType: Invidious endpoint: auth_playlists + +- title: Watch history + feedSources: + - id: inv_auth_history + title: Watch history + apiType: Invidious + endpoint: watch_history diff --git a/playlet-lib/src/config/invidious_video_api.yaml b/playlet-lib/src/config/invidious_video_api.yaml index bcd1f008..b982b177 100644 --- a/playlet-lib/src/config/invidious_video_api.yaml +++ b/playlet-lib/src/config/invidious_video_api.yaml @@ -202,3 +202,10 @@ channel_channels: responseHandler: ChannelRelatedChannelsHandler paginationType: Continuation tryCount: 3 + +watch_history: + title: Watch history + url: /api/v1/auth/history + authenticated: true + paginationType: Pages + responseHandler: WatchHistoryHandler diff --git a/playlet-web/src/lib/VideoFeed/VideoCastDialog.svelte b/playlet-web/src/lib/VideoFeed/VideoCastDialog.svelte index dce3215c..975f3919 100644 --- a/playlet-web/src/lib/VideoFeed/VideoCastDialog.svelte +++ b/playlet-web/src/lib/VideoFeed/VideoCastDialog.svelte @@ -86,6 +86,7 @@