Skip to content

Commit 7f445f6

Browse files
authored
Merge pull request #2915 from MathiusD/RefreshChannelsJob-frenquency
Allow configuration of the time between 2 RefreshChannelsJob
2 parents bf59928 + e60a183 commit 7f445f6

File tree

5 files changed

+100
-31
lines changed

5 files changed

+100
-31
lines changed

config/config.example.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ https_only: false
314314
##
315315
channel_threads: 1
316316

317+
##
318+
## Time interval between two executions of the job that crawls
319+
## channel videos (subscriptions update).
320+
##
321+
## Accepted values: a valid time interval (like 1h30m or 90m)
322+
## Default: 30m
323+
##
324+
#channel_refresh_interval: 30m
325+
317326
##
318327
## Forcefully dump and re-download the entire list of uploaded
319328
## videos when crawling channel (during subscriptions update).

src/invidious/config.cr

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,35 @@ end
5757
class Config
5858
include YAML::Serializable
5959

60-
property channel_threads : Int32 = 1 # Number of threads to use for crawling videos from channels (for updating subscriptions)
61-
property feed_threads : Int32 = 1 # Number of threads to use for updating feeds
62-
property output : String = "STDOUT" # Log file path or STDOUT
63-
property log_level : LogLevel = LogLevel::Info # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr
64-
property db : DBConfig? = nil # Database configuration with separate parameters (username, hostname, etc)
65-
60+
# Number of threads to use for crawling videos from channels (for updating subscriptions)
61+
property channel_threads : Int32 = 1
62+
# Time interval between two executions of the job that crawls channel videos (subscriptions update).
63+
@[YAML::Field(converter: Preferences::TimeSpanConverter)]
64+
property channel_refresh_interval : Time::Span = 30.minutes
65+
# Number of threads to use for updating feeds
66+
property feed_threads : Int32 = 1
67+
# Log file path or STDOUT
68+
property output : String = "STDOUT"
69+
# Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr
70+
property log_level : LogLevel = LogLevel::Info
71+
# Database configuration with separate parameters (username, hostname, etc)
72+
property db : DBConfig? = nil
73+
74+
# Database configuration using 12-Factor "Database URL" syntax
6675
@[YAML::Field(converter: Preferences::URIConverter)]
67-
property database_url : URI = URI.parse("") # Database configuration using 12-Factor "Database URL" syntax
68-
property decrypt_polling : Bool = true # Use polling to keep decryption function up to date
69-
property full_refresh : Bool = false # Used for crawling channels: threads should check all videos uploaded by a channel
70-
property https_only : Bool? # Used to tell Invidious it is behind a proxy, so links to resources should be https://
71-
property hmac_key : String? # HMAC signing key for CSRF tokens and verifying pubsub subscriptions
72-
property domain : String? # Domain to be used for links to resources on the site where an absolute URL is required
73-
property use_pubsub_feeds : Bool | Int32 = false # Subscribe to channels using PubSubHubbub (requires domain, hmac_key)
76+
property database_url : URI = URI.parse("")
77+
# Use polling to keep decryption function up to date
78+
property decrypt_polling : Bool = true
79+
# Used for crawling channels: threads should check all videos uploaded by a channel
80+
property full_refresh : Bool = false
81+
# Used to tell Invidious it is behind a proxy, so links to resources should be https://
82+
property https_only : Bool?
83+
# HMAC signing key for CSRF tokens and verifying pubsub subscriptions
84+
property hmac_key : String?
85+
# Domain to be used for links to resources on the site where an absolute URL is required
86+
property domain : String?
87+
# Subscribe to channels using PubSubHubbub (requires domain, hmac_key)
88+
property use_pubsub_feeds : Bool | Int32 = false
7489
property popular_enabled : Bool = true
7590
property captcha_enabled : Bool = true
7691
property login_enabled : Bool = true
@@ -79,28 +94,42 @@ class Config
7994
property admins : Array(String) = [] of String
8095
property external_port : Int32? = nil
8196
property default_user_preferences : ConfigPreferences = ConfigPreferences.from_yaml("")
82-
property dmca_content : Array(String) = [] of String # For compliance with DMCA, disables download widget using list of video IDs
83-
property check_tables : Bool = false # Check table integrity, automatically try to add any missing columns, create tables, etc.
84-
property cache_annotations : Bool = false # Cache annotations requested from IA, will not cache empty annotations or annotations that only contain cards
85-
property banner : String? = nil # Optional banner to be displayed along top of page for announcements, etc.
86-
property hsts : Bool? = true # Enables 'Strict-Transport-Security'. Ensure that `domain` and all subdomains are served securely
87-
property disable_proxy : Bool? | Array(String)? = false # Disable proxying server-wide: options: 'dash', 'livestreams', 'downloads', 'local'
97+
# For compliance with DMCA, disables download widget using list of video IDs
98+
property dmca_content : Array(String) = [] of String
99+
# Check table integrity, automatically try to add any missing columns, create tables, etc.
100+
property check_tables : Bool = false
101+
# Cache annotations requested from IA, will not cache empty annotations or annotations that only contain cards
102+
property cache_annotations : Bool = false
103+
# Optional banner to be displayed along top of page for announcements, etc.
104+
property banner : String? = nil
105+
# Enables 'Strict-Transport-Security'. Ensure that `domain` and all subdomains are served securely
106+
property hsts : Bool? = true
107+
# Disable proxying server-wide: options: 'dash', 'livestreams', 'downloads', 'local'
108+
property disable_proxy : Bool? | Array(String)? = false
88109

89110
# URL to the modified source code to be easily AGPL compliant
90111
# Will display in the footer, next to the main source code link
91112
property modified_source_code_url : String? = nil
92113

114+
# Connect to YouTube over 'ipv6', 'ipv4'. Will sometimes resolve fix issues with rate-limiting (see https://github.com/ytdl-org/youtube-dl/issues/21729)
93115
@[YAML::Field(converter: Preferences::FamilyConverter)]
94-
property force_resolve : Socket::Family = Socket::Family::UNSPEC # Connect to YouTube over 'ipv6', 'ipv4'. Will sometimes resolve fix issues with rate-limiting (see https://github.com/ytdl-org/youtube-dl/issues/21729)
95-
property port : Int32 = 3000 # Port to listen for connections (overridden by command line argument)
96-
property host_binding : String = "0.0.0.0" # Host to bind (overridden by command line argument)
97-
property pool_size : Int32 = 100 # Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`)
98-
property use_quic : Bool = false # Use quic transport for youtube api
99-
116+
property force_resolve : Socket::Family = Socket::Family::UNSPEC
117+
# Port to listen for connections (overridden by command line argument)
118+
property port : Int32 = 3000
119+
# Host to bind (overridden by command line argument)
120+
property host_binding : String = "0.0.0.0"
121+
# Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`)
122+
property pool_size : Int32 = 100
123+
# Use quic transport for youtube api
124+
property use_quic : Bool = false
125+
126+
# Saved cookies in "name1=value1; name2=value2..." format
100127
@[YAML::Field(converter: Preferences::StringToCookies)]
101-
property cookies : HTTP::Cookies = HTTP::Cookies.new # Saved cookies in "name1=value1; name2=value2..." format
102-
property captcha_key : String? = nil # Key for Anti-Captcha
103-
property captcha_api_url : String = "https://api.anti-captcha.com" # API URL for Anti-Captcha
128+
property cookies : HTTP::Cookies = HTTP::Cookies.new
129+
# Key for Anti-Captcha
130+
property captcha_key : String? = nil
131+
# API URL for Anti-Captcha
132+
property captcha_api_url : String = "https://api.anti-captcha.com"
104133

105134
def disabled?(option)
106135
case disabled = CONFIG.disable_proxy

src/invidious/helpers/utils.cr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ def recode_length_seconds(time)
5151
end
5252
end
5353

54+
def decode_interval(string : String) : Time::Span
55+
rawMinutes = string.try &.to_i32?
56+
57+
if !rawMinutes
58+
hours = /(?<hours>\d+)h/.match(string).try &.["hours"].try &.to_i32
59+
hours ||= 0
60+
61+
minutes = /(?<minutes>\d+)m(?!s)/.match(string).try &.["minutes"].try &.to_i32
62+
minutes ||= 0
63+
64+
time = Time::Span.new(hours: hours, minutes: minutes)
65+
else
66+
time = Time::Span.new(minutes: rawMinutes)
67+
end
68+
69+
return time
70+
end
71+
5472
def decode_time(string)
5573
time = string.try &.to_f?
5674

src/invidious/jobs/refresh_channels_job.cr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ class Invidious::Jobs::RefreshChannelsJob < Invidious::Jobs::BaseJob
5858
end
5959
end
6060

61-
# TODO: make this configurable
62-
LOGGER.debug("RefreshChannelsJob: Done, sleeping for thirty minutes")
63-
sleep 30.minutes
61+
LOGGER.debug("RefreshChannelsJob: Done, sleeping for #{CONFIG.channel_refresh_interval}")
62+
sleep CONFIG.channel_refresh_interval
6463
Fiber.yield
6564
end
6665
end

src/invidious/user/preferences.cr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,18 @@ struct Preferences
257257
cookies
258258
end
259259
end
260+
261+
module TimeSpanConverter
262+
def self.to_yaml(value : Time::Span, yaml : YAML::Nodes::Builder)
263+
return yaml.scalar value.total_minutes.to_i32
264+
end
265+
266+
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Time::Span
267+
if node.is_a?(YAML::Nodes::Scalar)
268+
return decode_interval(node.value)
269+
else
270+
node.raise "Expected scalar, not #{node.class}"
271+
end
272+
end
273+
end
260274
end

0 commit comments

Comments
 (0)