From e37e9a0b8e36cf5996ef64c6199d814e035faff8 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 13 Mar 2018 18:37:56 -0500 Subject: Add qualityselector --- src/invidious.cr | 48 ++++++++++++++++++++++++++++------------------ src/views/player/audio.ecr | 6 ++---- src/views/player/video.ecr | 2 +- src/views/watch.ecr | 43 ++++++++++++++++++++++++++--------------- 4 files changed, 60 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/invidious.cr b/src/invidious.cr index 6580bdf0..255ecc3c 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -189,14 +189,6 @@ get "/watch" do |env| fmt_stream << HTTP::Params.parse(string) end - signature = false - if fmt_stream[0]? && fmt_stream[0]["s"]? - signature = true - end - - # We want lowest quality first - fmt_stream.reverse! - adaptive_fmts = [] of HTTP::Params if video.info.has_key?("adaptive_fmts") video.info["adaptive_fmts"].split(",") do |string| @@ -204,6 +196,11 @@ get "/watch" do |env| end end + signature = false + if adaptive_fmts[0]? && adaptive_fmts[0]["s"]? + signature = true + end + if signature adaptive_fmts.each do |fmt| fmt["url"] += "&signature=" + decrypt_signature(fmt["s"]) @@ -214,6 +211,19 @@ get "/watch" do |env| end end + # 3gpp doesn't appear to play correclty in Chrome, so here we remove it + fmt_stream = fmt_stream.compact_map { |s| !s["type"].starts_with?("video/3gpp") ? s : nil } + fmt_stream = fmt_stream.uniq { |s| s["quality"] } + + video_streams = adaptive_fmts.compact_map { |s| s["type"].starts_with?("video") ? s : nil } + video_streams = video_streams.uniq { |s| s["size"] } + + audio_streams = adaptive_fmts.compact_map { |s| s["type"].starts_with?("audio") ? s : nil } + audio_streams.sort_by! { |s| s["bitrate"].to_i }.reverse! + audio_streams.each do |fmt| + fmt["bitrate"] = (fmt["bitrate"].to_f64/1000).to_i.to_s + end + rvs = [] of Hash(String, String) if video.info.has_key?("rvs") video.info["rvs"].split(",").each do |rv| @@ -358,7 +368,7 @@ get "/api/manifest/dash/id/:id" do |env| end if signature - adaptive_fmts.each do |fmt| + adaptive_fmts.each do |fmt| fmt["url"] += "&signature=" + decrypt_signature(fmt["s"]) end end @@ -379,20 +389,20 @@ get "/api/manifest/dash/id/:id" do |env| xml.element("AdaptationSet", id: 0, mimeType: "audio/mp4", subsegmentAlignment: true) do xml.element("Role", schemeIdUri: "urn:mpeg:DASH:role:2011", value: "main") video_streams.each do |fmt| - mimetype, codecs = fmt["type"].split(";") - codecs = codecs[9..-2] - fmt_type = mimetype.split("/")[0] - bandwidth = fmt["bitrate"] + mimetype, codecs = fmt["type"].split(";") + codecs = codecs[9..-2] + fmt_type = mimetype.split("/")[0] + bandwidth = fmt["bitrate"] itag = fmt["itag"] url = URI.unescape(fmt["url"]) xml.element("Representation", id: fmt["itag"], codecs: codecs, bandwidth: bandwidth) do xml.element("BaseURL") { xml.cdata url } - xml.element("SegmentBase", indexRange: fmt["init"]) do - xml.element("Initialization", range: fmt["index"]) - end + xml.element("SegmentBase", indexRange: fmt["init"]) do + xml.element("Initialization", range: fmt["index"]) end end + end end xml.element("AdaptationSet", id: 1, mimeType: "video/mp4", subsegmentAlignment: true) do @@ -408,15 +418,15 @@ get "/api/manifest/dash/id/:id" do |env| xml.element("Representation", id: itag, codecs: codecs, width: width, height: height, bandwidth: bandwidth, frameRate: fmt["fps"]) do xml.element("BaseURL") { xml.cdata url } - xml.element("SegmentBase", indexRange: fmt["init"]) do - xml.element("Initialization", range: fmt["index"]) - end + xml.element("SegmentBase", indexRange: fmt["init"]) do + xml.element("Initialization", range: fmt["index"]) end end end end end end + end manifest = manifest.gsub(%(), %()) manifest = manifest.gsub(%(), %()) diff --git a/src/views/player/audio.ecr b/src/views/player/audio.ecr index 35273a61..c5f7a30c 100644 --- a/src/views/player/audio.ecr +++ b/src/views/player/audio.ecr @@ -1,7 +1,5 @@ \ No newline at end of file diff --git a/src/views/player/video.ecr b/src/views/player/video.ecr index 90abe438..f986f003 100644 --- a/src/views/player/video.ecr +++ b/src/views/player/video.ecr @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/src/views/watch.ecr b/src/views/watch.ecr index 59cdda04..423db4fd 100644 --- a/src/views/watch.ecr +++ b/src/views/watch.ecr @@ -1,24 +1,37 @@ <% content_for "header" do %> + + <%= video.title %> - Invidious <% end %>
-<% if listen %> -<%= render "src/views/player/audio.ecr" %> -<% else %> -<%= render "src/views/player/video.ecr" %> -<% end %> + <% if listen %> + <%= render "src/views/player/audio.ecr" %> + <% else %> + <%= render "src/views/player/video.ecr" %> + <% end %>
@@ -128,21 +141,21 @@ function toggle_comments(target) {
<% if reddit_thread && !reddit_html.empty? %>
-
+

[ - ] <%= reddit_thread.data.title %>

- - View more comments on Reddit - + + View more comments on Reddit +
- <%= reddit_html %> -
+ <%= reddit_html %> +
- <% end %> - + <% end %> +
-- cgit v1.2.3