mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-21 21:17:20 +00:00
Add audio-only
This commit is contained in:
parent
90fe4ab4b4
commit
d1eb81b653
@ -107,11 +107,19 @@ context = OpenSSL::SSL::Context::Client.insecure
|
||||
get "/watch" do |env|
|
||||
video_id = env.params.query["v"]
|
||||
|
||||
if env.params.query["listen"]? && env.params.query["listen"] == "true"
|
||||
env.request.query_params.delete_all("listen")
|
||||
listen = true
|
||||
else
|
||||
env.request.query_params["listen"] = "true"
|
||||
listen = false
|
||||
end
|
||||
|
||||
if pg.query_one?("select exists (select true from videos where video_id = $1)", video_id, as: Bool)
|
||||
video_record = pg.query_one("select * from videos where video_id = $1", video_id, as: Video)
|
||||
|
||||
# If record was last updated more than 1 hour ago, refresh
|
||||
if Time.now - video_record.last_updated > Time::Span.new(1, 0, 0, 0)
|
||||
# If record was last updated more than 5 hours ago, refresh (expire param in response lasts for 6 hours)
|
||||
if Time.now - video_record.last_updated > Time::Span.new(0, 5, 0, 0)
|
||||
video_record = get_video(video_id, context)
|
||||
pg.exec("update videos set last_updated = $1, video_info = $3, video_html = $4,\
|
||||
views = $5, likes = $6, dislikes = $7, rating = $8, description = $9 where video_id = $2",
|
||||
@ -140,6 +148,11 @@ get "/watch" do |env|
|
||||
fmt_stream << HTTP::Params.parse(string)
|
||||
end
|
||||
|
||||
adaptive_fmts = [] of HTTP::Params
|
||||
video_info["adaptive_fmts"].split(",") do |string|
|
||||
adaptive_fmts << HTTP::Params.parse(string)
|
||||
end
|
||||
|
||||
fmt_stream.reverse! # We want lowest quality first
|
||||
|
||||
related_videos = video_html.xpath_nodes(%q(//li/div/a[contains(@class,"content-link")]/@href))
|
||||
|
@ -1,10 +1,23 @@
|
||||
<title><%= video_info["title"] %> - Invidious</title>
|
||||
<video style="width: 100%" poster="<%= video_info.has_key?("iurlhq720") ? video_info["iurlhq720"] : video_info["iurlmq"] %>" controls>
|
||||
<% fmt_stream.each do |fmt| %>
|
||||
<source src="<%= fmt["url"] %>" type="<%= fmt["type"].split(";")[0] %>">
|
||||
<% if listen %>
|
||||
<% adaptive_fmts.each do |fmt| %>
|
||||
<% url = fmt["url"] %>
|
||||
<% type = fmt["type"].to_s.split(";")[0] %>
|
||||
<% if type.starts_with?("audio") %>
|
||||
<source src="<%= url %>" type="<%= type %>">
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% fmt_stream.each do |fmt| %>
|
||||
<source src="<%= fmt["url"] %>" type="<%= fmt["type"].split(";")[0] %>">
|
||||
<% end %>
|
||||
<% end %>
|
||||
</video>
|
||||
<h1><%= video_info["title"] %></h1>
|
||||
<h1><%= video_info["title"] %> <a href="/watch?<%= env.request.query %>">
|
||||
<i class="fa <%= listen ? "fa-video-camera" : "fa-volume-up" %>" aria-hidden="true"></i>
|
||||
</a>
|
||||
</h1>
|
||||
<div class="pure-g">
|
||||
<div class="pure-u-1 pure-u-md-1-5">
|
||||
<p><i class="fa fa-eye" aria-hidden="true"></i> <%= video_record.views %></p>
|
||||
|
Loading…
Reference in New Issue
Block a user