From f98b9d47bca5b4a4fcc64099eb4ab514da271a6c Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Wed, 2 Nov 2022 19:40:05 -0400 Subject: [PATCH 1/5] Add search functions --- .vscode/settings.json | 2 - src/source/models/SearchSuggestionResult.bs | 10 ++++ src/source/services/Invidious.bs | 55 +++++++++++++++++++++ src/source/services/SponsorBlock.bs | 1 - 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/source/models/SearchSuggestionResult.bs diff --git a/.vscode/settings.json b/.vscode/settings.json index 3c4a2070..28e94581 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,6 @@ "build" ], "files.exclude": { - "build": true, ".history": true, "node_modules": true, "out": true, @@ -19,7 +18,6 @@ "**/.factorypath": true, "/tmp/**": true, "**/dist": true, - "**/build": true, "**/out": true }, "search.exclude": { diff --git a/src/source/models/SearchSuggestionResult.bs b/src/source/models/SearchSuggestionResult.bs new file mode 100644 index 00000000..cbf1e6b6 --- /dev/null +++ b/src/source/models/SearchSuggestionResult.bs @@ -0,0 +1,10 @@ +namespace RokuYoutube.Models.Invidious + + class SearchSuggestionResult + + public query as string + public suggestions as Array + + end class + +end namespace \ No newline at end of file diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index edf26e06..985971d2 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -1,11 +1,16 @@ import "pkg:/source/roku_modules/rokurequests/Requests.brs" +import "pkg:/source/models/SearchSuggestionResult.bs" namespace RokuYoutube.Services.Invidious const API_URL = "https://invidious.esmailelbob.xyz" const POPULAR_ENDPOINT = "/api/v1/popular" const TRENDING_ENDPOINT = "/api/v1/trending" + const VIDEOS_ENDPOINT = "/api/v1/videos" + const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions" + const SEARCH_ENDPOINT = "/api/v1/search" + function GetPopular() url = `${API_URL}${POPULAR_ENDPOINT}` response = Requests().get(url) @@ -34,4 +39,54 @@ namespace RokuYoutube.Services.Invidious end if end function + function SearchSuggestions(q as string) as SearchSuggestionResult + url = `${API_URL}${SEARCH_SUGGEST_ENDPOINT}` + args = { + params: { + q: q + } + } + response = Requests().get(url, args) + + if response.statuscode = 200 + return response.json + end if + end function + + function Search(q as string, page = invalid, sort_by = invalid, date = invalid, duration = invalid, _type = invalid, features = invalid) + url = `${API_URL}${SEARCH_ENDPOINT}` + + params = { + q: q + } + + if page <> invalid + params.page = page + end if + if sort_by <> invalid + params.sort_by = sort_by + end if + if date <> invalid + params.date = date + end if + if duration <> invalid + params.duration = duration + end if + if _type <> invalid + params.type = _type + end if + if features <> invalid + params.features = features.join(",") + end if + + args = { + params: params + } + + response = Requests().get(url, args) + + if response.statuscode = 200 + return response.json + end if + end function end namespace \ No newline at end of file diff --git a/src/source/services/SponsorBlock.bs b/src/source/services/SponsorBlock.bs index b22fa42e..b634737f 100644 --- a/src/source/services/SponsorBlock.bs +++ b/src/source/services/SponsorBlock.bs @@ -1,4 +1,3 @@ -' TODO: remove Requests.brs and import it from installed package import "pkg:/source/roku_modules/rokurequests/Requests.brs" namespace RokuYoutube.Services.SponsorBlock From 7d5ac747a303a09873490af3deb9a4e6a4fa8601 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Wed, 2 Nov 2022 20:01:51 -0400 Subject: [PATCH 2/5] Handle search returning playlists (temp) --- src/components/tasks/MainLoaderTask.brs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/tasks/MainLoaderTask.brs b/src/components/tasks/MainLoaderTask.brs index 69175b37..04af0134 100644 --- a/src/components/tasks/MainLoaderTask.brs +++ b/src/components/tasks/MainLoaderTask.brs @@ -38,13 +38,19 @@ function GetCategoryContent(category as string, json as object) as object row.children = [] for each item in json ' parse items and push them to row itemData = GetItemData(item) - row.children.Push(itemData) + if itemData <> invalid + row.children.Push(itemData) + end if end for return row end if end function function GetItemData(video as object) as object + ' TODO: handle playlists and channels + if video.videoId = invalid + return invalid + end if item = {} item.title = video.title From fe1a4cea1f2e570473d3b7177e22d06028c43c4a Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Wed, 2 Nov 2022 21:02:15 -0400 Subject: [PATCH 3/5] Add types --- src/source/models/SearchFilter.bs | 42 +++++++++++++++++++++++++++++++ src/source/services/Invidious.bs | 9 +++---- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/source/models/SearchFilter.bs diff --git a/src/source/models/SearchFilter.bs b/src/source/models/SearchFilter.bs new file mode 100644 index 00000000..4e961995 --- /dev/null +++ b/src/source/models/SearchFilter.bs @@ -0,0 +1,42 @@ +namespace RokuYoutube.Models.Invidious.SearchFilter + enum SortBy + Relevance = "relevance" + Rating = "rating" + UploadDate = "upload_date" + ViewCount = "view_count" + end enum + + enum Date + Hour = "hour" + Today = "today" + Week = "week" + Month = "month" + Year = "year" + end enum + + enum Duration + Short = "short" + Long = "long" + end enum + + enum SearchType + Video = "video" + Playlist = "playlist" + Channel = "channel" + All = "all" + end enum + + enum Features + HD = "hd" + Subtitles = "subtitles" + CreativeCommons = "creative_commons" + ThreeD = "3d" + Live = "live" + Purchased = "purchased" + FourK = "4k" + Three60 = "360" + Location = "location" + HDR = "hdr" + end enum + +end namespace \ No newline at end of file diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 985971d2..76874e0e 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -1,5 +1,6 @@ import "pkg:/source/roku_modules/rokurequests/Requests.brs" import "pkg:/source/models/SearchSuggestionResult.bs" +import "pkg:/source/models/SearchFilter.bs" namespace RokuYoutube.Services.Invidious const API_URL = "https://invidious.esmailelbob.xyz" @@ -53,7 +54,7 @@ namespace RokuYoutube.Services.Invidious end if end function - function Search(q as string, page = invalid, sort_by = invalid, date = invalid, duration = invalid, _type = invalid, features = invalid) + function Search(q as string, page = invalid as integer, sort_by = invalid as RokuYoutube.Models.Invidious.SearchFilter.SortBy, date = invalid as RokuYoutube.Models.Invidious.SearchFilter.Date, duration = invalid as RokuYoutube.Models.Invidious.SearchFilter.Duration, _type = invalid as RokuYoutube.Models.Invidious.SearchFilter.SearchType, features = invalid as RokuYoutube.Models.Invidious.SearchFilter.Features) url = `${API_URL}${SEARCH_ENDPOINT}` params = { @@ -61,7 +62,7 @@ namespace RokuYoutube.Services.Invidious } if page <> invalid - params.page = page + params.page = Str(page) end if if sort_by <> invalid params.sort_by = sort_by @@ -79,9 +80,7 @@ namespace RokuYoutube.Services.Invidious params.features = features.join(",") end if - args = { - params: params - } + args = { params: params } response = Requests().get(url, args) From f31042275781c05264b17b50bdd82c7941c487a5 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Wed, 2 Nov 2022 21:11:35 -0400 Subject: [PATCH 4/5] format --- src/source/services/Invidious.bs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 76874e0e..0dfc6d04 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -80,7 +80,9 @@ namespace RokuYoutube.Services.Invidious params.features = features.join(",") end if - args = { params: params } + args = { + params: params + } response = Requests().get(url, args) From aa72237782ce602bdfc924ba5dbfa863d0c645a2 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Wed, 2 Nov 2022 21:13:42 -0400 Subject: [PATCH 5/5] 3 rows is better --- src/components/GridScreen/GridScreen.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/GridScreen/GridScreen.xml b/src/components/GridScreen/GridScreen.xml index caf1143e..6d30d345 100644 --- a/src/components/GridScreen/GridScreen.xml +++ b/src/components/GridScreen/GridScreen.xml @@ -12,7 +12,7 @@ itemComponentName="RowListItemComponent" id="rowList" translation="[50,50]" - numRows="2" + numRows="3" rowitemSize="[[320,180]]" rowItemSpacing="[[20,0]]" itemSize="[1160,270]"