Use local links for video playback

This commit is contained in:
Omar Roth 2018-05-29 18:40:36 -05:00
parent f79825fc80
commit 61cd135780

View File

@ -281,6 +281,12 @@ get "/watch" do |env|
end end
end end
fmt_stream.each { |s| s.add("label", "#{s["quality"]} - #{s["type"].split(";")[0].split("/")[1]}") }
fmt_stream = fmt_stream.uniq { |s| s["label"] }
fmt_stream.each do |stream|
stream["url"] = URI.parse(stream["url"]).full_path
end
adaptive_fmts = [] of HTTP::Params adaptive_fmts = [] of HTTP::Params
if video.info.has_key?("adaptive_fmts") if video.info.has_key?("adaptive_fmts")
video.info["adaptive_fmts"].split(",") do |string| video.info["adaptive_fmts"].split(",") do |string|
@ -298,16 +304,11 @@ get "/watch" do |env|
end end
end end
fmt_stream.each { |s| s.add("label", "#{s["quality"]} - #{s["type"].split(";")[0].split("/")[1]}") }
fmt_stream = fmt_stream.uniq { |s| s["label"] }
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 = adaptive_fmts.compact_map { |s| s["type"].starts_with?("audio") ? s : nil }
audio_streams.sort_by! { |s| s["bitrate"].to_i }.reverse! audio_streams.sort_by! { |s| s["bitrate"].to_i }.reverse!
audio_streams.each do |fmt| audio_streams.each do |stream|
fmt["bitrate"] = (fmt["bitrate"].to_f64/1000).to_i.to_s stream["bitrate"] = (stream["bitrate"].to_f64/1000).to_i.to_s
stream["url"] = URI.parse(stream["url"]).full_path
end end
rvs = [] of Hash(String, String) rvs = [] of Hash(String, String)