* [Wip] search filters protobuf * Filters work * Small tweaks * changelog
77 lines
2.4 KiB
Plaintext
77 lines
2.4 KiB
Plaintext
import "pkg:/components/Services/Innertube/Context.bs"
|
|
import "pkg:/components/Services/Innertube/Parser.bs"
|
|
|
|
namespace Innertube
|
|
|
|
function Search(query as string, searchFilters as object, cancellation = invalid as object) as object
|
|
deviceInfo = CreateObject("roDeviceInfo")
|
|
|
|
payload = {
|
|
query: query
|
|
context: Innertube.CreateContext(Innertube.ClientType.WEB, deviceInfo, "")
|
|
}
|
|
|
|
if searchFilters <> invalid and searchFilters.Count() > 0
|
|
params = Innertube.GetEncodedSearchFilters(searchFilters)
|
|
if params <> ""
|
|
payload["params"] = Innertube.GetEncodedSearchFilters(searchFilters)
|
|
end if
|
|
end if
|
|
|
|
request = HttpClient.PostJson("https://www.youtube.com/youtubei/v1/search?prettyPrint=false&alt=json", payload)
|
|
request.Headers({
|
|
"accept": "*/*"
|
|
"accept-language": "*"
|
|
"user-agent": INNERTUBE_WEB_USER_AGENT
|
|
"x-youtube-client-name": INNERTUBE_WEB_CLIENT_NAME
|
|
"x-youtube-client-version": INNERTUBE_WEB_CLIENT_VERSION
|
|
})
|
|
|
|
request.Cancellation(cancellation)
|
|
|
|
response = request.Await()
|
|
if not response.IsSuccess()
|
|
return invalid
|
|
end if
|
|
|
|
json = response.Json()
|
|
return ParseResponse(json)
|
|
end function
|
|
|
|
function SearchSuggestions(query as string, cancellation = invalid as object) as object
|
|
request = HttpClient.Get("https://suggestqueries.google.com/complete/search?hl=en&gl=US&ds=yt&client=youtube&xssi=t&oe=UTF&q=" + query.EncodeUriComponent())
|
|
request.Headers({
|
|
"user-agent": INNERTUBE_WEB_USER_AGENT
|
|
})
|
|
request.CacheSeconds(60 * 60 * 24)
|
|
request.Cancellation(cancellation)
|
|
|
|
response = request.Await()
|
|
if not response.IsSuccess()
|
|
return invalid
|
|
end if
|
|
|
|
text = response.Text()
|
|
text = text.Replace(`)]}'`, "")
|
|
|
|
parsed = ParseJson(text)
|
|
if not IsArray(parsed) or parsed.Count() < 2
|
|
return invalid
|
|
end if
|
|
parsed = parsed[1]
|
|
|
|
suggestions = []
|
|
for each suggestion in parsed
|
|
sugg = suggestion[0]
|
|
if not IsString(sugg)
|
|
continue for
|
|
end if
|
|
|
|
suggestions.Push(sugg)
|
|
end for
|
|
|
|
return suggestions
|
|
end function
|
|
|
|
end namespace
|