fix: safely access "label" key

Fixes https://github.com/iv-org/invidious/issues/5095

On some videos, `label` is missing from the video information. Invidious
assumed that the `label` key existed.

Videos with label have this inside `metadataBadgeRenderer`:

```
{"style" => "BADGE_STYLE_TYPE_SIMPLE",
 "label" => "4K",
 "trackingParams" => "COMDENwwGAoiEwiCrebe6JWNAxWIxz8EHSQRFTU="}
```

but other videos, for some reason, look like this:

```
{"icon" => {"iconType" => "PERSON_RADAR"},
 "style" => "BADGE_STYLE_TYPE_SIMPLE",
 "trackingParams" => "CM4DENwwGAsiEwiCrebe6JWNAxWIxz8EHSQRFTU="}
```
This commit is contained in:
Fijxu 2025-05-09 02:58:29 -04:00
parent d1bc15b8bf
commit b120abdcc5
No known key found for this signature in database
GPG Key ID: 32C1DDF333EDA6A4

View File

@ -115,7 +115,7 @@ private module Parsers
badges = VideoBadges::None badges = VideoBadges::None
item_contents["badges"]?.try &.as_a.each do |badge| item_contents["badges"]?.try &.as_a.each do |badge|
b = badge["metadataBadgeRenderer"] b = badge["metadataBadgeRenderer"]
case b["label"].as_s case b["label"]?.try &.as_s
when "LIVE" when "LIVE"
badges |= VideoBadges::LiveNow badges |= VideoBadges::LiveNow
when "New" when "New"