Skip to content

Commit

Permalink
Automatically filter out potential invalid stream sources
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeichhorn committed Dec 13, 2023
1 parent 40c7c63 commit 5826a18
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/YouTubeKit/Extraction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ class Extraction {
class func applySignature(streamManifest: inout [InnerTube.StreamingData.Format], videoInfo: InnerTube.VideoInfo, js: String) throws {
var cipher = ThrowingLazy(try Cipher(js: js))

var invalidStreamIndices = [Int]()

for (i, stream) in streamManifest.enumerated() {
if let url = stream.url {
if url.contains("signature") || (stream.s == nil && (url.contains("&sig=") || url.contains("&lsig="))) {
Expand All @@ -288,6 +290,10 @@ class Extraction {
}

if let cipheredSignature = stream.s {
// Remove the stream from `streamManifest` for now, as signature extraction currently doesn't work most of time
invalidStreamIndices.append(i)
continue // Skip the rest of the code as we are removing this stream

let signature = try cipher.value.getSignature(cipheredSignature: cipheredSignature)

os_log("finished descrambling signature for itag=%{public}i", log: log, type: .debug, stream.itag)
Expand All @@ -311,6 +317,11 @@ class Extraction {
}
}
}

// Remove invalid streams
for index in invalidStreamIndices.reversed() {
streamManifest.remove(at: index)
}
}

/// Breaks up the data in the ``type`` key of the manifest, which contains the
Expand Down

0 comments on commit 5826a18

Please sign in to comment.