-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
162 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import "pkg:/components/Services/Innertube/Constants.bs" | ||
import "pkg:/source/AsyncTask/AsyncTask.bs" | ||
import "pkg:/source/AsyncTask/Tasks.bs" | ||
|
||
function Init() | ||
AsyncTask.Start(Tasks.InnertubeInitTask, { | ||
innertube: m.top | ||
}) | ||
end function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<component name="Innertube" extends="Node"> | ||
<interface> | ||
<field id="visitorData" type="string" /> | ||
</interface> | ||
</component> |
15 changes: 15 additions & 0 deletions
15
playlet-lib/src/components/Services/Innertube/InnertubeInitTask.bs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import "pkg:/components/Services/Innertube/SessionData.bs" | ||
|
||
@asynctask | ||
function InnertubeInitTask(input as object) as object | ||
innertubeNode = input.innertube | ||
|
||
sessionData = Innertube.GetSessionData() | ||
if sessionData = invalid | ||
return invalid | ||
end if | ||
|
||
innertubeNode.visitorData = sessionData.visitorData | ||
|
||
return invalid | ||
end function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
playlet-lib/src/components/Services/Innertube/SessionData.bs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import "pkg:/components/Services/Innertube/Constants.bs" | ||
import "pkg:/source/services/HttpClient.bs" | ||
import "pkg:/source/utils/Logging.bs" | ||
import "pkg:/source/utils/ObjectUtils.bs" | ||
import "pkg:/source/utils/RegistryUtils.bs" | ||
import "pkg:/source/utils/StringUtils.bs" | ||
import "pkg:/source/utils/TimeUtils.bs" | ||
|
||
namespace Innertube | ||
|
||
const SESSION_DATA_VERSION = 1 | ||
const INNERTUBE_VISITOR_DATA_LIFESPAN = 1000 * 60 * 60 * 24 | ||
|
||
function GetSessionData() as object | ||
sessionData = ReadSessionDataFromRegistry() | ||
if sessionData <> invalid | ||
return sessionData | ||
end if | ||
|
||
sessionData = RequestSessionData() | ||
if sessionData = invalid | ||
return invalid | ||
end if | ||
|
||
RegistryUtils.Write(RegistryUtils.INNERTUBE_SESSION_DATA, FormatJson(sessionData)) | ||
return sessionData | ||
end function | ||
|
||
function RequestSessionData() as object | ||
request = HttpClient.Get("https://www.youtube.com/sw.js_data") | ||
request.Headers({ | ||
"Accept-Language": "en-US,en;q=0.9" | ||
"User-Agent": INNERTUBE_WEB_USER_AGENT | ||
"Accept": "*/*" | ||
"Referer": "https://www.youtube.com/sw.js" | ||
}) | ||
|
||
response = request.Await() | ||
if not response.IsSuccess() | ||
LogError("Failed to fetch session data", response.ErrorMessage()) | ||
return invalid | ||
end if | ||
|
||
text = ValidString(response.Text()) | ||
if not text.StartsWith(")]}'") | ||
LogError("Invalid session data response", text) | ||
return invalid | ||
end if | ||
|
||
text = text.Replace(")]}'", "") | ||
json = ParseJson(text) | ||
if json = invalid | ||
LogError("Failed to parse session data", text) | ||
return invalid | ||
end if | ||
|
||
visitorData = ObjectUtils.Dig(json, [0, 2, 0, 0, 13]) | ||
if StringUtils.IsNullOrEmpty(visitorData) | ||
LogError("Visitor data not found", text) | ||
return invalid | ||
end if | ||
|
||
return { | ||
"__version": SESSION_DATA_VERSION | ||
"timestamp": TimeUtils.Now().AsSeconds() | ||
"visitorData": visitorData | ||
} | ||
end function | ||
|
||
function ReadSessionDataFromRegistry() as object | ||
sessionData = RegistryUtils.Read(RegistryUtils.INNERTUBE_SESSION_DATA) | ||
if StringUtils.IsNullOrEmpty(sessionData) | ||
return invalid | ||
end if | ||
|
||
sessionData = ParseJson(sessionData) | ||
if sessionData = invalid | ||
RegistryUtils.Delete(RegistryUtils.INNERTUBE_SESSION_DATA) | ||
return invalid | ||
end if | ||
|
||
timestamp = sessionData.timestamp | ||
nowSeconds = TimeUtils.Now().AsSeconds() | ||
if nowSeconds - timestamp > INNERTUBE_VISITOR_DATA_LIFESPAN | ||
RegistryUtils.Delete(RegistryUtils.INNERTUBE_SESSION_DATA) | ||
return invalid | ||
end if | ||
|
||
return sessionData | ||
end function | ||
end namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.