diff --git a/src/invidious.cr b/src/invidious.cr index 4b5e7b94..35cf22c6 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -214,9 +214,9 @@ if !CONFIG.external_videoplayback_proxy.empty? end if !CONFIG.tokens_server.empty? - Invidious::Jobs.register Invidious::Jobs::RefreshTokens.new + Invidious::Jobs.register Invidious::Jobs::RefreshSessionTokens.new else - LOGGER.info("jobs: Disabling RefreshTokens job. Invidious will use the tokens that are on the configuration file") + LOGGER.info("jobs: Disabling RefreshSessionTokens job. Invidious will use the tokens that are on the configuration file") end Invidious::Jobs.start_all diff --git a/src/invidious/helpers/session_tokens.cr b/src/invidious/helpers/session_tokens.cr index 812d4e4f..cd5b1eb6 100644 --- a/src/invidious/helpers/session_tokens.cr +++ b/src/invidious/helpers/session_tokens.cr @@ -1,4 +1,4 @@ -module Tokens +module SessionTokens extend self @@po_token : String | Nil @@visitor_data : String | Nil @@ -7,25 +7,25 @@ module 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}") + LOGGER.error("RefreshSessionTokens: 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}") + LOGGER.error("RefreshSessionTokens: 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") + LOGGER.debug("RefreshSessionTokens: 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") + LOGGER.warn("RefreshSessionTokens: 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}") + LOGGER.trace("RefreshSessionTokens: Tokens are:") + LOGGER.trace("RefreshSessionTokens: po_token: #{CONFIG.po_token}") + LOGGER.trace("RefreshSessionTokens: visitor_data: #{CONFIG.visitor_data}") end def set_tokens diff --git a/src/invidious/jobs/refresh_tokens.cr b/src/invidious/jobs/refresh_tokens.cr index 0d381c80..73e944b8 100644 --- a/src/invidious/jobs/refresh_tokens.cr +++ b/src/invidious/jobs/refresh_tokens.cr @@ -1,10 +1,10 @@ -class Invidious::Jobs::RefreshTokens < Invidious::Jobs::BaseJob +class Invidious::Jobs::RefreshSessionTokens < Invidious::Jobs::BaseJob def initialize end def begin loop do - Tokens.refresh_tokens + SessionTokens.refresh_tokens LOGGER.info("RefreshTokens: Done, sleeping for 5 seconds") sleep 5.seconds Fiber.yield