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:
Fijxu 2024-05-13 21:07:46 -04:00
parent eda7444ca4
commit e0d0dbde3c
No known key found for this signature in database
GPG key ID: 32C1DDF333EDA6A4

View file

@ -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)