From 2d1490f9255b05fa411d2f25710a20971a8ddb58 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 1 Dec 2022 16:50:06 -0500 Subject: [PATCH] Invidious calls cleanup, add fields, fix subscriptions --- src/config/invidious_video_api.json | 19 +++++- src/source/services/Invidious.bs | 80 ------------------------- src/source/services/InvidiousService.bs | 5 +- 3 files changed, 22 insertions(+), 82 deletions(-) diff --git a/src/config/invidious_video_api.json b/src/config/invidious_video_api.json index 6036f2ee..c7600583 100644 --- a/src/config/invidious_video_api.json +++ b/src/config/invidious_video_api.json @@ -18,6 +18,11 @@ "required": false, "type": "#ISO3166", "default": "GetUserCountryCode" + }, + "fields": { + "required": false, + "type": "string", + "default": "title,videoId,videoThumbnails,lengthSeconds,viewCount,author,publishedText,liveNow" } } }, @@ -25,7 +30,14 @@ "name": "popular", "displayName": "Popular", "url": "/api/v1/popular", - "authenticated": false + "authenticated": false, + "queryParams": { + "fields": { + "required": false, + "type": "string", + "default": "title,videoId,videoThumbnails,lengthSeconds,viewCount,author,publishedText,liveNow" + } + } }, { "name": "search", @@ -90,6 +102,11 @@ "required": false, "type": "#ISO3166", "default": "GetUserCountryCode" + }, + "fields": { + "required": false, + "type": "string", + "default": "title,videoId,videoThumbnails,lengthSeconds,viewCount,author,publishedText,liveNow" } } }, diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 9cc92634..ae6b4893 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -31,36 +31,6 @@ namespace Invidious } end function - function GetPopular() as object - instance = InvidiousSettings.GetSelectedInstance() - url = `${instance}${Invidious.POPULAR_ENDPOINT}` - - args = Invidious.DefaultArgs() - response = Requests().get(url, args) - - if response.statuscode = 200 - return response.json - end if - return invalid - end function - - function GetTrending(trendingType = "" as string) as object - instance = InvidiousSettings.GetSelectedInstance() - url = `${instance}${Invidious.TRENDING_ENDPOINT}` - - args = Invidious.DefaultArgs() - if trendingType <> "" - args.params.type = trendingType - end if - - response = Requests().get(url, args) - - if response.statuscode = 200 - return response.json - end if - return invalid - end function - function GetVideoUrl(videoId as string, itag as string, local as boolean) as string instance = InvidiousSettings.GetSelectedInstance() url = `${instance}/latest_version?id=${videoId}&itag=${itag}` @@ -152,56 +122,6 @@ namespace Invidious } end function - function GetUserFeed() as object - authToken = InvidiousSettings.GetAuthToken() - if authToken = invalid - return false - end if - headers = Invidious.GetAuthenticationHeaders(authToken.token) - - url = `${authToken.instance}${Invidious.AUTH_FEED}` - - args = { - headers: headers, - retryCount: 3 'Sometimes authentication fails randomly with a valid token... - } - - response = Requests().get(url, args) - - if response.statuscode = 403 - RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN) - end if - if response.statuscode = 200 - return response.json.videos - end if - return invalid - end function - - function GetUserPlaylists() as object - authToken = InvidiousSettings.GetAuthToken() - if authToken = invalid - return false - end if - headers = Invidious.GetAuthenticationHeaders(authToken.token) - - url = `${authToken.instance}${Invidious.AUTH_PLAYLISTS}` - - args = { - headers: headers, - retryCount: 3 'Sometimes authentication fails randomly with a valid token... - } - - response = Requests().get(url, args) - - if response.statuscode = 403 - RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN) - end if - if response.statuscode = 200 - return response.json - end if - return invalid - end function - function Logout() as boolean authToken = InvidiousSettings.GetAuthToken() if authToken = invalid diff --git a/src/source/services/InvidiousService.bs b/src/source/services/InvidiousService.bs index 519c76a0..8ccf83a3 100644 --- a/src/source/services/InvidiousService.bs +++ b/src/source/services/InvidiousService.bs @@ -92,7 +92,10 @@ class InvidiousService m.DeleteExpiredToken(response) if response.statuscode = 200 - return response.json.videos + videos = [] + videos.Append(response.json.notifications) + videos.Append(response.json.videos) + return videos end if return invalid end function