mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2026-01-30 02:32:45 +00:00
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:
@@ -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
|
||||
Reference in New Issue
Block a user