Tokens: Refresh po_token and visitor_data every 5 seconds
All checks were successful
Invidious CI / build (push) Successful in 8m45s
All checks were successful
Invidious CI / build (push) Successful in 8m45s
Closes #11
This commit is contained in:
parent
6587528ed9
commit
66b481713d
6 changed files with 46 additions and 10 deletions
|
@ -193,6 +193,10 @@ if !CONFIG.external_videoplayback_proxy.empty?
|
|||
Invidious::Jobs.register Invidious::Jobs::CheckExternalProxy.new
|
||||
end
|
||||
|
||||
if CONFIG.refresh_tokens
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshTokens.new
|
||||
end
|
||||
|
||||
Invidious::Jobs.start_all
|
||||
|
||||
def popular_videos
|
||||
|
|
|
@ -184,6 +184,9 @@ class Config
|
|||
# at the start of the URI
|
||||
property external_videoplayback_proxy : Array(String) = [] of String
|
||||
|
||||
# Job to refresh tokens from a Redis compatible DB
|
||||
property refresh_tokens : Bool = true
|
||||
|
||||
# Materialious redirects
|
||||
property materialious_domain : String?
|
||||
|
||||
|
|
25
src/invidious/helpers/redis_tokens.cr
Normal file
25
src/invidious/helpers/redis_tokens.cr
Normal file
|
@ -0,0 +1,25 @@
|
|||
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")
|
||||
LOGGER.debug("RefreshTokens: Tokens are:")
|
||||
LOGGER.debug("RefreshTokens: po_token: #{@@po_token}")
|
||||
LOGGER.debug("RefreshTokens: 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
|
|
@ -397,11 +397,3 @@ def gen_videoplayback_proxy_list
|
|||
end
|
||||
return external_videoplayback_proxy
|
||||
end
|
||||
|
||||
def get_po_token
|
||||
REDIS_DB.get("invidious:po_token")
|
||||
end
|
||||
|
||||
def get_visitor_data
|
||||
REDIS_DB.get("invidious:visitor_data")
|
||||
end
|
13
src/invidious/jobs/refresh_tokens.cr
Normal file
13
src/invidious/jobs/refresh_tokens.cr
Normal file
|
@ -0,0 +1,13 @@
|
|||
class Invidious::Jobs::RefreshTokens < Invidious::Jobs::BaseJob
|
||||
def initialize
|
||||
end
|
||||
|
||||
def begin
|
||||
loop do
|
||||
Tokens.refresh_tokens
|
||||
LOGGER.info("RefreshTokens: Done, sleeping for 5 seconds")
|
||||
sleep 5.seconds
|
||||
Fiber.yield
|
||||
end
|
||||
end
|
||||
end
|
|
@ -54,8 +54,7 @@ def extract_video_info(video_id : String, user_po_token, user_visitor_data)
|
|||
# Init client config for the API
|
||||
client_config = YoutubeAPI::ClientConfig.new
|
||||
|
||||
redis_po_token = get_po_token()
|
||||
redis_visitor_data = get_visitor_data()
|
||||
redis_po_token, redis_visitor_data = Tokens.get_tokens
|
||||
|
||||
po_token = (user_po_token if !user_po_token.empty?) || redis_po_token || CONFIG.po_token
|
||||
visitor_data = (user_visitor_data if !user_visitor_data.empty?) || redis_visitor_data || CONFIG.visitor_data
|
||||
|
|
Loading…
Reference in a new issue