Add search functions

This commit is contained in:
Brahim Hadriche committed 2022-11-02 19:40:05 -04:00
1 parent ef371da10c
commit f98b9d47bc
4 files changed
+65 -3

No files matched your search

-2
View File
@@ -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": {
@@ -0,0 +1,10 @@
namespace RokuYoutube.Models.Invidious
class SearchSuggestionResult
public query as string
public suggestions as Array
end class
end namespace
+55
View File
@@ -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
-1
View File
@@ -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