summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2019-07-24 19:07:48 -0500
committerOmar Roth <omarroth@protonmail.com>2019-07-24 19:18:26 -0500
commit607d6125fc50839115edd856e2862e5ccdcf3085 (patch)
tree0cfc331e9c3bb6f84ebe08634f84fe71bb23e97d
parent62152595652c7757e89a754811ae164b40cd08b3 (diff)
downloadinvidious-607d6125fc50839115edd856e2862e5ccdcf3085.tar.gz
invidious-607d6125fc50839115edd856e2862e5ccdcf3085.tar.bz2
invidious-607d6125fc50839115edd856e2862e5ccdcf3085.zip
Add support for '/embed/live_stream'
-rw-r--r--src/invidious.cr24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 0371ded4..a3b5bd1a 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -559,7 +559,8 @@ get "/embed/:id" do |env|
# YouTube embed supports `videoseries` with either `list=PLID`
# or `playlist=VIDEO_ID,VIDEO_ID`
- if id == "videoseries"
+ case id
+ when "videoseries"
url = ""
if plid
@@ -584,7 +585,26 @@ get "/embed/:id" do |env|
end
next env.redirect url
- elsif id.size > 11
+ when "live_stream"
+ client = make_client(YT_URL)
+ response = client.get("/embed/live_stream?channel=#{env.params.query["channel"]? || ""}")
+ video_id = response.body.match(/"video_id":"(?<video_id>[a-zA-Z0-9_-]{11})"/).try &.["video_id"]
+
+ env.params.query.delete_all("channel")
+
+ if !video_id || video_id == "live_stream"
+ error_message = "Video is unavailable."
+ next templated "error"
+ end
+
+ url = "/embed/#{video_id}"
+
+ if env.params.query.size > 0
+ url += "?#{env.params.query}"
+ end
+
+ next env.redirect url
+ when id.size > 11
url = "/embed/#{id[0, 11]}"
if env.params.query.size > 0