From ca4c2115eebd5b3eaeb7ebf9e4e704ad83e5b4bf Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Sat, 6 Aug 2022 13:14:35 +0200 Subject: [PATCH 1/2] Message when the video doesn't exist in playlist --- locales/en-US.json | 3 ++- src/invidious/routes/embed.cr | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/locales/en-US.json b/locales/en-US.json index 9701a621..5caa4bd1 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -471,5 +471,6 @@ "crash_page_switch_instance": "tried to use another instance", "crash_page_read_the_faq": "read the Frequently Asked Questions (FAQ)", "crash_page_search_issue": "searched for existing issues on GitHub", - "crash_page_report_issue": "If none of the above helped, please open a new issue on GitHub (preferably in English) and include the following text in your message (do NOT translate that text):" + "crash_page_report_issue": "If none of the above helped, please open a new issue on GitHub (preferably in English) and include the following text in your message (do NOT translate that text):", + "video_not_exist_in_playlist": "The video requested doesn't exist in the playlist. Click here for the playlist home page." } diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr index 84da9993..7860f8b9 100644 --- a/src/invidious/routes/embed.cr +++ b/src/invidious/routes/embed.cr @@ -2,11 +2,16 @@ module Invidious::Routes::Embed def self.redirect(env) + locale = env.get("preferences").as(Preferences).locale if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "") begin playlist = get_playlist(plid) offset = env.params.query["index"]?.try &.to_i? || 0 videos = get_playlist_videos(playlist, offset: offset) + if videos.empty? + url = "/playlist?list=#{plid}" + raise NotFoundException.new(translate(locale, "video_not_exist_in_playlist", url)) + end rescue ex : NotFoundException return error_template(404, ex) rescue ex @@ -26,6 +31,7 @@ module Invidious::Routes::Embed end def self.show(env) + locale = env.get("preferences").as(Preferences).locale id = env.params.url["id"] plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "") @@ -62,6 +68,10 @@ module Invidious::Routes::Embed playlist = get_playlist(plid) offset = env.params.query["index"]?.try &.to_i? || 0 videos = get_playlist_videos(playlist, offset: offset) + if videos.empty? + url = "/playlist?list=#{plid}" + raise NotFoundException.new(translate(locale, "video_not_exist_in_playlist", url)) + end rescue ex : NotFoundException return error_template(404, ex) rescue ex From 260bab598e00fe769ff36ba2c171768a1fbc31bb Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Fri, 2 Sep 2022 20:20:43 +0200 Subject: [PATCH 2/2] reword error messages --- locales/en-US.json | 2 +- src/invidious/routes/embed.cr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/locales/en-US.json b/locales/en-US.json index 5caa4bd1..5554b928 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -472,5 +472,5 @@ "crash_page_read_the_faq": "read the Frequently Asked Questions (FAQ)", "crash_page_search_issue": "searched for existing issues on GitHub", "crash_page_report_issue": "If none of the above helped, please open a new issue on GitHub (preferably in English) and include the following text in your message (do NOT translate that text):", - "video_not_exist_in_playlist": "The video requested doesn't exist in the playlist. Click here for the playlist home page." + "error_video_not_in_playlist": "The requested video doesn't exist in this playlist. Click here for the playlist home page." } diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr index 7860f8b9..e6486587 100644 --- a/src/invidious/routes/embed.cr +++ b/src/invidious/routes/embed.cr @@ -10,7 +10,7 @@ module Invidious::Routes::Embed videos = get_playlist_videos(playlist, offset: offset) if videos.empty? url = "/playlist?list=#{plid}" - raise NotFoundException.new(translate(locale, "video_not_exist_in_playlist", url)) + raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url)) end rescue ex : NotFoundException return error_template(404, ex) @@ -70,7 +70,7 @@ module Invidious::Routes::Embed videos = get_playlist_videos(playlist, offset: offset) if videos.empty? url = "/playlist?list=#{plid}" - raise NotFoundException.new(translate(locale, "video_not_exist_in_playlist", url)) + raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url)) end rescue ex : NotFoundException return error_template(404, ex)