mirror of
https://gitea.invidious.io/iv-org/invidious.git
synced 2024-08-15 00:53:41 +00:00
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`
This commit is contained in:
parent
eda7444ca4
commit
e0d0dbde3c
1 changed files with 3 additions and 1 deletions
|
@ -74,7 +74,9 @@ module Invidious::Routes::API::V1::Misc
|
||||||
response = playlist.to_json(offset, video_id: video_id)
|
response = playlist.to_json(offset, video_id: video_id)
|
||||||
json_response = JSON.parse(response)
|
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
|
offset = json_response["videos"].as_a[0]["index"].as_i
|
||||||
lookback = offset < 50 ? offset : 50
|
lookback = offset < 50 ? offset : 50
|
||||||
response = playlist.to_json(offset - lookback)
|
response = playlist.to_json(offset - lookback)
|
||||||
|
|
Loading…
Reference in a new issue