|
|
@ -432,32 +432,39 @@ get "/search" do |env|
|
|
|
|
page = env.params.query["page"]?.try &.to_i?
|
|
|
|
page = env.params.query["page"]?.try &.to_i?
|
|
|
|
page ||= 1
|
|
|
|
page ||= 1
|
|
|
|
|
|
|
|
|
|
|
|
sort = "relevance"
|
|
|
|
channel = nil
|
|
|
|
date = ""
|
|
|
|
date = ""
|
|
|
|
duration = ""
|
|
|
|
duration = ""
|
|
|
|
features = [] of String
|
|
|
|
features = [] of String
|
|
|
|
|
|
|
|
sort = "relevance"
|
|
|
|
|
|
|
|
|
|
|
|
operators = query.split(" ").select { |a| a.match(/\w+:[\w,]+/) }
|
|
|
|
operators = query.split(" ").select { |a| a.match(/\w+:[\w,]+/) }
|
|
|
|
operators.each do |operator|
|
|
|
|
operators.each do |operator|
|
|
|
|
key, value = operator.split(":")
|
|
|
|
key, value = operator.split(":")
|
|
|
|
|
|
|
|
|
|
|
|
case key
|
|
|
|
case key
|
|
|
|
when "sort"
|
|
|
|
when "channel", "user"
|
|
|
|
sort = value
|
|
|
|
channel = value
|
|
|
|
when "date"
|
|
|
|
when "date"
|
|
|
|
date = value
|
|
|
|
date = value
|
|
|
|
when "duration"
|
|
|
|
when "duration"
|
|
|
|
duration = value
|
|
|
|
duration = value
|
|
|
|
when "features"
|
|
|
|
when "features"
|
|
|
|
features = value.split(",")
|
|
|
|
features = value.split(",")
|
|
|
|
|
|
|
|
when "sort"
|
|
|
|
|
|
|
|
sort = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
search_query = (query.split(" ") - operators).join(" ")
|
|
|
|
search_query = (query.split(" ") - operators).join(" ")
|
|
|
|
|
|
|
|
|
|
|
|
search_params = build_search_params(sort: sort, date: date, content_type: "video",
|
|
|
|
if channel
|
|
|
|
duration: duration, features: features)
|
|
|
|
count, videos = channel_search(search_query, page, channel)
|
|
|
|
count, videos = search(search_query, page, search_params).as(Tuple)
|
|
|
|
else
|
|
|
|
|
|
|
|
search_params = build_search_params(sort: sort, date: date, content_type: "video",
|
|
|
|
|
|
|
|
duration: duration, features: features)
|
|
|
|
|
|
|
|
count, videos = search(search_query, page, search_params).as(Tuple)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
templated "search"
|
|
|
|
templated "search"
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1666,6 +1673,14 @@ get "/channel/:ucid" do |env|
|
|
|
|
auto_generated = true
|
|
|
|
auto_generated = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !auto_generated
|
|
|
|
|
|
|
|
if author.includes? " "
|
|
|
|
|
|
|
|
env.set "search", "channel:#{ucid} "
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
env.set "search", "channel:#{author.downcase} "
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
videos = [] of SearchVideo
|
|
|
|
videos = [] of SearchVideo
|
|
|
|
2.times do |i|
|
|
|
|
2.times do |i|
|
|
|
|
url = produce_channel_videos_url(ucid, page * 2 + (i - 1), auto_generated: auto_generated)
|
|
|
|
url = produce_channel_videos_url(ucid, page * 2 + (i - 1), auto_generated: auto_generated)
|
|
|
@ -1918,11 +1933,11 @@ get "/api/v1/comments/:id" do |env|
|
|
|
|
url = URI.parse(url)
|
|
|
|
url = URI.parse(url)
|
|
|
|
|
|
|
|
|
|
|
|
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.host
|
|
|
|
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? url.host
|
|
|
|
if url.path == "/redirect"
|
|
|
|
if url.path == "/redirect"
|
|
|
|
url = HTTP::Params.parse(url.query.not_nil!)["q"]
|
|
|
|
url = HTTP::Params.parse(url.query.not_nil!)["q"]
|
|
|
|
else
|
|
|
|
else
|
|
|
|
url = url.full_path
|
|
|
|
url = url.full_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
|
|
|
|
url = run["navigationEndpoint"]["commandMetadata"]?.try &.["webCommandMetadata"]["url"].as_s
|
|
|
|