0xced / XCDYouTubeKit

YouTube video player for iOS, tvOS and macOS
MIT License
2.93k stars 626 forks source link

Cannot play video with XCDYouTubeVideoErrorDomain Code: -2 #557

Open cou929 opened 2 years ago

cou929 commented 2 years ago

I encountered a situation where the video cannot play with the following error.

Domain: XCDYouTubeVideoErrorDomain
Code:   -2
User Info: {
}

It seems that sometimes YouTube returns some pattern of HTML that makes the parser fails.

<script nonce="tZD2YtPt7fxsKqPJwe7GAw">var ytInitialPlayerResponse = {
...
// This "privateDoNotAccessOrElseSafeScriptWrappedValue" key contains the JavaScript source code which contains `};`
"privateDoNotAccessOrElseSafeScriptWrappedValue": "(function(){function u(x){return x}var X=this||self,C=function(x,O,W,R,J){if(R=(J=X.trustedTypes,W),!J||!J.createPolicy)return R;try{R=J.createPolicy(O,{createHTML:y,createScript:y,createScriptURL:y})}catch(z){if(X.console)X.console[x](z.message)}return R},y=function(x){return u.call(this,x)}; ...",
...
}}}};var meta = document.createElement('meta'); meta.name = 'referrer'; meta.content = 'origin-when-cross-origin'; document.getElementsByTagName('head')[0].appendChild(meta);</script>

Is there anybody who encountered the same issue? How do we fix this problem?