Describe the bug
For videos with multiple audio tracks, fetchStreamingInfosThrowing(...) returns an HLS streamingURL that appears to resolve to a stream where AVFoundation does not expose the expected audio track metadata.
In practice:
• the official YouTube clients show English (US) original as the default track, with several dubbed alternatives
• but playback through the HLS URL returned by YouTubeKit starts in a dubbed language
• and AVPlayerItem only sees a single audible option with no useful metadata (displayName = "Unknown", locale = nil)
This makes it impossible to reliably select the original audio track when using the HLS playback URL returned by the library.
To Reproduce
import Foundation
import AVFoundation
import YouTubeKit
@main
struct Repro {
static func main() async throws {
let model = YouTubeModel()
model.selectedLocale = "en-US"
let searchResponse = try await SearchResponse.sendThrowingRequest(
youtubeModel: model,
data: [.query: "home"],
useCookies: false
)
if let visitorData = searchResponse.visitorData {
model.visitorData = visitorData
}
// Replace with any video that has original audio + dubbed tracks in official YouTube clients.
let video = YTVideo(videoId: "REPLACE_WITH_VIDEO_ID")
let streamingInfos = try await video.fetchStreamingInfosThrowing(
youtubeModel: model,
useCookies: nil
)
guard let streamingURL = streamingInfos.streamingURL else {
fatalError("Missing streamingURL")
}
print("streamingURL:", streamingURL)
let asset = AVURLAsset(url: streamingURL)
let item = AVPlayerItem(asset: asset)
guard let audibleGroup = try await item.asset.loadMediaSelectionGroup(for: .audible) else {
print("No audible group")
return
}
print("defaultOption:", audibleGroup.defaultOption?.displayName ?? "nil")
print("options count:", audibleGroup.options.count)
for option in audibleGroup.options {
print(
"option:",
option.displayName,
"locale:", option.locale?.identifier ?? "nil",
"dubbed:", option.hasMediaCharacteristic(.dubbedTranslation),
"voiceOver:", option.hasMediaCharacteristic(.voiceOverTranslation)
)
}
let player = AVPlayer(playerItem: item)
player.play()
try await Task.sleep(nanoseconds: 1_500_000_000)
let selected = item.currentMediaSelection.selectedMediaOption(in: audibleGroup)
print("selected after play:", selected?.displayName ?? "nil")
}
}
Observed behavior in our case:
• streamingURL is valid
• playback works
• but AVPlayerItem exposes only one audio option
• that option is effectively:
• displayName = "Unknown"
• locale = nil
• the playback starts in a dubbed language instead of the original English track
Representative logs:
[YTAudio] preselect selectable: Unknown [locale=nil, chars=none]
[YTAudio] preselect preferred: Unknown [locale=nil, chars=none]
[YTAudio] preselect selected: Unknown [locale=nil, chars=none]
[YTAudio] preselect default: Unknown [locale=nil, chars=none]
[YTAudio] preselect selected presentation language: nil
[YTAudio] preselect preferred custom schemes: []
[YTAudio] preselect selected presentation settings: [:]
[YTAudio] preselect effective presentation settings: [:]
[YTAudio] postselect selected: Unknown [locale=nil, chars=none]
Expected behavior
For videos that have an original audio track plus dubbed alternatives, I would expect the playback data returned by YouTubeKit to allow selecting the original audio track.
At minimum, one of these should be true:
• the returned HLS URL should expose proper alternative audio renditions to AVFoundation
• or the library should expose enough metadata / alternate stream information to let clients choose the original track explicitly
The default behavior should match official YouTube playback, where the original audio track is used by default and dubbed tracks are optional alternatives.
Additional context
This looks related specifically to the HLS streamingURL returned by fetchStreamingInfosThrowing(...).
From the app side, AVFoundation does not appear to receive normal audio track metadata for these videos, so this may mean:
• the selected playback URL already points to a dubbed-only/default-dub HLS variant
• or the chosen YouTube client/endpoint is returning an HLS manifest without proper alternate audio renditions
This is important because native playback otherwise works well through the HLS URL, but multilingual videos can start in the wrong language with no reliable way to switch back to the original track.
Describe the bug
For videos with multiple audio tracks, fetchStreamingInfosThrowing(...) returns an HLS streamingURL that appears to resolve to a stream where AVFoundation does not expose the expected audio track metadata.
In practice:
• the official YouTube clients show English (US) original as the default track, with several dubbed alternatives
• but playback through the HLS URL returned by YouTubeKit starts in a dubbed language
• and AVPlayerItem only sees a single audible option with no useful metadata (displayName = "Unknown", locale = nil)
This makes it impossible to reliably select the original audio track when using the HLS playback URL returned by the library.
To Reproduce
Observed behavior in our case:
• streamingURL is valid
• playback works
• but AVPlayerItem exposes only one audio option
• that option is effectively:
• displayName = "Unknown"
• locale = nil
• the playback starts in a dubbed language instead of the original English track
Representative logs:
Expected behavior
For videos that have an original audio track plus dubbed alternatives, I would expect the playback data returned by YouTubeKit to allow selecting the original audio track.
At minimum, one of these should be true:
• the returned HLS URL should expose proper alternative audio renditions to AVFoundation
• or the library should expose enough metadata / alternate stream information to let clients choose the original track explicitly
The default behavior should match official YouTube playback, where the original audio track is used by default and dubbed tracks are optional alternatives.
Additional context
This looks related specifically to the HLS streamingURL returned by fetchStreamingInfosThrowing(...).
From the app side, AVFoundation does not appear to receive normal audio track metadata for these videos, so this may mean:
• the selected playback URL already points to a dubbed-only/default-dub HLS variant
• or the chosen YouTube client/endpoint is returning an HLS manifest without proper alternate audio renditions
This is important because native playback otherwise works well through the HLS URL, but multilingual videos can start in the wrong language with no reliable way to switch back to the original track.