mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-21 02:18:52 +00:00
Merge pull request #2925 from matthewmcgarvey/routes-final
Move last remaining routes in main file to new pattern
This commit is contained in:
@@ -397,4 +397,14 @@ module Invidious::Routes::API::V1::Authenticated
|
||||
|
||||
env.response.status_code = 204
|
||||
end
|
||||
|
||||
def self.notifications(env)
|
||||
env.response.content_type = "text/event-stream"
|
||||
|
||||
raw_topics = env.params.body["topics"]? || env.params.query["topics"]?
|
||||
topics = raw_topics.try &.split(",").uniq.first(1000)
|
||||
topics ||= [] of String
|
||||
|
||||
create_notification_stream(env, topics, CONNECTION_CHANNEL)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -147,6 +147,39 @@ module Invidious::Routes::Channels
|
||||
end
|
||||
end
|
||||
|
||||
def self.live(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
|
||||
|
||||
private def self.fetch_basic_information(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
|
||||
@@ -481,4 +481,11 @@ module Invidious::Routes::Login
|
||||
|
||||
env.redirect referer
|
||||
end
|
||||
|
||||
def self.captcha(env)
|
||||
headers = HTTP::Headers{":authority" => "accounts.google.com"}
|
||||
response = YT_POOL.client &.get(env.request.resource, headers)
|
||||
env.response.headers["Content-Type"] = response.headers["Content-Type"]
|
||||
response.body
|
||||
end
|
||||
end
|
||||
|
||||
@@ -443,4 +443,15 @@ module Invidious::Routes::Playlists
|
||||
|
||||
templated "mix"
|
||||
end
|
||||
|
||||
# Undocumented, creates anonymous playlist with specified 'video_ids', max 50 videos
|
||||
def self.watch_videos(env)
|
||||
response = YT_POOL.client &.get(env.request.resource)
|
||||
if url = response.headers["Location"]?
|
||||
url = URI.parse(url).request_target
|
||||
return env.redirect url
|
||||
end
|
||||
|
||||
env.response.status_code = response.status_code
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user