diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f7724f4..4b6ad688 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
-- Nothing worth mentioning yet.
+### Fixed
+
+- Added `Visitor Data` to payload in Playlet backend
+ - Session data persists for 24 hours
+ - It reduces the privacy of the app, but can help with `Sign in to confirm you're not a bot errors`
+
+## Changed
+
+- Video queue view might be missing video titles and durations
+ - This is done to reduce the risk of rate limiting. No video titles in the queue is better than no videos playing at all.
+ - Only affects casting playlists from the YouTube mobile app.
## [0.36.0] - 2025-01-16
diff --git a/playlet-lib/src/components/MainScene.transpiled.xml b/playlet-lib/src/components/MainScene.transpiled.xml
index 21db3095..e19bc933 100644
--- a/playlet-lib/src/components/MainScene.transpiled.xml
+++ b/playlet-lib/src/components/MainScene.transpiled.xml
@@ -47,6 +47,7 @@
+
diff --git a/playlet-lib/src/components/MainScene.xml b/playlet-lib/src/components/MainScene.xml
index 6ec1d988..f177c2ee 100644
--- a/playlet-lib/src/components/MainScene.xml
+++ b/playlet-lib/src/components/MainScene.xml
@@ -56,6 +56,7 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeInitTask.bs b/playlet-lib/src/components/Services/Innertube/InnertubeInitTask.bs
new file mode 100644
index 00000000..310f3a8d
--- /dev/null
+++ b/playlet-lib/src/components/Services/Innertube/InnertubeInitTask.bs
@@ -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
diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
index 67a20036..b2add3d8 100644
--- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
+++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
@@ -18,6 +18,7 @@ namespace InnertubeService
cancellation = invalid
fetchNext = true
ctt = ""
+ visitorData = ""
raw = false
if options <> invalid
@@ -33,9 +34,12 @@ namespace InnertubeService
if options.DoesExist("raw")
raw = options.raw
end if
+ if options.DoesExist("visitorData")
+ visitorData = options.visitorData
+ end if
end if
- playerRequest = Innertube.CreatePlayerRequest(videoId, ctt)
+ playerRequest = Innertube.CreatePlayerRequest(videoId, ctt, visitorData)
playerRequest.Cancellation(cancellation)
playerRequest.Send()
diff --git a/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs b/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs
index 24e69ef4..8b385fd2 100644
--- a/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs
+++ b/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs
@@ -12,7 +12,7 @@ namespace Innertube
deviceInfo = CreateObject("roDeviceInfo")
payload = {
- "context": Innertube.CreateContext(Innertube.ClientType.Web, deviceInfo, ctt)
+ "context": Innertube.CreateContext(Innertube.ClientType.Web, deviceInfo, ctt, "")
}
payload.Append(payloadArgs)
diff --git a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs
index ae376eb6..9351d004 100644
--- a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs
+++ b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs
@@ -6,12 +6,12 @@ import "pkg:/source/utils/Types.bs"
namespace Innertube
- function CreatePlayerRequest(videoId as string, ctt as string) as object
+ function CreatePlayerRequest(videoId as string, ctt as string, visitorData as string) as object
deviceInfo = CreateObject("roDeviceInfo")
payload = {
"videoId": videoId
- "context": Innertube.CreateContext(Innertube.ClientType.IOS, deviceInfo, ctt)
+ "context": Innertube.CreateContext(Innertube.ClientType.IOS, deviceInfo, ctt, visitorData)
"playbackContext": {
"contentPlaybackContext": {
"vis": 0
diff --git a/playlet-lib/src/components/Services/Innertube/ResolveUrlEndpoint.bs b/playlet-lib/src/components/Services/Innertube/ResolveUrlEndpoint.bs
index d23b3427..137de711 100644
--- a/playlet-lib/src/components/Services/Innertube/ResolveUrlEndpoint.bs
+++ b/playlet-lib/src/components/Services/Innertube/ResolveUrlEndpoint.bs
@@ -6,7 +6,7 @@ namespace Innertube
deviceInfo = CreateObject("roDeviceInfo")
payload = {
- "context": CreateContext(ClientType.Web, deviceInfo, "")
+ "context": CreateContext(ClientType.Web, deviceInfo, "", "")
"url": url
}
diff --git a/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs b/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs
index 20b979ad..c28fbed1 100644
--- a/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs
+++ b/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs
@@ -10,7 +10,7 @@ namespace Innertube
deviceInfo = CreateObject("roDeviceInfo")
payload = {
- context: Innertube.CreateContext(Innertube.ClientType.WEB, deviceInfo, "")
+ context: Innertube.CreateContext(Innertube.ClientType.WEB, deviceInfo, "", "")
}
if continuation <> ""
diff --git a/playlet-lib/src/components/Services/Innertube/SessionData.bs b/playlet-lib/src/components/Services/Innertube/SessionData.bs
new file mode 100644
index 00000000..3bd29fae
--- /dev/null
+++ b/playlet-lib/src/components/Services/Innertube/SessionData.bs
@@ -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
diff --git a/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs b/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
index e12b4449..b9dc128f 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoContentTask.bs
@@ -5,6 +5,7 @@ import "pkg:/components/Services/Invidious/InvidiousService.bs"
function VideoContentTask(input as object) as object
contentNode = input.content
invidiousNode = input.invidious
+ innertubeNode = input.innertube
preferencesNode = input.preferences
loungeServiceNode = input.loungeService
playletServerPort = input.playletServerPort
@@ -22,8 +23,9 @@ function VideoContentTask(input as object) as object
backend = preferencesNode["playback.backend"]
if backend = "playlet"
metadata = InnertubeService.GetVideoMetadata(contentNode.videoId, {
- cancellation: m.top.cancellation
- ctt: loungeServiceNode.ctt
+ "cancellation": m.top.cancellation
+ "ctt": loungeServiceNode.ctt
+ "visitorData": innertubeNode.visitorData
})
else
metadata = service.GetVideoMetadata(contentNode.videoId, { cancellation: m.top.cancellation })
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
index 4cf9cef3..4ae43cfe 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
@@ -151,6 +151,7 @@ function StartVideoContentTask(videoContentNode as object)
m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTask, {
content: videoContentNode
invidious: m.top.invidious
+ innertube: m.top.innertube
preferences: m.top.preferences
loungeService: m.top.loungeService
playletServerPort: m.top.webServer.port
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
index 62d985a8..1530be11 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
@@ -5,6 +5,7 @@
+
diff --git a/playlet-lib/src/components/VideoQueue/VideoQueue.xml b/playlet-lib/src/components/VideoQueue/VideoQueue.xml
index 3393f45d..46fa6ba4 100644
--- a/playlet-lib/src/components/VideoQueue/VideoQueue.xml
+++ b/playlet-lib/src/components/VideoQueue/VideoQueue.xml
@@ -22,6 +22,7 @@
+
diff --git a/playlet-lib/src/components/VideoQueue/VideoQueueView.bs b/playlet-lib/src/components/VideoQueue/VideoQueueView.bs
index 41c02488..d7d7c2f0 100644
--- a/playlet-lib/src/components/VideoQueue/VideoQueueView.bs
+++ b/playlet-lib/src/components/VideoQueue/VideoQueueView.bs
@@ -57,7 +57,11 @@ function OnContentSet() as void
end if
AdjustFocus(videoCount)
- LoadVideoDetailsIfNeeded()
+ ' TODO:P1 LoadVideoDetailsIfNeeded is disabled for now.
+ ' Trying to fetch video info (especially one by one) can lead to rate limiting.
+ ' That would result in all videos being blocked. So for now, this is just a
+ ' nice to have, and should not be used.
+ ' LoadVideoDetailsIfNeeded()
end function
function OnKeyEvent(key as string, press as boolean) as boolean
@@ -143,6 +147,7 @@ function LoadVideoDetailsIfNeeded() as void
m.loadDetailsTask = AsyncTask.Start(Tasks.VideoQueueViewContentTask, {
videoNodes: m.videosDetailsToLoad
+ innertube: m.top.innertube
invidious: m.top.invidious
preferences: m.top.preferences
index: indexInLoadingArray
diff --git a/playlet-lib/src/components/VideoQueue/VideoQueueView.xml b/playlet-lib/src/components/VideoQueue/VideoQueueView.xml
index 70b9d044..7a409484 100644
--- a/playlet-lib/src/components/VideoQueue/VideoQueueView.xml
+++ b/playlet-lib/src/components/VideoQueue/VideoQueueView.xml
@@ -4,6 +4,7 @@
+
diff --git a/playlet-lib/src/components/VideoQueue/VideoQueueViewContentTask.bs b/playlet-lib/src/components/VideoQueue/VideoQueueViewContentTask.bs
index c7c398f1..a56cf071 100644
--- a/playlet-lib/src/components/VideoQueue/VideoQueueViewContentTask.bs
+++ b/playlet-lib/src/components/VideoQueue/VideoQueueViewContentTask.bs
@@ -7,6 +7,7 @@ import "pkg:/source/utils/MathUtils.bs"
@asynctask
function VideoQueueViewContentTask(input as object) as object
videoNodes = input.videoNodes
+ innertubeNode = input.innertube
invidiousNode = input.invidious
preferencesNode = input.preferences
service = new Invidious.InvidiousService(invidiousNode)
@@ -22,6 +23,7 @@ function VideoQueueViewContentTask(input as object) as object
cancellation: cancellation
tryCount: 1
fetchNext: false
+ visitorData: innertubeNode.visitorData
}
' TODO:P1: Use InnertubeService.GetVideoInfoBatched instead of loading each video individually
diff --git a/playlet-lib/src/components/VideoQueue/VideoQueueViewUtils.bs b/playlet-lib/src/components/VideoQueue/VideoQueueViewUtils.bs
index 55e52695..423e2911 100644
--- a/playlet-lib/src/components/VideoQueue/VideoQueueViewUtils.bs
+++ b/playlet-lib/src/components/VideoQueue/VideoQueueViewUtils.bs
@@ -6,6 +6,7 @@ namespace VideoQueueViewUtils
videoQueueView = CreateObject("roSGNode", "VideoQueueView")
videoQueueView.videoQueue = videoQueue
videoQueueView.appController = appController
+ videoQueueView.innertube = videoQueue.innertube
videoQueueView.invidious = videoQueue.invidious
videoQueueView.preferences = videoQueue.preferences
appController@.PushScreen(videoQueueView)
diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs
index 0382934a..c34e6a09 100644
--- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs
+++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs
@@ -5,8 +5,10 @@ namespace Http
class PlayletInvidiousBackendRouter extends HttpRouter
- function new()
+ function new(server as object)
super()
+
+ m.innertube = server.task.innertube
end function
@get("/playlet-invidious-backend/authorize_token")
@@ -426,7 +428,8 @@ namespace Http
raw = request.query.raw <> invalid
options = {
- raw: raw
+ "raw": raw
+ "visitorData": m.innertube.visitorData
}
metadata = InnertubeService.GetVideoMetadata(videoId, options)
diff --git a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs
index af220c2a..fc4c34ce 100644
--- a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs
+++ b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs
@@ -56,7 +56,7 @@ function SetupRoutes(server as object)
server.UseRouter(new Http.DialRouter(server))
server.UseRouter(new Http.CacheRouter())
server.UseRouter(new Http.RegistryRouter(server))
- server.UseRouter(new Http.PlayletInvidiousBackendRouter())
+ server.UseRouter(new Http.PlayletInvidiousBackendRouter(server))
etags = new Http.EtagUtils()
server.UseRouter(new Http.HttpStaticFilesRouter("/", "libpkg:/www", etags, { staticFiles: true, staticCompressed: true }))
diff --git a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.xml b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.xml
index a3ba7ad4..5a40f100 100644
--- a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.xml
+++ b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.xml
@@ -2,6 +2,7 @@
+
diff --git a/playlet-lib/src/source/utils/RegistryUtils.bs b/playlet-lib/src/source/utils/RegistryUtils.bs
index 5780af61..f305cbad 100644
--- a/playlet-lib/src/source/utils/RegistryUtils.bs
+++ b/playlet-lib/src/source/utils/RegistryUtils.bs
@@ -10,6 +10,7 @@ namespace RegistryUtils
const BOOKMARKS = "bookmarks"
const MESSAGES = "messages"
+ const INNERTUBE_SESSION_DATA = "innertube_session_data"
const LAST_LOUNGE_DATA = "last_lounge_data"
' "invidious_instances" is deprecated, but we keep for migration purposes