fix(companion): skip inv-sig-helper when Invidious Companion is enabled

- parser: skip decrypt_signature/decrypt_nsig when CONFIG.invidious_companion.present?

- youtube_api: avoid signatureTimestamp (STS) lookup under Companion

Aligns with the deprecation of inv-sig-helper in favor of Invidious Companion. No behavior change when Companion is disabled.

Refs: iv-org/invidious#5423
This commit is contained in:
naoNao89 2025-08-22 01:24:39 +07:00
parent 8ed07a58d4
commit 93c4a6bf26
2 changed files with 19 additions and 4 deletions

View File

@ -542,14 +542,25 @@ private def convert_url(fmt)
LOGGER.debug("convert_url: Decoding '#{cfr}'")
unsig = DECRYPT_FUNCTION.try &.decrypt_signature(cfr["s"])
# When using Invidious Companion, streaming URLs should already be usable.
# Skip inv-sig-helper based signature decryption in that case.
unsig = if CONFIG.invidious_companion.present?
nil
else
DECRYPT_FUNCTION.try &.decrypt_signature(cfr["s"])
end
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"])
# Skip nsig decryption when using Invidious Companion
n = if CONFIG.invidious_companion.present?
nil
else
DECRYPT_FUNCTION.try &.decrypt_nsig(params["n"])
end
params["n"] = n if n
if token = CONFIG.po_token

View File

@ -473,8 +473,12 @@ module YoutubeAPI
} of String => String | Int64
if {"WEB", "TVHTML5"}.any? { |s| client_config.name.starts_with? s }
if sts = DECRYPT_FUNCTION.try &.get_sts
playback_ctx["signatureTimestamp"] = sts.to_i64
# When using Invidious Companion, player requests are proxied there,
# so we skip fetching signatureTimestamp via inv-sig-helper.
if !CONFIG.invidious_companion.present?
if sts = DECRYPT_FUNCTION.try &.get_sts
playback_ctx["signatureTimestamp"] = sts.to_i64
end
end
end