From d1eb81b6533fd81eac94a64ccc929f4de517f48e Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Wed, 3 Jan 2018 20:06:16 -0600 Subject: [PATCH] Add audio-only --- src/invidious.cr | 17 +++++++++++++++-- src/views/watch.ecr | 19 ++++++++++++++++--- 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 @@ <%= video_info["title"] %> - Invidious -

<%= video_info["title"] %>

+

<%= video_info["title"] %> + " aria-hidden="true"> + +

<%= video_record.views %>