mirror of
https://github.com/iv-org/invidious.git
synced 2025-04-18 06:35:49 -04:00
added config option for token updater
This commit is contained in:
parent
27d66259b8
commit
030b301fcc
@ -210,6 +210,14 @@ http_proxy:
|
||||
# po_token: ""
|
||||
# visitor_data: ""
|
||||
|
||||
##
|
||||
## Monitor config for tokens each 1 minute
|
||||
##
|
||||
## Accepted values: true, false
|
||||
## Default: true
|
||||
##
|
||||
tokenmon_enabled : true
|
||||
|
||||
# -----------------------------
|
||||
# Logging
|
||||
# -----------------------------
|
||||
|
@ -196,7 +196,9 @@ Invidious::Jobs.register Invidious::Jobs::NotificationJob.new(CONNECTION_CHANNEL
|
||||
|
||||
Invidious::Jobs.register Invidious::Jobs::ClearExpiredItemsJob.new
|
||||
|
||||
Invidious::Jobs.register Invidious::Jobs::MonitorCfgTokensJob.new()
|
||||
if CONFIG.tokenmon_enabled
|
||||
Invidious::Jobs.register Invidious::Jobs::MonitorCfgTokensJob.new()
|
||||
end
|
||||
|
||||
Invidious::Jobs.register Invidious::Jobs::InstanceListRefreshJob.new
|
||||
|
||||
|
@ -99,6 +99,7 @@ class Config
|
||||
property hmac_key : String = ""
|
||||
# Domain to be used for links to resources on the site where an absolute URL is required
|
||||
property domain : String?
|
||||
property tokenmon_enabled : Bool = true
|
||||
# Subscribe to channels using PubSubHubbub (requires domain, hmac_key)
|
||||
property use_pubsub_feeds : Bool | Int32 = false
|
||||
property popular_enabled : Bool = true
|
||||
|
@ -23,6 +23,9 @@ module YoutubeAPI
|
||||
|
||||
private WINDOWS_VERSION = "10.0"
|
||||
|
||||
pot = ""
|
||||
vdata = ""
|
||||
|
||||
# Enumerate used to select one of the clients supported by the API
|
||||
enum ClientType
|
||||
Web
|
||||
@ -273,6 +276,17 @@ module YoutubeAPI
|
||||
# youtube API endpoints.
|
||||
#
|
||||
private def make_context(client_config : ClientConfig | Nil, video_id = "dQw4w9WgXcQ") : Hash
|
||||
# determine po_token and visitor_data
|
||||
if CONFIG.tokenmon_enabled
|
||||
# get the pot/vdata for usage later
|
||||
pot = ReloadTokens.pot.as(String)
|
||||
vdata = ReloadTokens.vdata.as(String)
|
||||
else
|
||||
# Use the configured pot
|
||||
pot = CONFIG.po_token.as(String)
|
||||
vdata = CONFIG.visitor_data.as(String)
|
||||
end
|
||||
|
||||
# Use the default client config if nil is passed
|
||||
client_config ||= DEFAULT_CLIENT_CONFIG
|
||||
|
||||
@ -320,8 +334,8 @@ module YoutubeAPI
|
||||
client_context["client"]["platform"] = platform
|
||||
end
|
||||
|
||||
if ReloadTokens.vdata.is_a?(String)
|
||||
client_context["client"]["visitorData"] = ReloadTokens.vdata.as(String)
|
||||
if vdata.is_a?(String)
|
||||
client_context["client"]["visitorData"] = vdata
|
||||
end
|
||||
|
||||
return client_context
|
||||
@ -469,6 +483,17 @@ module YoutubeAPI
|
||||
end
|
||||
end
|
||||
|
||||
# determine po_token and visitor_data
|
||||
if CONFIG.tokenmon_enabled
|
||||
# get the pot/vdata for usage later
|
||||
pot = ReloadTokens.pot.as(String)
|
||||
vdata = ReloadTokens.vdata.as(String)
|
||||
else
|
||||
# Use the configured pot
|
||||
pot = CONFIG.po_token.as(String)
|
||||
vdata = CONFIG.visitor_data.as(String)
|
||||
end
|
||||
|
||||
# JSON Request data, required by the API
|
||||
data = {
|
||||
"contentCheckOk" => true,
|
||||
@ -482,7 +507,7 @@ module YoutubeAPI
|
||||
"contentPlaybackContext" => playback_ctx,
|
||||
},
|
||||
"serviceIntegrityDimensions" => {
|
||||
"poToken" => ReloadTokens.pot.as(String),
|
||||
"poToken" => pot,
|
||||
},
|
||||
}
|
||||
|
||||
@ -616,8 +641,19 @@ module YoutubeAPI
|
||||
headers["User-Agent"] = user_agent
|
||||
end
|
||||
|
||||
if ReloadTokens.vdata.is_a?(String)
|
||||
headers["X-Goog-Visitor-Id"] = ReloadTokens.vdata.as(String)
|
||||
# determine po_token and visitor_data
|
||||
if CONFIG.tokenmon_enabled
|
||||
# get the pot/vdata for usage later
|
||||
pot = ReloadTokens.pot.as(String)
|
||||
vdata = ReloadTokens.vdata.as(String)
|
||||
else
|
||||
# Use the configured pot
|
||||
pot = CONFIG.po_token.as(String)
|
||||
vdata = CONFIG.visitor_data.as(String)
|
||||
end
|
||||
|
||||
if vdata.is_a?(String)
|
||||
headers["X-Goog-Visitor-Id"] = vdata
|
||||
end
|
||||
|
||||
# Logging
|
||||
|
Loading…
x
Reference in New Issue
Block a user