diff --git a/locales/en-US.json b/locales/en-US.json index fe5d864e2..018e32b55 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -193,6 +193,7 @@ "search_message_no_results": "No results found.", "search_message_change_filters_or_query": "Try widening your search query and/or changing the filters.", "search_message_use_another_instance": "You can also search on another instance.", + "search_message_requires_age_verification": "Youtube requires age verification for this search. Try rephrasing your search query to get results.", "Hide annotations": "Hide annotations", "Show annotations": "Show annotations", "Genre: ": "Genre: ", diff --git a/src/invidious/exceptions.cr b/src/invidious/exceptions.cr index f433b6c14..745e3ab9a 100644 --- a/src/invidious/exceptions.cr +++ b/src/invidious/exceptions.cr @@ -56,3 +56,6 @@ class RedditIsDeprecated < InfoException return "Reddit comments have been removed from Invidious." end end + +class SearchRequiresAgeVerification < InfoException +end diff --git a/src/invidious/routes/api/v1/search.cr b/src/invidious/routes/api/v1/search.cr index 14b19c837..67a68e568 100644 --- a/src/invidious/routes/api/v1/search.cr +++ b/src/invidious/routes/api/v1/search.cr @@ -9,6 +9,9 @@ module Invidious::Routes::API::V1::Search begin search_results = query.process + if query.requires_age_verification? + return Errors.error_json(400, "Youtube requires age verification for this search. Try rephrasing your search query to get results.") + end rescue ex return Errors.error_json(400, ex) end diff --git a/src/invidious/search/query.cr b/src/invidious/search/query.cr index 94a92e23d..4a755d683 100644 --- a/src/invidious/search/query.cr +++ b/src/invidious/search/query.cr @@ -20,6 +20,8 @@ module Invidious::Search property region : String? property channel : String = "" + getter? requires_age_verification : Bool = false + # Flag that indicates if the smart search features have been disabled. @inhibit_ssf : Bool = false @@ -124,7 +126,11 @@ module Invidious::Search case @type when .regular?, .playlist? - items = Processors.regular(self) + begin + items = Processors.regular(self) + rescue SearchRequiresAgeVerification + @requires_age_verification = true + end # when .channel? items = Processors.channel(self) diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr index ff0ced66e..cf17e03fd 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -13,7 +13,13 @@
-<%- if items.empty? -%> +<%- if query.requires_age_verification? -%> +
+
+ <%= I18n.translate(locale, "search_message_requires_age_verification") %>

+
+
+<%- elsif items.empty? -%>
<%= I18n.translate(locale, "search_message_no_results") %>

diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index 1031ba7ab..aa337bd6c 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -1121,7 +1121,25 @@ private module Extractors end end - return raw_items.flatten + raw_items = raw_items.flatten + + requires_age_verification(raw_items) + + return raw_items + end + + # 2026-11-24: Youtube started to return a new page that shows + # a "Confirm your age" when doing suggestive searches. + # This detects that message to set the query as a query + # that needs age verification, forcing the user to rephrase + # their search since there is no workaround for this. + private def self.requires_age_verification(raw_items) + background_promo_renderer = raw_items.first?.try &.dig?("backgroundPromoRenderer") + background_promo_renderer_title = background_promo_renderer.try &.dig?("title", "runs", 0, "text").try &.as_s + + if title = background_promo_renderer_title + raise SearchRequiresAgeVerification.new if title == "Confirm your age" + end end def self.extractor_name