Skip to content

0.4.11

Latest

Choose a tag to compare

@alexeichhorn alexeichhorn released this 30 Nov 16:02
7e06ef7

Update for latest changes by YouTube for video extraction.

  • Fixed local signature solving for YouTube's latest player changes thanks to @urshofer
  • Added availableAt and waitUntilAvailable() to Stream for videos with preroll ads

Waiting for preroll ads

For videos with preroll ads, YouTube only serves the stream URL after a short waiting period, usually a few seconds. Requesting the URL earlier can fail with 403 for the lifetime of that URL.

Call waitUntilAvailable() before playing or downloading a stream:

let stream = try await YouTube(videoID: "QdBZY2fkU-0").streams
    .filterVideoAndAudio()
    .filter { $0.isNativelyPlayable }
    .highestResolutionStream()

if let stream {
    try await stream.waitUntilAvailable()
    let player = AVPlayer(url: stream.url)
}

waitUntilAvailable() returns immediately if the stream is already available. If you want to handle the wait yourself, for example to show a loading state, check stream.availableAt directly.