Merge pull request #1 from iBicha/feature/search-api
Feature/search api
This commit is contained in:
7 files changed
+116
-5
No files matched your search
Vendored
-2
@@ -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": {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
itemComponentName="RowListItemComponent"
|
||||
id="rowList"
|
||||
translation="[50,50]"
|
||||
numRows="2"
|
||||
numRows="3"
|
||||
rowitemSize="[[320,180]]"
|
||||
rowItemSpacing="[[20,0]]"
|
||||
itemSize="[1160,270]"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace RokuYoutube.Models.Invidious
|
||||
|
||||
class SearchSuggestionResult
|
||||
|
||||
public query as string
|
||||
public suggestions as Array
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -1,11 +1,17 @@
|
||||
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"
|
||||
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 +40,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 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 = {
|
||||
q: q
|
||||
}
|
||||
|
||||
if page <> invalid
|
||||
params.page = Str(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,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
|
||||
|
||||
Reference in new issue
Block a user