Oauth stuff (#533)
* qrcode * add stuff * Some oauth stuff * remove some test code * Lint fix * Revert "add stuff" This reverts commit 8508471e4a0a2bfa06d4f04bfdece1f3c9191e1c. * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
fde8eaa0c2
commit
c85ac0acf1
12 files changed
+344
-78
No files matched your search
@@ -7,6 +7,15 @@
|
|||||||
<field id="serverUrl" type="string" />
|
<field id="serverUrl" type="string" />
|
||||||
<field id="accessToken" type="string" />
|
<field id="accessToken" type="string" />
|
||||||
|
|
||||||
|
<!-- Innertube fields -->
|
||||||
|
<field id="refreshToken" type="string" />
|
||||||
|
<field id="scope" type="string" />
|
||||||
|
<field id="tokenType" type="string" />
|
||||||
|
<field id="expiresIn" type="longinteger" />
|
||||||
|
<field id="expiresTimestamp" type="longinteger" />
|
||||||
|
<field id="clientId" type="string" />
|
||||||
|
<field id="clientSecret" type="string" />
|
||||||
|
|
||||||
<field id="color" type="color" />
|
<field id="color" type="color" />
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -58,14 +58,11 @@ function GenerateQrCode() as void
|
|||||||
m.top.uri = ""
|
m.top.uri = ""
|
||||||
|
|
||||||
if StringUtils.IsNullOrEmpty(text)
|
if StringUtils.IsNullOrEmpty(text)
|
||||||
m.busySpinner.control = "stop"
|
m.top.isBusy = false
|
||||||
m.busySpinner.visible = false
|
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
m.busySpinnerPoster.rotation = 0
|
m.top.isBusy = true
|
||||||
m.busySpinner.visible = true
|
|
||||||
m.busySpinner.control = "start"
|
|
||||||
|
|
||||||
m.qrCodeGenTask = AsyncTask.Start(Tasks.GenerateQrCodeTask, {
|
m.qrCodeGenTask = AsyncTask.Start(Tasks.GenerateQrCodeTask, {
|
||||||
poster: m.top
|
poster: m.top
|
||||||
@@ -80,6 +77,18 @@ function OnGenerateQrCodeTaskResult(output as object) as void
|
|||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
m.busySpinner.control = "stop"
|
m.top.isBusy = false
|
||||||
m.busySpinner.visible = false
|
end function
|
||||||
|
|
||||||
|
function OnIsBusy()
|
||||||
|
isBusy = m.top.isBusy
|
||||||
|
|
||||||
|
if isBusy
|
||||||
|
m.busySpinnerPoster.rotation = 0
|
||||||
|
m.busySpinner.control = "start"
|
||||||
|
m.busySpinner.visible = true
|
||||||
|
else
|
||||||
|
m.busySpinner.control = "stop"
|
||||||
|
m.busySpinner.visible = false
|
||||||
|
end if
|
||||||
end function
|
end function
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
<interface>
|
<interface>
|
||||||
<field id="text" type="string" onChange="OnTextChange" />
|
<field id="text" type="string" onChange="OnTextChange" />
|
||||||
<field id="padding" type="integer" />
|
<field id="padding" type="integer" />
|
||||||
|
<field id="isBusy" type="boolean" onChange="OnIsBusy" alwaysNotify="true" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
<BusySpinner
|
<BusySpinner
|
||||||
|
|||||||
@@ -236,20 +236,24 @@ namespace InnertubeService
|
|||||||
|
|
||||||
function GetBrowseAuthenticatedPage(browserId as string, options = invalid as object) as object
|
function GetBrowseAuthenticatedPage(browserId as string, options = invalid as object) as object
|
||||||
cancellation = invalid
|
cancellation = invalid
|
||||||
access_token = invalid
|
accessToken = invalid
|
||||||
|
continuation = ""
|
||||||
|
|
||||||
if options <> invalid
|
if options <> invalid
|
||||||
if options.DoesExist("cancellation")
|
if options.DoesExist("cancellation")
|
||||||
cancellation = options.cancellation
|
cancellation = options.cancellation
|
||||||
end if
|
end if
|
||||||
if options.DoesExist("access_token")
|
if options.DoesExist("accessToken")
|
||||||
access_token = options.access_token
|
accessToken = options.accessToken
|
||||||
|
end if
|
||||||
|
if options.DoesExist("continuation")
|
||||||
|
continuation = options.continuation
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
request = Innertube.CreateBrowseRequest(browserId, Innertube.ClientType.Tv)
|
request = Innertube.CreateBrowseRequest(browserId, Innertube.ClientType.Tv, "", continuation)
|
||||||
if access_token <> invalid
|
if accessToken <> invalid
|
||||||
request.Header("Authorization", "Bearer " + access_token)
|
request.Header("Authorization", "Bearer " + accessToken)
|
||||||
end if
|
end if
|
||||||
request.Cancellation(cancellation)
|
request.Cancellation(cancellation)
|
||||||
|
|
||||||
@@ -399,7 +403,7 @@ namespace InnertubeService
|
|||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
|
|
||||||
result2 = Innertube.GetDeviceAndUserCode(result.client_id, cancellation)
|
result2 = Innertube.GetDeviceAndUserCode(result.clientId, cancellation)
|
||||||
|
|
||||||
if CancellationUtils.IsCancelled(cancellation)
|
if CancellationUtils.IsCancelled(cancellation)
|
||||||
return invalid
|
return invalid
|
||||||
@@ -410,7 +414,7 @@ namespace InnertubeService
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function AuthGetActivationUrl(code as object) as string
|
function AuthGetActivationUrl(code as object) as string
|
||||||
return `https://www.youtube.com/tv/activate?user_code=${code.user_code}`
|
return `https://www.youtube.com/tv/activate?user_code=${code.userCode}`
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function AuthPollForAccessToken(code as object, cancellation = invalid as object) as object
|
function AuthPollForAccessToken(code as object, cancellation = invalid as object) as object
|
||||||
@@ -428,10 +432,10 @@ namespace InnertubeService
|
|||||||
if expiresTimestamp = invalid or expiresTimestamp < nowSeconds
|
if expiresTimestamp = invalid or expiresTimestamp < nowSeconds
|
||||||
refreshed = Innertube.RefreshAccessToken(accessToken, cancellation)
|
refreshed = Innertube.RefreshAccessToken(accessToken, cancellation)
|
||||||
|
|
||||||
if IsAssociativeArray(refreshed) and refreshed.DoesExist("access_token")
|
if IsAssociativeArray(refreshed) and refreshed.DoesExist("accessToken")
|
||||||
accessToken.Append(refreshed)
|
accessToken.Append(refreshed)
|
||||||
if accessToken.DoesExist("expires_in")
|
if accessToken.DoesExist("expiresIn")
|
||||||
accessToken["expires_timestamp"] = TimeUtils.Now().AsSeconds() + accessToken["expires_in"]
|
accessToken["expiresTimestamp"] = TimeUtils.Now().AsSeconds() + accessToken["expiresIn"]
|
||||||
end if
|
end if
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
@@ -445,7 +449,7 @@ namespace InnertubeService
|
|||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return Innertube.RevokeAccessToken(accessToken["access_token"], cancellation)
|
return Innertube.RevokeAccessToken(accessToken["accessToken"], cancellation)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
@@ -67,6 +67,8 @@ namespace Innertube
|
|||||||
"richItemRenderer": ParseRichItemRenderer
|
"richItemRenderer": ParseRichItemRenderer
|
||||||
"continuationItemRenderer": ParseContinuationItemRenderer
|
"continuationItemRenderer": ParseContinuationItemRenderer
|
||||||
"appendContinuationItemsAction": ParseAppendContinuationItemsAction
|
"appendContinuationItemsAction": ParseAppendContinuationItemsAction
|
||||||
|
"gridContinuation": ParseGridContinuation
|
||||||
|
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
||||||
' Ignored nodes:
|
' Ignored nodes:
|
||||||
' Posts not yet supported
|
' Posts not yet supported
|
||||||
"postRenderer": ParseNotImplemented
|
"postRenderer": ParseNotImplemented
|
||||||
@@ -850,11 +852,32 @@ namespace Innertube
|
|||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
lengthText = ""
|
||||||
|
isUpcoming = false
|
||||||
|
liveNow = false
|
||||||
|
thumbnailOverlays = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnailOverlays"])
|
||||||
|
if IsArray(thumbnailOverlays)
|
||||||
|
for each overlay in thumbnailOverlays
|
||||||
|
maybeLengthText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "text"]))
|
||||||
|
if maybeLengthText <> ""
|
||||||
|
lengthText = maybeLengthText
|
||||||
|
end if
|
||||||
|
liveNow = liveNow or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE")
|
||||||
|
isUpcoming = isUpcoming or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "UPCOMING")
|
||||||
|
end for
|
||||||
|
if liveNow or isUpcoming
|
||||||
|
lengthText = ""
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
video = {
|
video = {
|
||||||
"type": "video"
|
"type": "video"
|
||||||
"videoId": videoId
|
"videoId": videoId
|
||||||
"title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"]))
|
"title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"]))
|
||||||
"videoThumbnails": videoThumbnails
|
"videoThumbnails": videoThumbnails
|
||||||
|
"lengthText": lengthText
|
||||||
|
"liveNow": liveNow
|
||||||
|
"isUpcoming": isUpcoming
|
||||||
}
|
}
|
||||||
|
|
||||||
PushFeedItem(video, context)
|
PushFeedItem(video, context)
|
||||||
@@ -868,11 +891,23 @@ namespace Innertube
|
|||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
videoCountText = ""
|
||||||
|
thumbnailOverlays = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnailOverlays"])
|
||||||
|
if IsArray(thumbnailOverlays)
|
||||||
|
for each overlay in thumbnailOverlays
|
||||||
|
videoCountText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "text"]))
|
||||||
|
if videoCountText <> ""
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
end if
|
||||||
|
|
||||||
playlist = {
|
playlist = {
|
||||||
"type": "playlist"
|
"type": "playlist"
|
||||||
"playlistId": playlistId
|
"playlistId": playlistId
|
||||||
"title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"]))
|
"title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"]))
|
||||||
"playlistThumbnail": ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnail", "thumbnails"])
|
"playlistThumbnail": ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnail", "thumbnails", 0, "url"])
|
||||||
|
"videoCountText": videoCountText
|
||||||
}
|
}
|
||||||
|
|
||||||
PushFeedItem(playlist, context)
|
PushFeedItem(playlist, context)
|
||||||
@@ -911,6 +946,19 @@ namespace Innertube
|
|||||||
return nodeData["continuationItems"]
|
return nodeData["continuationItems"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ParseGridContinuation(nodeData as object, context as object) as object
|
||||||
|
continuation = ObjectUtils.Dig(nodeData, ["continuations", 0, "nextContinuationData", "continuation"])
|
||||||
|
if IsString(continuation)
|
||||||
|
context.currentFeed.continuation = continuation
|
||||||
|
end if
|
||||||
|
return nodeData["items"]
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ParseTvSurfaceContentContinuation(nodeData as object, context as object) as object
|
||||||
|
' title = ParseText(ObjectUtils.Dig(nodeData, ["header", "tvSurfaceHeaderRenderer", "title"]))
|
||||||
|
return nodeData["content"]
|
||||||
|
end function
|
||||||
|
|
||||||
function ParseText(data as object) as string
|
function ParseText(data as object) as string
|
||||||
if data = invalid
|
if data = invalid
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ namespace Innertube
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"client_id": match[1]
|
"clientId": match[1]
|
||||||
"client_secret": match[2]
|
"clientSecret": match[2]
|
||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -69,13 +69,14 @@ namespace Innertube
|
|||||||
throw `Failed to get device code: ${response.ErrorMessage()}`
|
throw `Failed to get device code: ${response.ErrorMessage()}`
|
||||||
end if
|
end if
|
||||||
|
|
||||||
responseData = response.Json()
|
responseData = ToCamelCase(response.Json())
|
||||||
if responseData.DoesExist("error_code")
|
|
||||||
|
if responseData.DoesExist("errorCode")
|
||||||
throw "Failed to get device code: " + ToString(responseData)
|
throw "Failed to get device code: " + ToString(responseData)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if responseData.DoesExist("expires_in")
|
if responseData.DoesExist("expiresIn")
|
||||||
responseData["expires_timestamp"] = TimeUtils.Now().AsSeconds() + responseData["expires_in"]
|
responseData["expiresTimestamp"] = TimeUtils.Now().AsSeconds() + responseData["expiresIn"]
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return responseData
|
return responseData
|
||||||
@@ -83,9 +84,9 @@ namespace Innertube
|
|||||||
|
|
||||||
function PollForAccessToken(clientIdentity as object, deviceAndUserCode as object, cancellation = invalid as dynamic) as object
|
function PollForAccessToken(clientIdentity as object, deviceAndUserCode as object, cancellation = invalid as dynamic) as object
|
||||||
payload = {
|
payload = {
|
||||||
"client_id": clientIdentity.client_id
|
"client_id": clientIdentity.clientId
|
||||||
"client_secret": clientIdentity.client_secret
|
"client_secret": clientIdentity.clientSecret
|
||||||
"code": deviceAndUserCode.device_code
|
"code": deviceAndUserCode.deviceCode
|
||||||
"grant_type": "http://oauth.net/grant_type/device/1.0"
|
"grant_type": "http://oauth.net/grant_type/device/1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,13 +105,13 @@ namespace Innertube
|
|||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
|
|
||||||
responseData = response.Json()
|
responseData = ToCamelCase(response.Json())
|
||||||
if not responseData.DoesExist("error")
|
if not responseData.DoesExist("error")
|
||||||
if responseData.DoesExist("expires_in")
|
if responseData.DoesExist("expiresIn")
|
||||||
responseData["expires_timestamp"] = TimeUtils.Now().AsSeconds() + responseData["expires_in"]
|
responseData["expiresTimestamp"] = TimeUtils.Now().AsSeconds() + responseData["expiresIn"]
|
||||||
end if
|
end if
|
||||||
responseData["client_id"] = clientIdentity.client_id
|
responseData["clientId"] = clientIdentity["clientId"]
|
||||||
responseData["client_secret"] = clientIdentity.client_secret
|
responseData["clientSecret"] = clientIdentity["clientSecret"]
|
||||||
return responseData
|
return responseData
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -142,9 +143,9 @@ namespace Innertube
|
|||||||
|
|
||||||
function RefreshAccessToken(accessToken as object, cancellation = invalid as dynamic) as object
|
function RefreshAccessToken(accessToken as object, cancellation = invalid as dynamic) as object
|
||||||
payload = {
|
payload = {
|
||||||
"client_id": accessToken.client_id
|
"client_id": accessToken.clientId
|
||||||
"client_secret": accessToken.client_secret
|
"client_secret": accessToken.clientSecret
|
||||||
"refresh_token": accessToken.refresh_token
|
"refresh_token": accessToken.refreshToken
|
||||||
"grant_type": "refresh_token"
|
"grant_type": "refresh_token"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,8 +157,8 @@ namespace Innertube
|
|||||||
throw `Failed to refresh token: ${response.ErrorMessage()}`
|
throw `Failed to refresh token: ${response.ErrorMessage()}`
|
||||||
end if
|
end if
|
||||||
|
|
||||||
responseData = response.Json()
|
responseData = ToCamelCase(response.Json())
|
||||||
if responseData.DoesExist("error_code")
|
if responseData.DoesExist("errorCode")
|
||||||
throw "Failed to refresh token: " + ToString(responseData)
|
throw "Failed to refresh token: " + ToString(responseData)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -176,4 +177,22 @@ namespace Innertube
|
|||||||
return success
|
return success
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ToCamelCase(obj as object) as object
|
||||||
|
if not IsAssociativeArray(obj)
|
||||||
|
return obj
|
||||||
|
end if
|
||||||
|
|
||||||
|
newObj = {}
|
||||||
|
for each key in obj
|
||||||
|
newKey = key
|
||||||
|
underScoreIndex = newKey.InStr("_")
|
||||||
|
while underScoreIndex <> -1 and underScoreIndex < newKey.Len() - 2
|
||||||
|
newKey = newKey.Left(underScoreIndex) + UCase(newKey.Mid(underScoreIndex + 1, 1)) + newKey.Mid(underScoreIndex + 2)
|
||||||
|
underScoreIndex = newKey.InStr("_")
|
||||||
|
end while
|
||||||
|
newObj[newKey] = obj[key]
|
||||||
|
end for
|
||||||
|
return newObj
|
||||||
|
end function
|
||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
@@ -316,6 +316,7 @@ namespace Innertube
|
|||||||
responseData["response"]
|
responseData["response"]
|
||||||
responseData["onResponseReceivedActions"]
|
responseData["onResponseReceivedActions"]
|
||||||
responseData["onResponseReceivedCommands"]
|
responseData["onResponseReceivedCommands"]
|
||||||
|
responseData["continuationContents"]
|
||||||
]
|
]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -560,9 +560,15 @@ namespace Invidious
|
|||||||
videos.Append(json.videos)
|
videos.Append(json.videos)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return {
|
result = {
|
||||||
items: videos
|
items: videos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if json.continuation <> invalid
|
||||||
|
result.continuation = json.continuation
|
||||||
|
end if
|
||||||
|
|
||||||
|
return result
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function WatchHistoryHandler(context as object) as object
|
function WatchHistoryHandler(context as object) as object
|
||||||
@@ -576,49 +582,49 @@ namespace Invidious
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
if not IsArray(json)
|
if IsArray(json)
|
||||||
return invalid
|
videos = []
|
||||||
end if
|
if json.Count() = 0
|
||||||
|
return {
|
||||||
|
items: videos
|
||||||
|
}
|
||||||
|
end if
|
||||||
|
|
||||||
videos = []
|
videoDictionary = {}
|
||||||
if json.Count() = 0
|
|
||||||
return {
|
videosMetadata = InnertubeService.GetVideoInfoBatched(json)
|
||||||
|
if not StringUtils.IsNullOrEmpty(videosMetadata.error)
|
||||||
|
LogError("Failed to load video metadata", videosMetadata.error)
|
||||||
|
else
|
||||||
|
for each video in videosMetadata.videos
|
||||||
|
videoDictionary[video.videoId] = video
|
||||||
|
end for
|
||||||
|
end if
|
||||||
|
|
||||||
|
for each videoId in json
|
||||||
|
video = videoDictionary[videoId]
|
||||||
|
if video = invalid
|
||||||
|
video = {
|
||||||
|
"type": "video"
|
||||||
|
"videoId": videoId
|
||||||
|
"videoThumbnails": [{
|
||||||
|
"quality": "medium"
|
||||||
|
"url": `https://i.ytimg.com/vi/${videoId}/mqdefault.jpg`
|
||||||
|
"width": 320
|
||||||
|
"height": 180
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
end if
|
||||||
|
|
||||||
|
videos.push(video)
|
||||||
|
end for
|
||||||
|
|
||||||
|
json = {
|
||||||
items: videos
|
items: videos
|
||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
|
|
||||||
videoDictionary = {}
|
return json
|
||||||
|
|
||||||
videosMetadata = InnertubeService.GetVideoInfoBatched(json)
|
|
||||||
if not StringUtils.IsNullOrEmpty(videosMetadata.error)
|
|
||||||
LogError("Failed to load video metadata", videosMetadata.error)
|
|
||||||
else
|
|
||||||
for each video in videosMetadata.videos
|
|
||||||
videoDictionary[video.videoId] = video
|
|
||||||
end for
|
|
||||||
end if
|
|
||||||
|
|
||||||
for each videoId in json
|
|
||||||
video = videoDictionary[videoId]
|
|
||||||
if video = invalid
|
|
||||||
video = {
|
|
||||||
"type": "video"
|
|
||||||
"videoId": videoId
|
|
||||||
"videoThumbnails": [{
|
|
||||||
"quality": "medium"
|
|
||||||
"url": `https://i.ytimg.com/vi/${videoId}/mqdefault.jpg`
|
|
||||||
"width": 320
|
|
||||||
"height": 180
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
end if
|
|
||||||
|
|
||||||
videos.push(video)
|
|
||||||
end for
|
|
||||||
|
|
||||||
return {
|
|
||||||
items: videos
|
|
||||||
}
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function DeleteExpiredToken(response as object, authToken as object) as void
|
function DeleteExpiredToken(response as object, authToken as object) as void
|
||||||
|
|||||||
@@ -51,6 +51,15 @@ function LoadProfilesFromRegistry()
|
|||||||
profileNode.username = profile.username
|
profileNode.username = profile.username
|
||||||
profileNode.serverUrl = profile.serverUrl
|
profileNode.serverUrl = profile.serverUrl
|
||||||
profileNode.accessToken = profile.accessToken
|
profileNode.accessToken = profile.accessToken
|
||||||
|
|
||||||
|
profileNode.refreshToken = profile.refreshToken
|
||||||
|
profileNode.scope = profile.scope
|
||||||
|
profileNode.tokenType = profile.tokenType
|
||||||
|
profileNode.expiresIn = profile.expiresIn
|
||||||
|
profileNode.expiresTimestamp = profile.expiresTimestamp
|
||||||
|
profileNode.clientId = profile.clientId
|
||||||
|
profileNode.clientSecret = profile.clientSecret
|
||||||
|
|
||||||
profileNode.color = profile.color
|
profileNode.color = profile.color
|
||||||
|
|
||||||
profileNodes.Push(profileNode)
|
profileNodes.Push(profileNode)
|
||||||
@@ -157,6 +166,13 @@ function GetProfilesDto(includeAccessToken as boolean) as object
|
|||||||
|
|
||||||
if includeAccessToken
|
if includeAccessToken
|
||||||
profile["accessToken"] = profileNode.accessToken
|
profile["accessToken"] = profileNode.accessToken
|
||||||
|
profile["refreshToken"] = profileNode.refreshToken
|
||||||
|
profile["scope"] = profileNode.scope
|
||||||
|
profile["tokenType"] = profileNode.tokenType
|
||||||
|
profile["expiresIn"] = profileNode.expiresIn
|
||||||
|
profile["expiresTimestamp"] = profileNode.expiresTimestamp
|
||||||
|
profile["clientId"] = profileNode.clientId
|
||||||
|
profile["clientSecret"] = profileNode.clientSecret
|
||||||
end if
|
end if
|
||||||
|
|
||||||
userProfiles.profiles.Push(profile)
|
userProfiles.profiles.Push(profile)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||||
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
@asynctask
|
@asynctask
|
||||||
function ProfilesVerifyTokensTask(input as object) as object
|
function ProfilesVerifyTokensTask(input as object) as object
|
||||||
@@ -10,6 +11,9 @@ function ProfilesVerifyTokensTask(input as object) as object
|
|||||||
invalidProfiles = []
|
invalidProfiles = []
|
||||||
|
|
||||||
for each profileNode in profileContentNodes
|
for each profileNode in profileContentNodes
|
||||||
|
if not StringUtils.IsNullOrEmpty(profileNode.refreshToken)
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
if not service.VerifyTokenScope(profileNode.accessToken)
|
if not service.VerifyTokenScope(profileNode.accessToken)
|
||||||
invalidProfiles.push(profileNode)
|
invalidProfiles.push(profileNode)
|
||||||
end if
|
end if
|
||||||
|
|||||||
+148
@@ -20,6 +20,154 @@ namespace Http
|
|||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
@get("/playlet-invidious-backend/api/v1/auth/feed")
|
||||||
|
function GetAuthFeed(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
accessToken = request.headers["authorization"]
|
||||||
|
if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ")
|
||||||
|
response.Json({
|
||||||
|
"error": "Missing or invalid 'Authorization' header"
|
||||||
|
})
|
||||||
|
response.http_code = 403
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
options = {
|
||||||
|
"accessToken": accessToken.Mid("Bearer ".Len())
|
||||||
|
}
|
||||||
|
continuation = request.query.continuation
|
||||||
|
if not StringUtils.IsNullOrEmpty(continuation)
|
||||||
|
options.continuation = continuation
|
||||||
|
end if
|
||||||
|
|
||||||
|
feeds = InnertubeService.GetSubscriptions(options)
|
||||||
|
if feeds = invalid
|
||||||
|
response.Json({
|
||||||
|
"error": "Failed to get auth feed"
|
||||||
|
})
|
||||||
|
response.http_code = 500
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"videos": []
|
||||||
|
}
|
||||||
|
|
||||||
|
if feeds.Count() > 0
|
||||||
|
result["videos"] = ValidArray(feeds[0].items)
|
||||||
|
if feeds[0].DoesExist("continuation")
|
||||||
|
result["continuation"] = feeds[0].continuation
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
response.Json(result)
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
@get("/playlet-invidious-backend/api/v1/auth/subscriptions")
|
||||||
|
function GetAuthSubscriptions(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
accessToken = request.headers["authorization"]
|
||||||
|
if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ")
|
||||||
|
response.Json({
|
||||||
|
"error": "Missing or invalid 'Authorization' header"
|
||||||
|
})
|
||||||
|
response.http_code = 403
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
response.Json([])
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
@get("/playlet-invidious-backend/api/v1/auth/playlists")
|
||||||
|
function GetAuthPlaylists(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
accessToken = request.headers["authorization"]
|
||||||
|
if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ")
|
||||||
|
response.Json({
|
||||||
|
"error": "Missing or invalid 'Authorization' header"
|
||||||
|
})
|
||||||
|
response.http_code = 403
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
options = {
|
||||||
|
"accessToken": accessToken.Mid("Bearer ".Len())
|
||||||
|
}
|
||||||
|
continuation = request.query.continuation
|
||||||
|
if not StringUtils.IsNullOrEmpty(continuation)
|
||||||
|
options.continuation = continuation
|
||||||
|
end if
|
||||||
|
|
||||||
|
feeds = InnertubeService.GetPlaylists(options)
|
||||||
|
if feeds = invalid
|
||||||
|
response.Json({
|
||||||
|
"error": "Failed to get auth playlists"
|
||||||
|
})
|
||||||
|
response.http_code = 500
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
if feeds.Count() > 0
|
||||||
|
response.Json(feeds[0])
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
response.Json({
|
||||||
|
"items": []
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
@get("/playlet-invidious-backend/api/v1/auth/history")
|
||||||
|
function GetAuthHistory(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
accessToken = request.headers["authorization"]
|
||||||
|
if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ")
|
||||||
|
response.Json({
|
||||||
|
"error": "Missing or invalid 'Authorization' header"
|
||||||
|
})
|
||||||
|
response.http_code = 403
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
options = {
|
||||||
|
"accessToken": accessToken.Mid("Bearer ".Len())
|
||||||
|
}
|
||||||
|
continuation = request.query.continuation
|
||||||
|
if not StringUtils.IsNullOrEmpty(continuation)
|
||||||
|
options.continuation = continuation
|
||||||
|
end if
|
||||||
|
|
||||||
|
feeds = InnertubeService.GetWatchHistory(options)
|
||||||
|
if feeds = invalid
|
||||||
|
response.Json({
|
||||||
|
"error": "Failed to get auth history"
|
||||||
|
})
|
||||||
|
response.http_code = 500
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
if feeds.Count() > 0
|
||||||
|
response.Json(feeds[0])
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
response.Json({
|
||||||
|
"items": []
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
@get("/playlet-invidious-backend/api/v1/stats")
|
@get("/playlet-invidious-backend/api/v1/stats")
|
||||||
function GetStats(context as object) as boolean
|
function GetStats(context as object) as boolean
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ auth_playlists:
|
|||||||
title: Playlists
|
title: Playlists
|
||||||
url: /api/v1/auth/playlists
|
url: /api/v1/auth/playlists
|
||||||
authenticated: true
|
authenticated: true
|
||||||
|
paginationType: Continuation
|
||||||
|
|
||||||
playlist:
|
playlist:
|
||||||
title: Playlist
|
title: Playlist
|
||||||
|
|||||||
Reference in new issue
Block a user