Skip to content

Invidious is an alternative front-end to YouTube

Add ability to set po_token and visitordata ID (#4789)

Samantaz Fox2d18ff1f80aa
diff --cc src/invidious/videos.cr
index c44a8f46,44ed53ee..0d26b395
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@@ -98,39 -98,6 +98,40 @@@ struct Vide
# Methods for parsing streaming data
+ def convert_url(fmt)
+ if cfr = fmt["signatureCipher"]?.try { |json| HTTP::Params.parse(json.as_s) }
+ sp = cfr["sp"]
+ url = URI.parse(cfr["url"])
+ params = url.query_params
+
+ LOGGER.debug("Videos: Decoding '#{cfr}'")
+
+ unsig = DECRYPT_FUNCTION.try &.decrypt_signature(cfr["s"])
+ params[sp] = unsig if unsig
+ else
+ url = URI.parse(fmt["url"].as_s)
+ params = url.query_params
+ end
+
+ n = DECRYPT_FUNCTION.try &.decrypt_nsig(params["n"])
+ params["n"] = n if n
++ params["pot"] = CONFIG.po_token if CONFIG.po_token
+
+ params["host"] = url.host.not_nil!
+ if region = self.info["region"]?.try &.as_s
+ params["region"] = region
+ end
+
+ url.query_params = params
+ LOGGER.trace("Videos: new url is '#{url}'")
+
+ return url.to_s
+ rescue ex
+ LOGGER.debug("Videos: Error when parsing video URL")
+ LOGGER.trace(ex.inspect_with_backtrace)
+ return ""
+ end
+
def fmt_stream
return @fmt_stream.as(Array(Hash(String, JSON::Any))) if @fmt_stream
diff --cc src/invidious/yt_backend/youtube_api.cr
index 09a5e7f4,0efbe949..6d585bf2
--- a/src/invidious/yt_backend/youtube_api.cr
+++ b/src/invidious/yt_backend/youtube_api.cr
@@@ -475,8 -467,13 +479,11 @@@ module YoutubeAP
"lockedSafetyMode" => false,
},
"playbackContext" => {
- "contentPlaybackContext" => {
- "html5Preference": "HTML5_PREF_WANTS",
- },
+ "contentPlaybackContext" => playback_ctx,
},
+ "serviceIntegrityDimensions" => {
+ "poToken" => CONFIG.po_token,
+ },
}
# Append the additional parameters if those were provided