From ac8fb9d8c8d9a102ae11460d0e04b9948d0b092d Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 19 Jul 2018 11:04:29 -0500 Subject: [PATCH] Add 'raw' and 'quality' options to embedded videos --- src/invidious.cr | 19 +++++++++++++++++++ src/invidious/views/embed.ecr | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index ae3f463c..73a8eee3 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -422,6 +422,13 @@ get "/embed/:id" do |env| end listen ||= false + raw = env.params.query["raw"]? && env.params.query["raw"].to_i + raw ||= 0 + raw = raw == 1 + + quality = env.params.query["quality"]? && env.params.query["quality"] + quality ||= "hd720" + autoplay = env.params.query["autoplay"]?.try &.to_i autoplay ||= 0 @@ -472,6 +479,18 @@ get "/embed/:id" do |env| stream["bitrate"] = (stream["bitrate"].to_f64/1000).to_i.to_s end + if raw + url = fmt_stream[0]["url"] + + fmt_stream.each do |fmt| + if fmt["label"].split(" - ")[0] == quality + url = fmt["url"] + end + end + + next env.redirect url + end + thumbnail = "https://i.ytimg.com/vi/#{id}/mqdefault.jpg" rendered "embed" diff --git a/src/invidious/views/embed.ecr b/src/invidious/views/embed.ecr index 3b3b1d5c..27c2d495 100644 --- a/src/invidious/views/embed.ecr +++ b/src/invidious/views/embed.ecr @@ -40,7 +40,11 @@ video, #my_video, .video-js, .vjs-default-skin <% end %> <% else %> <% fmt_stream.each_with_index do |fmt, i| %> + <% if quality != "hd720" %> + " type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= quality == fmt["label"].split(" - ")[0] %>"> + <% else %> " type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>"> + <% end %> <% end %> <% end %>