diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 6508c847..c0c2f37b 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -238,13 +238,12 @@ class Config end {% end %} - if !config.invidious_companion.empty? + if config.invidious_companion.present? # invidious_companion and signature_server can't work together if config.signature_server puts "Config: You can not run inv_sig_helper and invidious_companion at the same time." exit(1) - end - if config.invidious_companion_key.empty? + elsif config.invidious_companion_key.empty? puts "Config: Please configure a key if you are using invidious companion." exit(1) elsif config.invidious_companion_key == "CHANGE_ME!!" diff --git a/src/invidious/routes/api/manifest.cr b/src/invidious/routes/api/manifest.cr index b2085666..e32d6f2e 100644 --- a/src/invidious/routes/api/manifest.cr +++ b/src/invidious/routes/api/manifest.cr @@ -8,7 +8,7 @@ module Invidious::Routes::API::Manifest id = env.params.url["id"] region = env.params.query["region"]? - if !CONFIG.invidious_companion.empty? + if CONFIG.invidious_companion.present? invidious_companion = CONFIG.invidious_companion.sample return env.redirect "#{invidious_companion.public_url}/api/manifest/dash/id/#{id}?#{env.params.query}" end diff --git a/src/invidious/routes/video_playback.cr b/src/invidious/routes/video_playback.cr index 391aa139..9c35ffcc 100644 --- a/src/invidious/routes/video_playback.cr +++ b/src/invidious/routes/video_playback.cr @@ -253,7 +253,7 @@ module Invidious::Routes::VideoPlayback # YouTube /videoplayback links expire after 6 hours, # so we have a mechanism here to redirect to the latest version def self.latest_version(env) - if !CONFIG.invidious_companion.empty? + if CONFIG.invidious_companion.present? invidious_companion = CONFIG.invidious_companion.sample return env.redirect "#{invidious_companion.public_url}/latest_version?#{env.params.query}" end diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index 91aca03e..66d5977c 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -333,7 +333,7 @@ module Invidious::Routes::Watch env.params.query["title"] = filename env.params.query["local"] = "true" - if (!CONFIG.invidious_companion.empty?) + if (CONFIG.invidious_companion.present?) video = get_video(video_id) return env.redirect "#{video.invidious_companion["baseUrl"].as_s}/latest_version?#{env.params.query}" else diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr index 4d0e0378..b25db0b7 100644 --- a/src/invidious/videos/parser.cr +++ b/src/invidious/videos/parser.cr @@ -100,7 +100,7 @@ def extract_video_info(video_id : String) params = parse_video_info(video_id, player_response) params["reason"] = JSON::Any.new(reason) if reason - if !CONFIG.invidious_companion.empty? + if CONFIG.invidious_companion.present? new_player_response = nil # Don't use Android test suite client if po_token is passed because po_token doesn't diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr index 37f5f586..d7589381 100644 --- a/src/invidious/views/components/player.ecr +++ b/src/invidious/views/components/player.ecr @@ -23,7 +23,7 @@ src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}" src_url += "&local=true" if params.local src_url = video.invidious_companion["baseUrl"].as_s + src_url + - "&check=#{invidious_companion_encrypt(video.id)}" if (!CONFIG.invidious_companion.empty?) + "&check=#{invidious_companion_encrypt(video.id)}" if (CONFIG.invidious_companion.present?) bitrate = fmt["bitrate"] mimetype = HTML.escape(fmt["mimeType"].as_s) @@ -39,7 +39,7 @@ <% if params.quality == "dash" src_url = "/api/manifest/dash/id/" + video.id + "?local=true&unique_res=1" src_url = video.invidious_companion["baseUrl"].as_s + src_url + - "&check=#{invidious_companion_encrypt(video.id)}" if (!CONFIG.invidious_companion.empty?) + "&check=#{invidious_companion_encrypt(video.id)}" if (CONFIG.invidious_companion.present?) %> <% end %> @@ -51,7 +51,7 @@ src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}" src_url += "&local=true" if params.local src_url = video.invidious_companion["baseUrl"].as_s + src_url + - "&check=#{invidious_companion_encrypt(video.id)}" if (!CONFIG.invidious_companion.empty?) + "&check=#{invidious_companion_encrypt(video.id)}" if (CONFIG.invidious_companion.present?) quality = fmt["quality"] mimetype = HTML.escape(fmt["mimeType"].as_s) diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 74f65449..54a0f5f4 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -500,7 +500,7 @@ module YoutubeAPI data["params"] = params end - if !CONFIG.invidious_companion.empty? + if CONFIG.invidious_companion.present? return self._post_invidious_companion("/youtubei/v1/player", data) else return self._post_json("/youtubei/v1/player", data, client_config) @@ -696,7 +696,7 @@ module YoutubeAPI begin invidious_companion = CONFIG.invidious_companion.sample - response = make_client(invidious_companion.private_url, + response = make_client(invidious_companion.private_url, use_http_proxy: false &.post(endpoint, headers: headers, body: data.to_json)) body = response.body if (response.status_code != 200)