From 48da2ced4656b026c19b35ed87fdaa5a2c6bb234 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 19 Mar 2018 12:35:35 -0500 Subject: [PATCH] Add error handling for top videos --- src/helpers.cr | 9 +++++++-- src/invidious.cr | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/helpers.cr b/src/helpers.cr index e75ce4ed..4d6666ca 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -259,7 +259,12 @@ def rank_videos(db, n, pool, filter) break else client = get_client(pool) - video = get_video(id, client, db) + begin + video = get_video(id, client, db) + rescue ex + next + end + pool << client if video.language @@ -267,7 +272,7 @@ def rank_videos(db, n, pool, filter) else description = XML.parse(video.description) content = [video.title, description.content].join(" ") - content = content[0,10000] + content = content[0, 10000] results = DetectLanguage.detect(content) language = results[0].language diff --git a/src/invidious.cr b/src/invidious.cr index 7c804e56..73fb339f 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -135,7 +135,11 @@ spawn do end loop do - top = rank_videos(PG_DB, 40, youtube_pool, filter) + begin + top = rank_videos(PG_DB, 40, youtube_pool, filter) + rescue ex + next + end if top.size > 0 args = arg_array(top) @@ -150,6 +154,7 @@ spawn do begin videos << get_video(id, client, PG_DB) rescue ex + next end youtube_pool << client end