|
|
@ -507,14 +507,14 @@ end
|
|
|
|
class VideoRedirect < Exception
|
|
|
|
class VideoRedirect < Exception
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def get_video(id, db, proxies = {} of String => Array({ip: String, port: Int32}), refresh = true)
|
|
|
|
def get_video(id, db, proxies = {} of String => Array({ip: String, port: Int32}), refresh = true, region = nil)
|
|
|
|
if db.query_one?("SELECT EXISTS (SELECT true FROM videos WHERE id = $1)", id, as: Bool)
|
|
|
|
if db.query_one?("SELECT EXISTS (SELECT true FROM videos WHERE id = $1)", id, as: Bool)
|
|
|
|
video = db.query_one("SELECT * FROM videos WHERE id = $1", id, as: Video)
|
|
|
|
video = db.query_one("SELECT * FROM videos WHERE id = $1", id, as: Video)
|
|
|
|
|
|
|
|
|
|
|
|
# If record was last updated over 10 minutes ago, refresh (expire param in response lasts for 6 hours)
|
|
|
|
# If record was last updated over 10 minutes ago, refresh (expire param in response lasts for 6 hours)
|
|
|
|
if refresh && Time.now - video.updated > 10.minutes
|
|
|
|
if refresh && Time.now - video.updated > 10.minutes
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
video = fetch_video(id, proxies)
|
|
|
|
video = fetch_video(id, proxies, region)
|
|
|
|
video_array = video.to_a
|
|
|
|
video_array = video.to_a
|
|
|
|
|
|
|
|
|
|
|
|
args = arg_array(video_array[1..-1], 2)
|
|
|
|
args = arg_array(video_array[1..-1], 2)
|
|
|
@ -529,7 +529,7 @@ def get_video(id, db, proxies = {} of String => Array({ip: String, port: Int32})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
video = fetch_video(id, proxies)
|
|
|
|
video = fetch_video(id, proxies, region)
|
|
|
|
video_array = video.to_a
|
|
|
|
video_array = video.to_a
|
|
|
|
|
|
|
|
|
|
|
|
args = arg_array(video_array)
|
|
|
|
args = arg_array(video_array)
|
|
|
@ -540,12 +540,12 @@ def get_video(id, db, proxies = {} of String => Array({ip: String, port: Int32})
|
|
|
|
return video
|
|
|
|
return video
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_video(id, proxies)
|
|
|
|
def fetch_video(id, proxies, region)
|
|
|
|
html_channel = Channel(XML::Node | String).new
|
|
|
|
html_channel = Channel(XML::Node | String).new
|
|
|
|
info_channel = Channel(HTTP::Params).new
|
|
|
|
info_channel = Channel(HTTP::Params).new
|
|
|
|
|
|
|
|
|
|
|
|
spawn do
|
|
|
|
spawn do
|
|
|
|
client = make_client(YT_URL)
|
|
|
|
client = make_client(YT_URL, proxies, region)
|
|
|
|
html = client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999")
|
|
|
|
html = client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999")
|
|
|
|
|
|
|
|
|
|
|
|
if md = html.headers["location"]?.try &.match(/v=(?<id>[a-zA-Z0-9_-]{11})/)
|
|
|
|
if md = html.headers["location"]?.try &.match(/v=(?<id>[a-zA-Z0-9_-]{11})/)
|
|
|
@ -557,7 +557,7 @@ def fetch_video(id, proxies)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
spawn do
|
|
|
|
spawn do
|
|
|
|
client = make_client(YT_URL)
|
|
|
|
client = make_client(YT_URL, proxies, region)
|
|
|
|
info = client.get("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1")
|
|
|
|
info = client.get("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1")
|
|
|
|
info = HTTP::Params.parse(info.body)
|
|
|
|
info = HTTP::Params.parse(info.body)
|
|
|
|
|
|
|
|
|
|
|
@ -628,9 +628,9 @@ def fetch_video(id, proxies)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
proxy = {ip: proxy.proxy_host, port: proxy.proxy_port}
|
|
|
|
proxy = {ip: proxy.proxy_host, port: proxy.proxy_port}
|
|
|
|
region = proxies.select { |region, list| list.includes? proxy }
|
|
|
|
region_proxies = proxies.select { |region, list| list.includes? proxy }
|
|
|
|
if !region.empty?
|
|
|
|
if !region_proxies.empty?
|
|
|
|
info["region"] = region.keys[0]
|
|
|
|
info["region"] = region_proxies.keys[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
break
|
|
|
@ -736,11 +736,13 @@ def process_video_params(query, preferences)
|
|
|
|
listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe
|
|
|
|
listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe
|
|
|
|
preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase }
|
|
|
|
preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase }
|
|
|
|
quality = query["quality"]?
|
|
|
|
quality = query["quality"]?
|
|
|
|
|
|
|
|
region = query["region"]?
|
|
|
|
speed = query["speed"]?.try &.to_f?
|
|
|
|
speed = query["speed"]?.try &.to_f?
|
|
|
|
video_loop = query["loop"]?.try &.to_i?
|
|
|
|
video_loop = query["loop"]?.try &.to_i?
|
|
|
|
volume = query["volume"]?.try &.to_i?
|
|
|
|
volume = query["volume"]?.try &.to_i?
|
|
|
|
|
|
|
|
|
|
|
|
if preferences
|
|
|
|
if preferences
|
|
|
|
|
|
|
|
# region ||= preferences.region
|
|
|
|
autoplay ||= preferences.autoplay.to_unsafe
|
|
|
|
autoplay ||= preferences.autoplay.to_unsafe
|
|
|
|
continue ||= preferences.continue.to_unsafe
|
|
|
|
continue ||= preferences.continue.to_unsafe
|
|
|
|
listen ||= preferences.listen.to_unsafe
|
|
|
|
listen ||= preferences.listen.to_unsafe
|
|
|
@ -798,6 +800,7 @@ def process_video_params(query, preferences)
|
|
|
|
preferred_captions: preferred_captions,
|
|
|
|
preferred_captions: preferred_captions,
|
|
|
|
quality: quality,
|
|
|
|
quality: quality,
|
|
|
|
raw: raw,
|
|
|
|
raw: raw,
|
|
|
|
|
|
|
|
region: region,
|
|
|
|
speed: speed,
|
|
|
|
speed: speed,
|
|
|
|
video_end: video_end,
|
|
|
|
video_end: video_end,
|
|
|
|
video_loop: video_loop,
|
|
|
|
video_loop: video_loop,
|
|
|
|