summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr17
-rw-r--r--src/views/watch.ecr19
2 files changed, 31 insertions, 5 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 33be4c6f..41956e42 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -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))
diff --git a/src/views/watch.ecr b/src/views/watch.ecr
index 30aa9a61..12799fb6 100644
--- a/src/views/watch.ecr
+++ b/src/views/watch.ecr
@@ -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>