mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-22 16:19:53 +05:30
Search: Add support for youtu.be and youtube.com URLs
This commit is contained in:
parent
eb0f651812
commit
4c0b5c314d
@ -51,6 +51,12 @@ module Invidious::Routes::Search
|
||||
else
|
||||
user = env.get? "user"
|
||||
|
||||
# An URL was copy/pasted in the search box.
|
||||
# Redirect the user to the appropriate page.
|
||||
if query.is_url?
|
||||
return env.redirect UrlSanitizer.process(query.text).to_s
|
||||
end
|
||||
|
||||
begin
|
||||
items = query.process
|
||||
rescue ex : ChannelSearchException
|
||||
|
@ -48,11 +48,12 @@ module Invidious::Search
|
||||
)
|
||||
# Get the raw search query string (common to all search types). In
|
||||
# Regular search mode, also look for the `search_query` URL parameter
|
||||
if @type.regular?
|
||||
@raw_query = params["q"]? || params["search_query"]? || ""
|
||||
else
|
||||
@raw_query = params["q"]? || ""
|
||||
end
|
||||
_raw_query = params["q"]?
|
||||
_raw_query ||= params["search_query"]? if @type.regular?
|
||||
_raw_query ||= ""
|
||||
|
||||
# Remove surrounding whitespaces. Mostly useful for copy/pasted URLs.
|
||||
@raw_query = _raw_query.strip
|
||||
|
||||
# Get the page number (also common to all search types)
|
||||
@page = params["page"]?.try &.to_i? || 1
|
||||
@ -85,7 +86,7 @@ module Invidious::Search
|
||||
@filters = Filters.from_iv_params(params)
|
||||
@channel = params["channel"]? || ""
|
||||
|
||||
if @filters.default? && @raw_query.includes?(':')
|
||||
if @filters.default? && @raw_query.index(/\w:\w/)
|
||||
# Parse legacy filters from query
|
||||
@filters, @channel, @query, subs = Filters.from_legacy_filters(@raw_query)
|
||||
else
|
||||
@ -136,5 +137,19 @@ module Invidious::Search
|
||||
|
||||
return params
|
||||
end
|
||||
|
||||
# Checks if the query is a standalone URL
|
||||
def is_url? : Bool
|
||||
# Only supported in regular search mode
|
||||
return false if !@type.regular?
|
||||
|
||||
# If filters are present, that's a regular search
|
||||
return false if !@filters.default?
|
||||
|
||||
# Simple heuristics: domain name
|
||||
return @raw_query.starts_with?(
|
||||
/(https?:\/\/)?(www\.)?(m\.)?youtu(\.be|be\.com)\//
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user