From 0cf86974dd840137ac5202acc0919f5d0a8ff3c2 Mon Sep 17 00:00:00 2001
From: Omar Roth <omarroth@protonmail.com>
Date: Sat, 4 May 2019 10:47:54 -0500
Subject: [PATCH] Add redirect for videos with no audio sources

---
 src/invidious.cr | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/invidious.cr b/src/invidious.cr
index 0a891ba9..cf0d7c46 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -419,6 +419,12 @@ get "/watch" do |env|
   video_streams = video.video_streams(adaptive_fmts)
   audio_streams = video.audio_streams(adaptive_fmts)
 
+  # Older videos may not have audio sources available.
+  # We redirect here so they're not unplayable
+  if params.listen && audio_streams.empty?
+    next env.redirect "/watch?#{env.params.query}&listen=0"
+  end
+
   captions = video.captions
 
   preferred_captions = captions.select { |caption|