From 4818b89ab164713b1e52b7b03e48d47b6e7bce26 Mon Sep 17 00:00:00 2001 From: Jakub Filo Date: Sat, 27 Aug 2022 22:36:07 +0200 Subject: [PATCH 1/2] Allow to set maximum custom playlist length via a config variable. --- config/config.example.yml | 8 ++++++++ src/invidious/config.cr | 3 +++ src/invidious/database/playlists.cr | 2 +- src/invidious/routes/api/v1/authenticated.cr | 4 ++-- src/invidious/routes/playlists.cr | 6 +++--- src/invidious/routes/subscriptions.cr | 2 +- src/invidious/user/imports.cr | 2 +- 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index 10734c3a..424e2a38 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -869,3 +869,11 @@ default_user_preferences: ## Default: false ## #extend_desc: false + + ## + ## Maximum custom playlist length limit. + ## + ## Accepted values: Integer + ## Default: 500 + ## + #playlist_length_limit: 500 diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 786b65df..f0873df4 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -131,6 +131,9 @@ class Config # API URL for Anti-Captcha property captcha_api_url : String = "https://api.anti-captcha.com" + # Playlist length limit + property playlist_length_limit : Int32 = 500 + def disabled?(option) case disabled = CONFIG.disable_proxy when Bool diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index c6754a1e..5f47ff95 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -248,7 +248,7 @@ module Invidious::Database::PlaylistVideos return PG_DB.query_one?(request, plid, index, as: String) end - def select_ids(plid : String, index : VideoIndex, limit = 500) : Array(String) + def select_ids(plid : String, index : VideoIndex, limit = CONFIG.playlist_length_limit) : Array(String) request = <<-SQL SELECT id FROM playlist_videos WHERE plid = $1 diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr index 1f5ad8ef..421355bb 100644 --- a/src/invidious/routes/api/v1/authenticated.cr +++ b/src/invidious/routes/api/v1/authenticated.cr @@ -226,8 +226,8 @@ module Invidious::Routes::API::V1::Authenticated return error_json(403, "Invalid user") end - if playlist.index.size >= 500 - return error_json(400, "Playlist cannot have more than 500 videos") + if playlist.index.size >= CONFIG.playlist_length_limit + return error_json(400, "Playlist cannot have more than #{CONFIG.playlist_length_limit} videos") end video_id = env.params.json["videoId"].try &.as(String) diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr index fe7e4e1c..0d242ee6 100644 --- a/src/invidious/routes/playlists.cr +++ b/src/invidious/routes/playlists.cr @@ -330,11 +330,11 @@ module Invidious::Routes::Playlists when "action_edit_playlist" # TODO: Playlist stub when "action_add_video" - if playlist.index.size >= 500 + if playlist.index.size >= CONFIG.playlist_length_limit if redirect - return error_template(400, "Playlist cannot have more than 500 videos") + return error_template(400, "Playlist cannot have more than #{CONFIG.playlist_length_limit} videos") else - return error_json(400, "Playlist cannot have more than 500 videos") + return error_json(400, "Playlist cannot have more than #{CONFIG.playlist_length_limit} videos") end end diff --git a/src/invidious/routes/subscriptions.cr b/src/invidious/routes/subscriptions.cr index 7b1fa876..ed595d9a 100644 --- a/src/invidious/routes/subscriptions.cr +++ b/src/invidious/routes/subscriptions.cr @@ -120,7 +120,7 @@ module Invidious::Routes::Subscriptions json.field "privacy", playlist.privacy.to_s json.field "videos" do json.array do - Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: 500).each do |video_id| + Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: CONFIG.playlist_length_limit).each do |video_id| json.string video_id end end diff --git a/src/invidious/user/imports.cr b/src/invidious/user/imports.cr index f8b9e4e4..bd929e4d 100644 --- a/src/invidious/user/imports.cr +++ b/src/invidious/user/imports.cr @@ -71,7 +71,7 @@ struct Invidious::User Invidious::Database::Playlists.update_description(playlist.id, description) videos = item["videos"]?.try &.as_a?.try &.each_with_index do |video_id, idx| - raise InfoException.new("Playlist cannot have more than 500 videos") if idx > 500 + raise InfoException.new("Playlist cannot have more than #{CONFIG.playlist_length_limit} videos") if idx > 500 video_id = video_id.try &.as_s? next if !video_id From 7c45026383132c5aaf47b761ef132f5b0e635bb8 Mon Sep 17 00:00:00 2001 From: Jakub Filo Date: Wed, 28 Sep 2022 12:21:23 +0200 Subject: [PATCH 2/2] Fix playlist limit --- config/config.example.yml | 18 ++++++++---------- src/invidious/database/playlists.cr | 2 +- src/invidious/routes/subscriptions.cr | 2 +- src/invidious/user/imports.cr | 4 +++- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index 424e2a38..160a2750 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -453,7 +453,13 @@ feed_threads: 1 ## #modified_source_code_url: "" - +## +## Maximum custom playlist length limit. +## +## Accepted values: Integer +## Default: 500 +## +#playlist_length_limit: 500 ######################################### # @@ -859,7 +865,7 @@ default_user_preferences: ## Default: false ## #automatic_instance_redirect: false - + ## ## Show the entire video description by default (when set to 'false', ## only the first few lines of the description are shown and a @@ -869,11 +875,3 @@ default_user_preferences: ## Default: false ## #extend_desc: false - - ## - ## Maximum custom playlist length limit. - ## - ## Accepted values: Integer - ## Default: 500 - ## - #playlist_length_limit: 500 diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index 5f47ff95..c6754a1e 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -248,7 +248,7 @@ module Invidious::Database::PlaylistVideos return PG_DB.query_one?(request, plid, index, as: String) end - def select_ids(plid : String, index : VideoIndex, limit = CONFIG.playlist_length_limit) : Array(String) + def select_ids(plid : String, index : VideoIndex, limit = 500) : Array(String) request = <<-SQL SELECT id FROM playlist_videos WHERE plid = $1 diff --git a/src/invidious/routes/subscriptions.cr b/src/invidious/routes/subscriptions.cr index ed595d9a..7b1fa876 100644 --- a/src/invidious/routes/subscriptions.cr +++ b/src/invidious/routes/subscriptions.cr @@ -120,7 +120,7 @@ module Invidious::Routes::Subscriptions json.field "privacy", playlist.privacy.to_s json.field "videos" do json.array do - Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: CONFIG.playlist_length_limit).each do |video_id| + Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: 500).each do |video_id| json.string video_id end end diff --git a/src/invidious/user/imports.cr b/src/invidious/user/imports.cr index bd929e4d..20ae0d47 100644 --- a/src/invidious/user/imports.cr +++ b/src/invidious/user/imports.cr @@ -71,7 +71,9 @@ struct Invidious::User Invidious::Database::Playlists.update_description(playlist.id, description) videos = item["videos"]?.try &.as_a?.try &.each_with_index do |video_id, idx| - raise InfoException.new("Playlist cannot have more than #{CONFIG.playlist_length_limit} videos") if idx > 500 + if idx > CONFIG.playlist_length_limit + raise InfoException.new("Playlist cannot have more than #{CONFIG.playlist_length_limit} videos") + end video_id = video_id.try &.as_s? next if !video_id