Move live endpoints into Channels route
parent
919413e2b9
commit
e215a20a0a
@ -1,34 +0,0 @@
|
||||
module Invidious::Routes::Live
|
||||
def self.check(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
# Appears to be a bug in routing, having several routes configured
|
||||
# as `/a/:a`, `/b/:a`, `/c/:a` results in 404
|
||||
value = env.request.resource.split("/")[2]
|
||||
body = ""
|
||||
{"channel", "user", "c"}.each do |type|
|
||||
response = YT_POOL.client &.get("/#{type}/#{value}/live?disable_polymer=1")
|
||||
if response.status_code == 200
|
||||
body = response.body
|
||||
end
|
||||
end
|
||||
|
||||
video_id = body.match(/'VIDEO_ID': "(?<id>[a-zA-Z0-9_-]{11})"/).try &.["id"]?
|
||||
if video_id
|
||||
params = [] of String
|
||||
env.params.query.each do |k, v|
|
||||
params << "#{k}=#{v}"
|
||||
end
|
||||
params = params.join("&")
|
||||
|
||||
url = "/watch?v=#{video_id}"
|
||||
if !params.empty?
|
||||
url += "&#{params}"
|
||||
end
|
||||
|
||||
env.redirect url
|
||||
else
|
||||
env.redirect "/channel/#{value}"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue