From 3bc25cc2d10f8489e3452b9e10bda605f0447298 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sun, 6 Jul 2025 20:38:00 -0400 Subject: [PATCH] Use web safari for playback (#673) * Use web safari for playback * user agent --- CHANGELOG.md | 4 ++ .../Services/Innertube/Constants.bs | 13 ++++++- .../components/Services/Innertube/Context.bs | 37 +++++++++++++++++++ .../Services/Innertube/InnertubeService.bs | 2 +- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 219e907e..f3a13d76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +- Experiment: use web safari for `/player` endpoint + ## [0.40.9] - 2025-07-06 ### Fixed diff --git a/playlet-lib/src/components/Services/Innertube/Constants.bs b/playlet-lib/src/components/Services/Innertube/Constants.bs index 1024f9b5..68c02c2c 100644 --- a/playlet-lib/src/components/Services/Innertube/Constants.bs +++ b/playlet-lib/src/components/Services/Innertube/Constants.bs @@ -1,4 +1,5 @@ -const VIDEO_PLAYER_USER_AGENT = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0" +' const VIDEO_PLAYER_USER_AGENT = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0" +const VIDEO_PLAYER_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15" const INNERTUBE_IOS_CLIENT_NAME = "5" const INNERTUBE_IOS_CLIENT_VERSION = "20.20.5" @@ -6,6 +7,16 @@ const INNERTUBE_IOS_DEVICE_MODEL = "iPhone16,2" const INNERTUBE_IOS_OS_VERSION = "18.1" const INNERTUBE_IOS_USER_AGENT = "com.google.ios.youtube/20.20.5 (iPhone16,2; U; CPU iOS 18_1_0 like Mac OS X)" +const INNERTUBE_WEB_SAFARI_BROWSER_NAME = "Safari" +const INNERTUBE_WEB_SAFARI_BROWSER_VERSION = "17.6" +const INNERTUBE_WEB_SAFARI_CLIENT_NAME = "1" +const INNERTUBE_WEB_SAFARI_CLIENT_VERSION = "2.20250701.09.00" +const INNERTUBE_WEB_SAFARI_DEVICE_MAKE = "Apple" +const INNERTUBE_WEB_SAFARI_DEVICE_MODEL = "" +const INNERTUBE_WEB_SAFARI_OS_NAME = "Macintosh" +const INNERTUBE_WEB_SAFARI_OS_VERSION = "10_15_7" +const INNERTUBE_WEB_SAFARI_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15" + const INNERTUBE_WEB_BROWSER_NAME = "Chrome" const INNERTUBE_WEB_BROWSER_VERSION = "136.0.0.0" const INNERTUBE_WEB_CLIENT_NAME = "1" diff --git a/playlet-lib/src/components/Services/Innertube/Context.bs b/playlet-lib/src/components/Services/Innertube/Context.bs index 796b59a3..f8269563 100644 --- a/playlet-lib/src/components/Services/Innertube/Context.bs +++ b/playlet-lib/src/components/Services/Innertube/Context.bs @@ -8,6 +8,7 @@ namespace Innertube Web = "WEB" IOS = "IOS" Tv = "TV" + WebSafari = "WEB_SAFARI" end enum function CreateHeaders(clienType as Innertube.ClientType) as object @@ -35,6 +36,14 @@ namespace Innertube "x-youtube-client-name": INNERTUBE_TV_CLIENT_NAME "x-youtube-client-version": INNERTUBE_TV_CLIENT_VERSION } + else if clienType = ClientType.WebSafari + return { + "accept": "*/*" + "accept-language": "*" + "user-agent": INNERTUBE_WEB_SAFARI_USER_AGENT + "x-youtube-client-name": INNERTUBE_WEB_SAFARI_CLIENT_NAME + "x-youtube-client-version": INNERTUBE_WEB_SAFARI_CLIENT_VERSION + } else throw "Invalid client type" end if @@ -48,6 +57,8 @@ namespace Innertube client = CreateContextClientIOS(deviceInfo) else if clienType = ClientType.Tv client = CreateContextClientTv(deviceInfo) + else if clienType = ClientType.WebSafari + client = CreateContextClientWebSafari(deviceInfo) else throw "Invalid client type" end if @@ -177,6 +188,32 @@ namespace Innertube } end function + function CreateContextClientWebSafari(deviceInfo as object) as object + return { + "hl": GetCurrentLocale(deviceInfo) + "gl": GetContentRegion(deviceInfo) + "remoteHost": "" + "screenDensityFloat": 1 + "screenHeightPoints": 1440 + "screenPixelDensity": 1 + "screenWidthPoints": 2560 + "clientName": INNERTUBE_WEB_SAFARI_CLIENT_NAME + "clientVersion": INNERTUBE_WEB_SAFARI_CLIENT_VERSION + "osName": INNERTUBE_WEB_SAFARI_OS_NAME + "osVersion": INNERTUBE_WEB_SAFARI_OS_VERSION + "platform": "DESKTOP" + "clientFormFactor": "UNKNOWN_FORM_FACTOR" + "userInterfaceTheme": "USER_INTERFACE_THEME_LIGHT" + "timeZone": deviceInfo.GetTimeZone() + "originalUrl": "https://www.youtube.com" + "deviceMake": INNERTUBE_WEB_SAFARI_DEVICE_MAKE + "deviceModel": INNERTUBE_WEB_SAFARI_DEVICE_MODEL + "browserName": INNERTUBE_WEB_SAFARI_BROWSER_NAME + "browserVersion": INNERTUBE_WEB_SAFARI_BROWSER_VERSION + "utcOffsetMinutes": -240 + } + end function + function GetCurrentLocale(deviceInfo as object) as string currentLocale = deviceInfo.GetCurrentLocale() ' en_CA is not a valid locale for Innertube diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs index 2b8737fe..c93c59b7 100644 --- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs +++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs @@ -21,7 +21,7 @@ namespace InnertubeService fetchNext = OptionUtils.GetOrDefault(options, "fetchNext", true) raw = OptionUtils.GetOrDefault(options, "raw", false) - playerRequest = Innertube.CreatePlayerRequest(videoId, Innertube.ClientType.IOS, options) + playerRequest = Innertube.CreatePlayerRequest(videoId, Innertube.ClientType.WebSafari, options) playerRequest.Cancellation(cancellation) if raw playerRequest.LogCurlCommand()