Fix resolve url functionality
This commit is contained in:
1 parent
e23da56b37
commit
31a4669c79
4 files changed
+109
No files matched your search
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Fixed
|
||||
|
||||
- Channels sub count in web app
|
||||
- Channel drag and drop in web app
|
||||
|
||||
### Removed
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/CancellationUtils.bs"
|
||||
import "pkg:/source/utils/ObjectUtils.bs"
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/components/Services/Innertube/ResolveUrl.bs"
|
||||
|
||||
namespace InnertubeService
|
||||
|
||||
@@ -239,6 +240,27 @@ namespace InnertubeService
|
||||
return Innertube.ParsePlaylistPageResponse(json)
|
||||
end function
|
||||
|
||||
function ResolveUrl(url as string, options = invalid as object) as object
|
||||
cancellation = invalid
|
||||
|
||||
if options <> invalid
|
||||
if options.DoesExist("cancellation")
|
||||
cancellation = options.cancellation
|
||||
end if
|
||||
end if
|
||||
|
||||
request = Innertube.CreateResolveUrlRequest(url)
|
||||
request.Cancellation(cancellation)
|
||||
|
||||
response = request.Await()
|
||||
if not response.IsSuccess()
|
||||
return invalid
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
return json
|
||||
end function
|
||||
|
||||
function AuthGetCode(cancellation = invalid as object) as object
|
||||
result = Innertube.GetClientIdentity(cancellation)
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Innertube
|
||||
function CreateResolveUrlRequest(url as string) as object
|
||||
deviceInfo = CreateObject("roDeviceInfo")
|
||||
|
||||
payload = {
|
||||
"context": CreateContext(ClientType.Web, deviceInfo, "")
|
||||
"url": url
|
||||
}
|
||||
|
||||
request = HttpClient.PostJson("https://www.youtube.com/youtubei/v1/navigation/resolve_url?prettyPrint=false&alt=json", payload)
|
||||
headers = {
|
||||
"accept": "*/*"
|
||||
"accept-language": "*"
|
||||
}
|
||||
headers.Append(CreateHeaders(ClientType.Web))
|
||||
request.Headers(headers)
|
||||
|
||||
return request
|
||||
end function
|
||||
end namespace
|
||||
+66
@@ -107,6 +107,72 @@ namespace Http
|
||||
return true
|
||||
end function
|
||||
|
||||
@get("/playlet-invidious-backend/api/v1/resolveurl")
|
||||
function ResolveUrl(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
|
||||
url = request.query.url
|
||||
if StringUtils.IsNullOrEmpty(url)
|
||||
response.Default(400, "Missing 'url' query parameter")
|
||||
return true
|
||||
end if
|
||||
|
||||
json = InnertubeService.ResolveUrl(url, response)
|
||||
if json = invalid
|
||||
response.Default(500, "Failed to resolve URL")
|
||||
return true
|
||||
end if
|
||||
|
||||
endpoint = json["endpoint"]
|
||||
pageType = ValidString(ObjectUtils.Dig(endpoint, ["commandMetadata", "webCommandMetadata", "webPageType"]))
|
||||
if pageType = "WEB_PAGE_TYPE_UNKNOWN" or pageType = ""
|
||||
response.Default(400, "Unknown url")
|
||||
return true
|
||||
end if
|
||||
|
||||
subEndpoint = endpoint["watchEndpoint"]
|
||||
if subEndpoint = invalid
|
||||
subEndpoint = endpoint["browseEndpoint"]
|
||||
if subEndpoint = invalid
|
||||
subEndpoint = endpoint
|
||||
end if
|
||||
end if
|
||||
|
||||
params = ObjectUtils.Dig(subEndpoint, ["params"])
|
||||
|
||||
result = {
|
||||
"pageType": pageType
|
||||
}
|
||||
|
||||
browseId = ObjectUtils.Dig(subEndpoint, ["browseId"])
|
||||
if not StringUtils.IsNullOrEmpty(browseId)
|
||||
result["ucid"] = browseId
|
||||
end if
|
||||
|
||||
videoId = ObjectUtils.Dig(subEndpoint, ["videoId"])
|
||||
if not StringUtils.IsNullOrEmpty(videoId)
|
||||
result["videoId"] = videoId
|
||||
end if
|
||||
|
||||
playlistId = ObjectUtils.Dig(subEndpoint, ["playlistId"])
|
||||
if not StringUtils.IsNullOrEmpty(playlistId)
|
||||
result["playlistId"] = playlistId
|
||||
end if
|
||||
|
||||
startTimeSeconds = ObjectUtils.Dig(subEndpoint, ["startTimeSeconds"])
|
||||
if ValidInt(startTimeSeconds) > 0
|
||||
result["startTimeSeconds"] = startTimeSeconds
|
||||
end if
|
||||
|
||||
if IsString(params)
|
||||
result["params"] = params
|
||||
end if
|
||||
|
||||
response.Json(result)
|
||||
return true
|
||||
end function
|
||||
|
||||
@get("*")
|
||||
function GetAll(context as object) as boolean
|
||||
request = context.request
|
||||
|
||||
Reference in new issue
Block a user