summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFijxu <fijxu@nadeko.net>2024-05-13 21:07:46 -0400
committerFijxu <fijxu@nadeko.net>2024-05-13 21:07:46 -0400
commite0d0dbde3cd1cba313d990244977a890a32976de (patch)
tree8d4761de15fe262b46be56803e65ae4e8e1a9465 /src
parenteda7444ca46dbc3941205316baba8030fe0b2989 (diff)
downloadinvidious-e0d0dbde3cd1cba313d990244977a890a32976de.tar.gz
invidious-e0d0dbde3cd1cba313d990244977a890a32976de.tar.bz2
invidious-e0d0dbde3cd1cba313d990244977a890a32976de.zip
API: Check if playlist has any videos on it.
Invidious assumes that every playlist will have at least one video because it needs to check for the `index` key. So if there is no videos on a playlist, there is no `index` key and Invidious throws `Index out of bounds`
Diffstat (limited to 'src')
-rw-r--r--src/invidious/routes/api/v1/misc.cr4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr
index 12942906..0c79692d 100644
--- a/src/invidious/routes/api/v1/misc.cr
+++ b/src/invidious/routes/api/v1/misc.cr
@@ -74,7 +74,9 @@ module Invidious::Routes::API::V1::Misc
response = playlist.to_json(offset, video_id: video_id)
json_response = JSON.parse(response)
- if json_response["videos"].as_a[0]["index"] != offset
+ if json_response["videos"].as_a.empty?
+ json_response = JSON.parse(response)
+ elsif json_response["videos"].as_a[0]["index"] != offset
offset = json_response["videos"].as_a[0]["index"].as_i
lookback = offset < 50 ? offset : 50
response = playlist.to_json(offset - lookback)