From 1e214aae7cedbb0770312e3eb2901216d27e6da7 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 29 Jan 2019 19:55:27 -0600 Subject: Reload player instead of removing invalid source --- src/invidious/views/components/player.ecr | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'src') diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr index 80879b67..b165985f 100644 --- a/src/invidious/views/components/player.ecr +++ b/src/invidious/views/components/player.ecr @@ -115,7 +115,7 @@ var player = videojs("player", options, function() { }); player.on('error', function(event) { - if (player.error().code === 2) { + if (player.error().code === 2 || player.error().code === 4) { console.log("An error occured in the player, reloading..."); var currentTime = player.currentTime(); @@ -126,25 +126,6 @@ player.on('error', function(event) { } player.currentTime(currentTime); player.playbackRate(playbackRate); - player.play() - } else if (player.error().code === 4) { - console.log("Detected invalid source, removing..."); - var currentTime = player.currentTime(); - var sources = player.options().sources; - - for (var i = 0; i < sources.length; i++) { - if (sources[i].src === player.currentSource().src) { - sources.splice(i, 1); - break - } - }; - - player.load(); - if (currentTime > 0.5) { - currentTime -= 0.5; - } - player.currentTime(currentTime); - player.src(sources); player.play(); } }); -- cgit v1.2.3 From 9e73e3b15326bfac7c94a2cd997f742abbe66305 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 31 Jan 2019 08:48:44 -0600 Subject: Add errorcode for invalid video IDs --- src/invidious/videos.cr | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index ec911e3f..6298fa4e 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -633,6 +633,10 @@ def fetch_video(id, proxies, region) end end + if info["errorcode"]?.try &.== "2" + raise "Video unavailable." + end + title = info["title"] author = info["author"] ucid = info["ucid"] -- cgit v1.2.3 From def58ff11f226f6d8f6cafc7b743e8ba2434fd72 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 31 Jan 2019 09:09:00 -0600 Subject: Add interval and timeout for errors in player --- src/invidious/views/components/player.ecr | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr index b165985f..9efe04fc 100644 --- a/src/invidious/views/components/player.ecr +++ b/src/invidious/views/components/player.ecr @@ -116,17 +116,19 @@ var player = videojs("player", options, function() { player.on('error', function(event) { if (player.error().code === 2 || player.error().code === 4) { - console.log("An error occured in the player, reloading..."); + setInterval(setTimeout(function (event) { + console.log("An error occured in the player, reloading..."); - var currentTime = player.currentTime(); - var playbackRate = player.playbackRate(); - player.load(); - if (currentTime > 0.5) { - currentTime -= 0.5; - } - player.currentTime(currentTime); - player.playbackRate(playbackRate); - player.play(); + var currentTime = player.currentTime(); + var playbackRate = player.playbackRate(); + player.load(); + if (currentTime > 0.5) { + currentTime -= 0.5; + } + player.currentTime(currentTime); + player.playbackRate(playbackRate); + player.play(); + }, 5000), 5000); } }); -- cgit v1.2.3 From cef061d6fb62cee6ebd87c7d98c778fccb9271bb Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 31 Jan 2019 14:40:26 -0600 Subject: Fix incorrect default in user preferences --- src/invidious.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/invidious.cr b/src/invidious.cr index a720670a..69bbed77 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1146,7 +1146,7 @@ post "/preferences" do |env| captions = [captions_0, captions_1, captions_2] related_videos = env.params.body["related_videos"]?.try &.as(String) - related_videos ||= "off" + related_videos ||= "on" related_videos = related_videos == "on" redirect_feed = env.params.body["redirect_feed"]?.try &.as(String) -- cgit v1.2.3 From fbb5df084990a67e934d9aeb8fc535a0a7198b8e Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 31 Jan 2019 14:54:02 -0600 Subject: Default to showing recommendations for logged out users --- src/invidious.cr | 2 +- src/invidious/views/watch.ecr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/invidious.cr b/src/invidious.cr index 69bbed77..a720670a 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1146,7 +1146,7 @@ post "/preferences" do |env| captions = [captions_0, captions_1, captions_2] related_videos = env.params.body["related_videos"]?.try &.as(String) - related_videos ||= "on" + related_videos ||= "off" related_videos = related_videos == "on" redirect_feed = env.params.body["redirect_feed"]?.try &.as(String) diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index dc58d48d..a8f98492 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -141,7 +141,7 @@ - <% if preferences && preferences.related_videos || plid %> + <% if !preferences || preferences && preferences.related_videos || plid %>
<% if plid %>
-- cgit v1.2.3 From c9bc081f8c4d3b6d7d19d911f6b1944c5f461e77 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 31 Jan 2019 15:06:53 -0600 Subject: Respect DEFAULT_USER_PREFERENCES in video params --- src/invidious.cr | 22 +++++++++++----------- src/invidious/users.cr | 18 +++++++++--------- src/invidious/videos.cr | 16 ++++++++-------- 3 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/invidious.cr b/src/invidious.cr index a720670a..99f9e1af 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1128,21 +1128,21 @@ post "/preferences" do |env| listen = listen == "on" speed = env.params.body["speed"]?.try &.as(String).to_f? - speed ||= 1.0 + speed ||= DEFAULT_USER_PREFERENCES.speed quality = env.params.body["quality"]?.try &.as(String) - quality ||= "hd720" + quality ||= DEFAULT_USER_PREFERENCES.quality volume = env.params.body["volume"]?.try &.as(String).to_i? - volume ||= 100 + volume ||= DEFAULT_USER_PREFERENCES.volume - comments_0 = env.params.body["comments_0"]?.try &.as(String) || "youtube" - comments_1 = env.params.body["comments_1"]?.try &.as(String) || "" + comments_0 = env.params.body["comments_0"]?.try &.as(String) || DEFAULT_USER_PREFERENCES.comments[0] + comments_1 = env.params.body["comments_1"]?.try &.as(String) || DEFAULT_USER_PREFERENCES.comments[1] comments = [comments_0, comments_1] - captions_0 = env.params.body["captions_0"]?.try &.as(String) || "" - captions_1 = env.params.body["captions_1"]?.try &.as(String) || "" - captions_2 = env.params.body["captions_2"]?.try &.as(String) || "" + captions_0 = env.params.body["captions_0"]?.try &.as(String) || DEFAULT_USER_PREFERENCES.captions[0] + captions_1 = env.params.body["captions_1"]?.try &.as(String) || DEFAULT_USER_PREFERENCES.captions[1] + captions_2 = env.params.body["captions_2"]?.try &.as(String) || DEFAULT_USER_PREFERENCES.captions[2] captions = [captions_0, captions_1, captions_2] related_videos = env.params.body["related_videos"]?.try &.as(String) @@ -1154,7 +1154,7 @@ post "/preferences" do |env| redirect_feed = redirect_feed == "on" locale = env.params.body["locale"]?.try &.as(String) - locale ||= "en-US" + locale ||= DEFAULT_USER_PREFERENCES.locale dark_mode = env.params.body["dark_mode"]?.try &.as(String) dark_mode ||= "off" @@ -1165,10 +1165,10 @@ post "/preferences" do |env| thin_mode = thin_mode == "on" max_results = env.params.body["max_results"]?.try &.as(String).to_i? - max_results ||= 40 + max_results ||= DEFAULT_USER_PREFERENCES.max_results sort = env.params.body["sort"]?.try &.as(String) - sort ||= "published" + sort ||= DEFAULT_USER_PREFERENCES.sort latest_only = env.params.body["latest_only"]?.try &.as(String) latest_only ||= "off" diff --git a/src/invidious/users.cr b/src/invidious/users.cr index dbbe87f8..d45c5af4 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -79,36 +79,36 @@ class Preferences autoplay: Bool, continue: { type: Bool, - default: false, + default: DEFAULT_USER_PREFERENCES.continue, }, listen: { type: Bool, - default: false, + default: DEFAULT_USER_PREFERENCES.listen, }, speed: Float32, quality: String, volume: Int32, comments: { type: Array(String), - default: ["youtube", ""], + default: DEFAULT_USER_PREFERENCES.comments, converter: StringToArray, }, captions: { type: Array(String), - default: ["", "", ""], + default: DEFAULT_USER_PREFERENCES.captions, }, redirect_feed: { type: Bool, - default: false, + default: DEFAULT_USER_PREFERENCES.redirect_feed, }, related_videos: { type: Bool, - default: true, + default: DEFAULT_USER_PREFERENCES.related_videos, }, dark_mode: Bool, thin_mode: { type: Bool, - default: false, + default: DEFAULT_USER_PREFERENCES.thin_mode, }, max_results: Int32, sort: String, @@ -116,11 +116,11 @@ class Preferences unseen_only: Bool, notifications_only: { type: Bool, - default: false, + default: DEFAULT_USER_PREFERENCES.notifications_only, }, locale: { type: String, - default: "en-US", + default: DEFAULT_USER_PREFERENCES.locale, }, }) end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 6298fa4e..a95f5443 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -745,14 +745,14 @@ def process_video_params(query, preferences) volume ||= preferences.volume end - autoplay ||= 0 - continue ||= 0 - listen ||= 0 - preferred_captions ||= [] of String - quality ||= "hd720" - speed ||= 1 - video_loop ||= 0 - volume ||= 100 + autoplay ||= DEFAULT_USER_PREFERENCES.autoplay.to_unsafe + continue ||= DEFAULT_USER_PREFERENCES.continue.to_unsafe + listen ||= DEFAULT_USER_PREFERENCES.listen.to_unsafe + preferred_captions ||= DEFAULT_USER_PREFERENCES.captions + quality ||= DEFAULT_USER_PREFERENCES.quality + speed ||= DEFAULT_USER_PREFERENCES.speed + video_loop ||= DEFAULT_USER_PREFERENCES.video_loop.to_unsafe + volume ||= DEFAULT_USER_PREFERENCES.volume autoplay = autoplay == 1 continue = continue == 1 -- cgit v1.2.3 From d5c9b7dfe8055e939c555c32d106f02c7f983120 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 31 Jan 2019 20:25:58 -0600 Subject: Only play after error if already playing --- src/invidious/views/components/player.ecr | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr index 9efe04fc..7f932ef4 100644 --- a/src/invidious/views/components/player.ecr +++ b/src/invidious/views/components/player.ecr @@ -121,13 +121,18 @@ player.on('error', function(event) { var currentTime = player.currentTime(); var playbackRate = player.playbackRate(); + var paused = player.paused() + player.load(); if (currentTime > 0.5) { currentTime -= 0.5; } player.currentTime(currentTime); player.playbackRate(playbackRate); - player.play(); + + if (!paused) { + player.play(); + } }, 5000), 5000); } }); -- cgit v1.2.3