-
Notifications
You must be signed in to change notification settings - Fork 0
Yt script #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Yt script #8
Changes from all commits
34c4f9d
8325ed7
d950406
9b3e8c7
2d8668c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| sub init() | ||
| m.global.http.request = { payload: { | ||
| m.http = createObject("roSGNode", "httpTask") | ||
| m.http.control = "RUN" | ||
| m.http.request = { payload: { | ||
| userId: 1, | ||
| title: "WOW, IT WORKED ^_^", | ||
| }, url: "https://jsonplaceholder.typicode.com/albums", requestType: "GET"} | ||
| m.global.http.observeFieldScoped("response", "useResponse") | ||
| }, url: "https://www.youtube.com/watch?v=1FL22N1EXDo", requestType: "GET" } | ||
| m.http.observeFieldScoped("response", "useResponse") | ||
| end sub | ||
|
|
||
| sub useResponse() | ||
| ?m.global.http.response | ||
| initialPlayerResponseRegEx = createObject("roRegex", "ytInitialPlayerResponse\s*=\s*({.+?})\s*;", "m") | ||
| matches = initialPlayerResponseRegEx.match(m.http.response.body) | ||
| ?ParseJson(matches[1]).streamingData.adaptiveFormats[0].url | ||
| end sub | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,15 +14,15 @@ function handleCalls() as Object | |
| response = fire(msg.getData()) | ||
| end if | ||
| else if msgType = "roUrlEvent" | ||
| if msg.getInt() = 1 | ||
| if msg.getResponseCode() > 0 | ||
| response = handleResponse(msg.getString(),msg,true) | ||
| else | ||
| response = handleResponse(msg.getFailureReason(),msg,false) | ||
| end if | ||
| if msg.getInt() = 1 | ||
| if msg.getResponseCode() > 0 | ||
| response = handleResponse(msg.getString(), msg, true) | ||
| else | ||
| response = handleResponse(msg.getFailureReason(), msg, false) | ||
| end if | ||
| m.top.response = response | ||
| return response | ||
| end if | ||
| m.top.response = response | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, we don't need it's return |
||
| return response | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean that we can handle only a single request? If yes then
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we'll save the request's result in the response's AA and after resolving it we'll clear it's index |
||
| end if | ||
| end while | ||
| end function | ||
|
|
@@ -31,7 +31,7 @@ function fire(request as Object) as Object | |
| httpRequest = initiateHttpClient(request.url) | ||
| requestId = httpRequest.getIdentity().ToStr() | ||
| m.urlRequest[requestId] = { | ||
|
Comment on lines
32
to
33
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better: m.urlRequest[httpRequest.getIdentity().ToStr()] = {
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| request:httpRequest | ||
| request: httpRequest | ||
| } | ||
| if checkRequestType(request.requestType) | ||
| httpRequest.AsyncPostFromString(formatJson(request.payload)) | ||
|
|
@@ -42,15 +42,15 @@ end function | |
|
|
||
| function handleResponse(responseString as String, message as Object, isOk as Boolean) as Object | ||
| if isOk | ||
| body = parseJson(responseString) | ||
| body = responseString | ||
| else | ||
| body = "An Error has Occurred!!" | ||
| end if | ||
| requestId = message.GetSourceIdentity().ToStr() | ||
| m.urlRequest[requestId] = invalid | ||
| requestId = message.GetSourceIdentity().ToStr() | ||
| m.urlRequest[requestId] = invalid | ||
| return { | ||
| requestId: requestId | ||
| body:body | ||
| body: body | ||
| } | ||
| end function | ||
|
|
||
|
|
@@ -60,9 +60,7 @@ function initiateHttpClient(url as String) as Object | |
| httpRequest.InitClientCertificates() | ||
| httpRequest.SetPort(m.port) | ||
| httpRequest.SetUrl(url) | ||
| httpRequest.RetainBodyOnError(true) | ||
| httpRequest.addHeader("Content-Type", "application/json") | ||
| httpRequest.addHeader("Accept", "application/json") | ||
| httpRequest.RetainBodyOnError(false) | ||
| return httpRequest | ||
| end function | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ | |
| <field id="request" type="assocarray" /> | ||
| <field id="response" type="assocarray" /> | ||
| </interface> | ||
| <children></children> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No needed.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it |
||
| </component> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should request after we observe the field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done