tokens: use http instead of redis to get the tokens
It should be compatible with github.com/iv-org/youtube-trusted-session-generator
This commit is contained in:
parent
91bcec72c8
commit
58c4d8c951
5 changed files with 41 additions and 46 deletions
|
@ -213,8 +213,10 @@ if !CONFIG.external_videoplayback_proxy.empty?
|
||||||
Invidious::Jobs.register Invidious::Jobs::CheckExternalProxy.new
|
Invidious::Jobs.register Invidious::Jobs::CheckExternalProxy.new
|
||||||
end
|
end
|
||||||
|
|
||||||
if CONFIG.refresh_tokens
|
if !CONFIG.tokens_server.empty?
|
||||||
Invidious::Jobs.register Invidious::Jobs::RefreshTokens.new
|
Invidious::Jobs.register Invidious::Jobs::RefreshTokens.new
|
||||||
|
else
|
||||||
|
LOGGER.info("jobs: Disabling RefreshTokens job. Invidious will use the tokens that are on the configuration file")
|
||||||
end
|
end
|
||||||
|
|
||||||
Invidious::Jobs.start_all
|
Invidious::Jobs.start_all
|
||||||
|
|
|
@ -192,15 +192,14 @@ class Config
|
||||||
# at the start of the URI
|
# at the start of the URI
|
||||||
property external_videoplayback_proxy : Array(NamedTuple(url: String, balance: Bool)) = [] of NamedTuple(url: String, balance: Bool)
|
property external_videoplayback_proxy : Array(NamedTuple(url: String, balance: Bool)) = [] of NamedTuple(url: String, balance: Bool)
|
||||||
|
|
||||||
# Job to refresh tokens from a Redis compatible DB
|
|
||||||
property refresh_tokens : Bool = true
|
|
||||||
|
|
||||||
property pubsub_domain : String = ""
|
property pubsub_domain : String = ""
|
||||||
|
|
||||||
property ignore_user_tokens : Bool = false
|
property ignore_user_tokens : Bool = false
|
||||||
|
|
||||||
property server_id_cookie_name : String = "INVIDIOUS_SERVER_ID"
|
property server_id_cookie_name : String = "INVIDIOUS_SERVER_ID"
|
||||||
|
|
||||||
|
property tokens_server : String = ""
|
||||||
|
|
||||||
{% if flag?(:linux) %}
|
{% if flag?(:linux) %}
|
||||||
property reload_config_automatically : Bool = true
|
property reload_config_automatically : Bool = true
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
module Tokens
|
|
||||||
extend self
|
|
||||||
@@po_token : String | Nil
|
|
||||||
@@visitor_data : String | Nil
|
|
||||||
|
|
||||||
def refresh_tokens
|
|
||||||
@@po_token = REDIS_DB.get("invidious:po_token")
|
|
||||||
@@visitor_data = REDIS_DB.get("invidious:visitor_data")
|
|
||||||
if !@@po_token.nil? && !@@visitor_data.nil?
|
|
||||||
set_tokens
|
|
||||||
LOGGER.debug("RefreshTokens: Successfully updated po_token and visitor_data")
|
|
||||||
else
|
|
||||||
LOGGER.warn("RefreshTokens: Tokens are empty!")
|
|
||||||
end
|
|
||||||
LOGGER.trace("RefreshTokens: Tokens are:")
|
|
||||||
LOGGER.trace("RefreshTokens: po_token: #{CONFIG.po_token}")
|
|
||||||
LOGGER.trace("RefreshTokens: visitor_data: #{CONFIG.visitor_data}")
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_tokens
|
|
||||||
CONFIG.po_token = @@po_token
|
|
||||||
CONFIG.visitor_data = @@visitor_data
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_tokens
|
|
||||||
return {@@po_token, @@visitor_data}
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_po_token
|
|
||||||
return @@po_token
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_visitor_data
|
|
||||||
return @@visitor_data
|
|
||||||
end
|
|
||||||
end
|
|
35
src/invidious/helpers/session_tokens.cr
Normal file
35
src/invidious/helpers/session_tokens.cr
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
module Tokens
|
||||||
|
extend self
|
||||||
|
@@po_token : String | Nil
|
||||||
|
@@visitor_data : String | Nil
|
||||||
|
|
||||||
|
def refresh_tokens
|
||||||
|
begin
|
||||||
|
response = HTTP::Client.get "#{CONFIG.tokens_server}/generate"
|
||||||
|
if !response.status_code == 200
|
||||||
|
LOGGER.error("RefreshTokens: Expected response to have status code 200 but got #{response.status_code} from #{CONFIG.tokens_server}")
|
||||||
|
end
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
@@po_token = json.try &.["potoken"].as_s || nil
|
||||||
|
@@visitor_data = json.try &.["visitorData"].as_s || nil
|
||||||
|
rescue ex
|
||||||
|
LOGGER.error("RefreshTokens: Failed to fetch tokens from #{CONFIG.tokens_server}: #{ex.message}")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if !@@po_token.nil? && !@@visitor_data.nil?
|
||||||
|
set_tokens
|
||||||
|
LOGGER.debug("RefreshTokens: Successfully updated po_token and visitor_data")
|
||||||
|
else
|
||||||
|
LOGGER.warn("RefreshTokens: Tokens are empty!. Invidious will use the tokens that are on the configuration file")
|
||||||
|
end
|
||||||
|
LOGGER.trace("RefreshTokens: Tokens are:")
|
||||||
|
LOGGER.trace("RefreshTokens: po_token: #{CONFIG.po_token}")
|
||||||
|
LOGGER.trace("RefreshTokens: visitor_data: #{CONFIG.visitor_data}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_tokens
|
||||||
|
CONFIG.po_token = @@po_token
|
||||||
|
CONFIG.visitor_data = @@visitor_data
|
||||||
|
end
|
||||||
|
end
|
|
@ -54,11 +54,6 @@ def extract_video_info(video_id : String)
|
||||||
# Init client config for the API
|
# Init client config for the API
|
||||||
client_config = YoutubeAPI::ClientConfig.new
|
client_config = YoutubeAPI::ClientConfig.new
|
||||||
|
|
||||||
redis_po_token, redis_visitor_data = Tokens.get_tokens
|
|
||||||
|
|
||||||
po_token = redis_po_token || CONFIG.po_token
|
|
||||||
visitor_data = redis_visitor_data || CONFIG.visitor_data
|
|
||||||
|
|
||||||
# Fetch data from the player endpoint
|
# Fetch data from the player endpoint
|
||||||
player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config)
|
player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config)
|
||||||
|
|
||||||
|
@ -109,7 +104,7 @@ def extract_video_info(video_id : String)
|
||||||
|
|
||||||
# Don't use Android test suite client if po_token is passed because po_token doesn't
|
# Don't use Android test suite client if po_token is passed because po_token doesn't
|
||||||
# work for Android test suite client.
|
# work for Android test suite client.
|
||||||
if reason.nil? && po_token.nil?
|
if reason.nil? && CONFIG.po_token.nil?
|
||||||
# Fetch the video streams using an Android client in order to get the
|
# Fetch the video streams using an Android client in order to get the
|
||||||
# decrypted URLs and maybe fix throttling issues (#2194). See the
|
# decrypted URLs and maybe fix throttling issues (#2194). See the
|
||||||
# following issue for an explanation about decrypted URLs:
|
# following issue for an explanation about decrypted URLs:
|
||||||
|
|
Loading…
Reference in a new issue