From d659a451d6dece62dbb091a958083c8a347da5b1 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Tue, 23 Aug 2022 19:04:08 +0200 Subject: [PATCH] videos: remove unused 'VideoRedirect' exception --- src/invidious/jsonify/api_v1/common.cr | 18 ++++++++++++++++++ src/invidious/jsonify/api_v1/video_json.cr | 13 ------------- src/invidious/routes/api/manifest.cr | 2 -- src/invidious/routes/api/v1/videos.cr | 9 --------- src/invidious/routes/embed.cr | 2 -- src/invidious/routes/watch.cr | 2 -- src/invidious/videos.cr | 7 ------- 7 files changed, 18 insertions(+), 35 deletions(-) create mode 100644 src/invidious/jsonify/api_v1/common.cr diff --git a/src/invidious/jsonify/api_v1/common.cr b/src/invidious/jsonify/api_v1/common.cr new file mode 100644 index 00000000..64b06465 --- /dev/null +++ b/src/invidious/jsonify/api_v1/common.cr @@ -0,0 +1,18 @@ +require "json" + +module Invidious::JSONify::APIv1 + extend self + + def thumbnails(json : JSON::Builder, id : String) + json.array do + build_thumbnails(id).each do |thumbnail| + json.object do + json.field "quality", thumbnail[:name] + json.field "url", "#{thumbnail[:host]}/vi/#{id}/#{thumbnail["url"]}.jpg" + json.field "width", thumbnail[:width] + json.field "height", thumbnail[:height] + end + end + end + end +end diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 1082f6d3..0a5173ce 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -222,19 +222,6 @@ module Invidious::JSONify::APIv1 end end - def thumbnails(json, id) - json.array do - build_thumbnails(id).each do |thumbnail| - json.object do - json.field "quality", thumbnail[:name] - json.field "url", "#{thumbnail[:host]}/vi/#{id}/#{thumbnail["url"]}.jpg" - json.field "width", thumbnail[:width] - json.field "height", thumbnail[:height] - end - end - end - end - def storyboards(json, id, storyboards) json.array do storyboards.each do |storyboard| diff --git a/src/invidious/routes/api/manifest.cr b/src/invidious/routes/api/manifest.cr index bfb8a377..ae65f10d 100644 --- a/src/invidious/routes/api/manifest.cr +++ b/src/invidious/routes/api/manifest.cr @@ -14,8 +14,6 @@ module Invidious::Routes::API::Manifest begin video = get_video(id, region: region) - rescue ex : VideoRedirect - return env.redirect env.request.resource.gsub(id, ex.video_id) rescue ex : NotFoundException haltf env, status_code: 404 rescue ex diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index 6f1f5916..a6b2eb4e 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -9,9 +9,6 @@ module Invidious::Routes::API::V1::Videos begin video = get_video(id, region: region) - rescue ex : VideoRedirect - env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id) - return error_json(302, "Video is unavailable", {"videoId" => ex.video_id}) rescue ex : NotFoundException return error_json(404, ex) rescue ex @@ -41,9 +38,6 @@ module Invidious::Routes::API::V1::Videos begin video = get_video(id, region: region) - rescue ex : VideoRedirect - env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id) - return error_json(302, "Video is unavailable", {"videoId" => ex.video_id}) rescue ex : NotFoundException haltf env, 404 rescue ex @@ -168,9 +162,6 @@ module Invidious::Routes::API::V1::Videos begin video = get_video(id, region: region) - rescue ex : VideoRedirect - env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id) - return error_json(302, "Video is unavailable", {"videoId" => ex.video_id}) rescue ex : NotFoundException haltf env, 404 rescue ex diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr index e6486587..289d87c9 100644 --- a/src/invidious/routes/embed.cr +++ b/src/invidious/routes/embed.cr @@ -131,8 +131,6 @@ module Invidious::Routes::Embed begin video = get_video(id, region: params.region) - rescue ex : VideoRedirect - return env.redirect env.request.resource.gsub(id, ex.video_id) rescue ex : NotFoundException return error_template(404, ex) rescue ex diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index fe1d8e54..5f481557 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -61,8 +61,6 @@ module Invidious::Routes::Watch begin video = get_video(id, region: params.region) - rescue ex : VideoRedirect - return env.redirect env.request.resource.gsub(id, ex.video_id) rescue ex : NotFoundException LOGGER.error("get_video not found: #{id} : #{ex.message}") return error_template(404, ex) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index fcc9a8a4..bec26de9 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -319,13 +319,6 @@ struct Video getset_bool isUpcoming end -class VideoRedirect < Exception - property video_id : String - - def initialize(@video_id) - end -end - def get_video(id, refresh = true, region = nil, force_refresh = false) if (video = Invidious::Database::Videos.select(id)) && !region # If record was last updated over 10 minutes ago, or video has since premiered,