feat: detect age restricted search queries and display a message about it (#6175)

* feat: detect age restricted search queries and display a message about it

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.

* and also display the message for the search API

* Update src/invidious/yt_backend/extractors.cr

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This commit is contained in:
Fijxu
2026-11-27 00:37:05 -03:00
committed by GitHub
parent d8c00579d0
commit 0f5e4945b3
6 changed files with 40 additions and 3 deletions

View File

@@ -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 <a href=\"`x`\">search on another instance</a>.",
"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: ",

View File

@@ -56,3 +56,6 @@ class RedditIsDeprecated < InfoException
return "Reddit comments have been removed from Invidious."
end
end
class SearchRequiresAgeVerification < InfoException
end

View File

@@ -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

View File

@@ -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)

View File

@@ -13,7 +13,13 @@
<hr/>
<%- if items.empty? -%>
<%- if query.requires_age_verification? -%>
<div class="h-box no-results-error">
<div>
<%= I18n.translate(locale, "search_message_requires_age_verification") %><br/><br/>
</div>
</div>
<%- elsif items.empty? -%>
<div class="h-box no-results-error">
<div>
<%= I18n.translate(locale, "search_message_no_results") %><br/><br/>

View File

@@ -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