mirror of
https://github.com/iv-org/invidious.git
synced 2026-11-27 08:21:44 +00:00
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:
@@ -193,6 +193,7 @@
|
|||||||
"search_message_no_results": "No results found.",
|
"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_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_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",
|
"Hide annotations": "Hide annotations",
|
||||||
"Show annotations": "Show annotations",
|
"Show annotations": "Show annotations",
|
||||||
"Genre: ": "Genre: ",
|
"Genre: ": "Genre: ",
|
||||||
|
|||||||
@@ -56,3 +56,6 @@ class RedditIsDeprecated < InfoException
|
|||||||
return "Reddit comments have been removed from Invidious."
|
return "Reddit comments have been removed from Invidious."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SearchRequiresAgeVerification < InfoException
|
||||||
|
end
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ module Invidious::Routes::API::V1::Search
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
search_results = query.process
|
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
|
rescue ex
|
||||||
return Errors.error_json(400, ex)
|
return Errors.error_json(400, ex)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ module Invidious::Search
|
|||||||
property region : String?
|
property region : String?
|
||||||
property channel : String = ""
|
property channel : String = ""
|
||||||
|
|
||||||
|
getter? requires_age_verification : Bool = false
|
||||||
|
|
||||||
# Flag that indicates if the smart search features have been disabled.
|
# Flag that indicates if the smart search features have been disabled.
|
||||||
@inhibit_ssf : Bool = false
|
@inhibit_ssf : Bool = false
|
||||||
|
|
||||||
@@ -124,7 +126,11 @@ module Invidious::Search
|
|||||||
|
|
||||||
case @type
|
case @type
|
||||||
when .regular?, .playlist?
|
when .regular?, .playlist?
|
||||||
items = Processors.regular(self)
|
begin
|
||||||
|
items = Processors.regular(self)
|
||||||
|
rescue SearchRequiresAgeVerification
|
||||||
|
@requires_age_verification = true
|
||||||
|
end
|
||||||
#
|
#
|
||||||
when .channel?
|
when .channel?
|
||||||
items = Processors.channel(self)
|
items = Processors.channel(self)
|
||||||
|
|||||||
@@ -13,7 +13,13 @@
|
|||||||
<hr/>
|
<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 class="h-box no-results-error">
|
||||||
<div>
|
<div>
|
||||||
<%= I18n.translate(locale, "search_message_no_results") %><br/><br/>
|
<%= I18n.translate(locale, "search_message_no_results") %><br/><br/>
|
||||||
|
|||||||
@@ -1121,7 +1121,25 @@ private module Extractors
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def self.extractor_name
|
def self.extractor_name
|
||||||
|
|||||||
Reference in New Issue
Block a user