From fd0ac3a6719b3d6280ce2e784ad370c8d10a6129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9ry=20Mathieu=20=28Mathius=29?= Date: Tue, 22 Feb 2022 01:35:35 +0100 Subject: [PATCH] Update management of channel_refresh_interval Follow indications: https://github.com/iv-org/invidious/pull/2915#discussion_r811373503 --- config/config.example.yml | 6 +++--- docker-compose.yml | 2 +- src/invidious/helpers/utils.cr | 18 ++++++++++++++++++ src/invidious/user/preferences.cr | 6 +++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index 9519f34a7..a6440e3d5 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -317,10 +317,10 @@ channel_threads: 1 ## ## Time between two jobs for crawling videos from channels ## -## Accepted values: a valid time interval (hours:min:seconds) -## Default: 00:30:00 +## Accepted values: a valid time interval (like 1h30m or 90min) +## Default: 30m ## -channel_refresh_interval: 00:30:00 +channel_refresh_interval: 30min ## ## Forcefully dump and re-download the entire list of uploaded diff --git a/docker-compose.yml b/docker-compose.yml index ab35a496e..4fdad921e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: INVIDIOUS_CONFIG: | log_level: Info channel_threads: 1 - channel_refresh_interval: 00:30:00 + channel_refresh_interval: 30m check_tables: true feed_threads: 1 db: diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 22575c57a..53f64f4ea 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -53,6 +53,24 @@ def recode_length_seconds(time : Int32) : String end end +def decode_interval(string : String) : Time::Span + rawMinutes = string.try &.to_i32? + + if !rawMinutes + hours = /(?\d+)h/.match(string).try &.["hours"].try &.to_i32 + hours ||= 0 + + minutes = /(?\d+)m(?!s)/.match(string).try &.["minutes"].try &.to_i32 + minutes ||= 0 + + time = Time::Span.new(hours: hours, minutes: minutes) + else + time = Time::Span.new(minutes: rawMinutes) + end + + return time +end + def decode_time(string) time = string.try &.to_f? diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr index c01bdd821..9eeed53f5 100644 --- a/src/invidious/user/preferences.cr +++ b/src/invidious/user/preferences.cr @@ -259,15 +259,15 @@ struct Preferences module TimeSpanConverter def self.to_yaml(value : Time::Span, yaml : YAML::Nodes::Builder) - return yaml.scalar recode_length_seconds(value.total_seconds.to_i32) + return yaml.scalar value.total_minutes.to_i32 end def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Time::Span if node.is_a?(YAML::Nodes::Scalar) - return decode_time_span(node.value) + return decode_interval(node.value) else node.raise "Expected scalar, not #{node.class}" end end end -end \ No newline at end of file +end