Potential fix for pull request finding

Hardening via `.try &.as_h?` makes sense - not sure if YT would ever return null

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Maarten den Braber 2026-07-31 11:12:35 +02:00 committed by GitHub
parent 09fe7557d6
commit 9752768d58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -154,18 +154,21 @@ module Invidious::JSONify::APIv1
# one audio track. The same data already drives the DASH manifest # one audio track. The same data already drives the DASH manifest
# (see `Invidious::Routes::API::Manifest`), but was never exposed on # (see `Invidious::Routes::API::Manifest`), but was never exposed on
# the API, leaving clients to scrape `xtags` out of the stream URL. # the API, leaving clients to scrape `xtags` out of the stream URL.
if audio_track = fmt["audioTrack"]? if audio_track = fmt["audioTrack"]?.try &.as_h?
json.field "audioTrack" do json.field "audioTrack" do
json.object do json.object do
# Language tag with a track discriminator, e.g. "en-US.4". if id = audio_track["id"]?
json.field "id", audio_track["id"] if audio_track["id"]? json.field "id", id
# Human-readable label, e.g. "English (original)". end
json.field "displayName", audio_track["displayName"] if audio_track["displayName"]? if display_name = audio_track["displayName"]?
# True for the video's original (undubbed) audio. json.field "displayName", display_name
json.field "audioIsDefault", audio_track["audioIsDefault"] if audio_track["audioIsDefault"]? end
if audio_is_default = audio_track["audioIsDefault"]?
json.field "audioIsDefault", audio_is_default
end end
end end
end end
end
# Extra misc stuff # Extra misc stuff
json.field "colorInfo", fmt["colorInfo"] if fmt.has_key?("colorInfo") json.field "colorInfo", fmt["colorInfo"] if fmt.has_key?("colorInfo")