alexeichhorn / YouTubeKit

YouTube video and audio extractor for iOS, watchOS, visionOS, tvOS and macOS
MIT License
209 stars 47 forks source link

pattern (ytplayer\.config\s*=\s*) failed: The operation couldn’t be completed. (YouTubeKit.YouTubeKitError error 1.) #26

Closed naticio closed 1 year ago

naticio commented 1 year ago

Maybe I',m new but I cannot reproduce the video in my app.....has anybody experienced the same issue?

waliid commented 1 year ago

Hello @naticio, could you please provide us the video you are trying to play?

Thanks!

kubacizek commented 1 year ago

I'm experiencing the same problem. I'm attaching console log & html object from Extraction.swift:67

Video example: https://www.youtube.com/watch?v=aayzIpzTmn0

escaped-html.txt

applying descrambler
finding initial function name
Failed to decode object from given start point: The data couldn’t be read because it isn’t in the correct format.
pattern (ytplayer\.config\s*=\s*) failed: The operation couldn’t be completed. (YouTubeKit.YouTubeKitError error 1.)
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
signature found, skip decipher
waliid commented 1 year ago

Hello @kubacizek,

Unfortunately I'm not able to reproduce. I've tried with the testSampleVideo2 and it works with the id aayzIpzTmn0. Could you please provide us your code?

kubacizek commented 1 year ago

Hello @waliid,

Oh, I can see the problem now. I have this filter in my code

let video = YouTube(videoID: entity.id)
let streams = try await video.streams
let stream = streams.filter { stream in
    stream.includesAudioTrack && stream.includesVideoTrack
}.highestResolutionStream()

The problem is that there are no streams which includes both audio and video track. This wasn't the problem before. I tried more videos but the result is always the same. Is this even fixable from your side?

waliid commented 1 year ago

Hi @kubacizek,

Could you please try something like this:

let stream = streams.filter { stream in
    stream.includesVideoTrack && stream.subtype == "mp4"
}.highestResolutionStream()

video

or this:

let stream = streams.filter { stream in
    stream.includesAudioTrack
}.highestAudioBitrateStream()

audio

Thanks!

kubacizek commented 1 year ago

Hi @waliid,

Yes this works. But previously there was a stream that contained both video and audio. Anyway I think that I can merge this two streams into one in the code and achieve the result I need.

Thank you anyway!

naticio commented 1 year ago

it works!, thank you !!