0xced / XCDYouTubeKit

YouTube video player for iOS, tvOS and macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can Not Play video any more - XCDYouTubeVideoErrorDomain Code=-3

JmyW opened this issue · comments

commented

Start from today(or maybe yesterday). Most of videos are failed to play. The error is returned "XCDYouTubeVideoErrorDomain Code=-3".

https://www.youtube.com/watch?v=AgFeZr5ptV8
https://www.youtube.com/watch?v=bnVUHWCynig
https://www.youtube.com/watch?v=clJsnBoVQDA

Could anyone help? thanks in advance.

I'm having the same issue since this morning.
The failures seem to be random, the same video is sometimes available to be played and sometimes fails.
I have not found the root cause of this all yet, but it seems like the issue lies with YouTube's get_video_info URL sometimes returning a 404 error.
The following is the print of the NSHTTPURLResponse I get when trying to access the get_video_info in the -(void) handleVideoInfoResponseWithInfo:(NSDictionary *)info response:(NSURLResponse *)response handler inside XCDYouTubeVideoOperation.m

<NSHTTPURLResponse: 0x2834e8180> { URL: https://www.youtube.com/get_video_info?el=embedded&hl=ja&ps=default&video_id=dy90tA3TT1c } { Status Code: 404, Headers { "Alt-Svc" = ( "h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"" ); "Cache-Control" = ( "no-cache" ); "Content-Length" = ( 0 ); "Content-Type" = ( "text/html; charset=utf-8" ); Date = ( "Tue, 18 May 2021 06:10:38 GMT" ); Expires = ( "Tue, 27 Apr 1971 19:44:06 GMT" ); Server = ( "YouTube Frontend Proxy" ); "Set-Cookie" = ( "VISITOR_INFO1_LIVE=YqCzchuOn6U; path=/; domain=.youtube.com; secure; expires=Sun, 14-Nov-2021 06:10:38 GMT; httponly", "YSC=hmbP_-FCTAY; path=/; domain=.youtube.com; secure; httponly" ); "Strict-Transport-Security" = ( "max-age=31536000" ); p3p = ( "CP=\"This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en for more info.\"" ); "x-content-type-options" = ( nosniff ); "x-frame-options" = ( SAMEORIGIN ); "x-xss-protection" = ( 0 ); } }

If anyone has any idea how to solve this I would love to hear about it!
I'll update as well if I figure this out...

Same here! Sometimes it fails other times it works fine.

Sometime, i got two error:-
Domain: XCDYouTubeVideoErrorDomain
Code: -2
User Info: {
NSLocalizedDescription = "Invalid parameters.";
NSURL = "https://www.youtube.com/get_video_info?el=detailpage&hl=en&ps=default&video_id=";
}

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

Please suggest me right path, my application is live on appstore and many user will get same error.

I still have no idea what is actually causing this.
However, since the 404 errors seem to be random I realised that just retrying when they happen seem to make most videos able to play. I'm not sure if this is the best way of handling this though, but at least in my case it has reduced the number of errors from happening almost 80% of the time to a very small percentage.

By adding the following code to XCDYouTubeVideoOperation.m, just below the error handling for HTTP 429 errors (around row 373 or so), it is possible to retry when this error happens.

if ([(NSHTTPURLResponse *)response statusCode] == 429)
{
    // error handling for 429 errors
}

/** ↓ Insert from here **/
if ([(NSHTTPURLResponse *)response statusCode] == 404 && responseString.length == 0)
{
    [self handleConnectionError:[NSError errorWithDomain:XCDYouTubeVideoErrorDomain code:XCDYouTubeErrorEmptyResponse userInfo:@{NSLocalizedDescriptionKey : @"The response is empty."}] requestType:requestType];
    return;
}
/** ↑ Insert end **/

if (responseString.length == 0)
{

If anyone have any better solutions, please share them!

commented

I tried the approach above, but in my testing this didn't seem to have much effect at all. I even increased the amount of retries, but once there's a 404 it seems to be unavailable for a little while:

screenshot

commented

Unfortunately I have nothing new to add (re fixes) except to confirm as of today I'm noticing this same issue. Looking forward to learning more, i.e. what can be done to quickly fix.

Unfortunately I have nothing new to add (re fixes) except to confirm as of today I'm noticing this same issue. Looking forward to learning more, i.e. what can be done to quickly fix.

Same here, I started experiencing the bug today...

Same here, videos are not reproducing

Same here... none of the videos are playing..

Hmm, I did add a few other changes as well, like incorporating #524, apart from retrying on 404 errors.
I am now able to play all videos. It's strange that the same doesn't seem to work for you guys..
My way of retrying doesn't seem to be the best way of handling this error anyway, so I am still interested in any solutions you can find.

commented

Hmm, I did add a few other changes as well, like incorporating #524, apart from retrying on 404 errors.
I am now able to play all videos. It's strange that the same doesn't seem to work for you guys..
My way of retrying doesn't seem to be the best way of handling this error anyway, so I am still interested in any solutions
you can find.

Adding your 404 retry code (w/ no other changes) does seem to be solving the issue for me*, i.e. in (as specified in your previous response) I added your code to XCDYouTubeVideoOperation.m:

if ([(NSHTTPURLResponse *)response statusCode] == 404 && responseString.length == 0) {
..

Thank you, very much appreciated.
However, wondering if this is just a temporary issue @ YouTube (seemingly w/ get_video_info) or if this signals a major change in how moving forward we can access YT video data in-app.

*PS I checked how many Xs the retry code is triggered and it's consistently 2Xs before the method (handleConnectionSuccessWithData:) continues successfully w/o retrying. Reason why this works (consistently after retrying 2Xs) is beyond my understanding, just happy it does (work, for now).

Same issue encounter today. any update on this?

Domain: XCDYouTubeVideoErrorDomain Code: -3 User Info: { } The operation couldn’t be completed. (XCDYouTubeVideoErrorDomain error -3.)

commented

@fightveryexplosion Thanks a lot for the great work and sharing. In my case, it's solved. Appreciate!
@mjroldan Have you tried the solution fightvertexplosion shared? It indeed works.

@fightveryexplosion Thanks a lot for the great work and sharing. In my case, it's solved. Appreciate!
@mjroldan Have you tried the solution fightvertexplosion shared? It indeed works.

Not yet so far but do we have any solution without having resubmit the app to app store?

How can fix this error please help anyone

looks like the get_video_info API is either temporarily not available or disabled completely from youtube. Opening this page -https://www.youtube.com/get_video_info?video_id=B4CRkpBGQzU
in browser gives a 404.

If this API starts working (Youtube controls it), this repo might start working again.

commented

Same here! all my videos
[XCDYouTubeKit] Video operation finished with error: The operation couldn’t be completed. (XCDYouTubeVideoErrorDomain error -3.)
Domain: XCDYouTubeVideoErrorDomain
Code: -3
User Info: {
}

commented

@fightveryexplosion Interesting, I also used that PR as a base, but for me the 429 error handling is at line 218 not 373.

Do you see the first call (get_video_info?el=embedded) fail and the second (get_video_info?el=detailpage) work when you test? Just wondering aloud how the tweak seems to work for some and not for others.

Hopefully that API is simply bugged and fixed by Google. The official library doesn't help our tvOS app...

commented

looks like the get_video_info API is either temporarily not available or disabled completely from youtube. Opening this page -https://www.youtube.com/get_video_info?video_id=B4CRkpBGQzU
in browser gives a 404.

Same issue, I was also getting 404 error(s) even when testing get_video_info from a browser,
however in app @fightveryexplosion retry fix works for me and always after the second try — don’t know why this succeeds after retrying twice because I assume the underlying call is also to get_video_info (which as we experienced is now always returning 404 errors from the browser).

@fightveryexplosion Great, it's working, thanks!
But i got another issue like i could not get captionURLs and autoGeneratedCaptionURLs, i need to show caption in video. Before it was working ,but after applying this solution i could not get above parameter. Anyone know about this issue please help me, thanks.

commented

I did some more testing and noticed that the retry tweak works when I'm on a VPN to the US (from EU). Curiously, I still see the 404 errors when inspecting my network calls, but a few seconds later video stream data arrives regardless. When the VPN is disabled, this never happens.

Might be useful for the others who reported the tweak not working to test this if they have a lot of users outside the EU.

@0xced
I have Generated PR For #526
Please review it and let me know

commented

Just wanted to confirm that the fix above also works in the EU, awesome!

commented

Thanks @jatin19121990, this works for me too.
(Commented out the retry code posted earlier and replaced with this fix.)

Wow, thank you! This works for me as well, without the need for retrying! @jatin19121990 you're the best!
And to think all it took to fix this was one additional parameter to the get_video_info request, lmao.

commented

Wow, thank you! This works for me as well, without the need for retrying! @jatin19121990 you're the best!
And to think all it took to fix this was one additional parameter to the get_video_info request, lmao.

@fightveryexplosion, your retry worked too, a clever temporary fix that had our app up and running last night before today's parameter addition. Thanks again.

commented

@jatin19121990 @fightveryexplosion Thank you both so much for solving this issue. And thanks for all people joining discussion and sharing status. Since it's confirmed fixed by both ways from multiple participants, I'm closing this issue.

Does this merge need a SPM release to show?

@0xced could we get a new release with this fix please?

commented

I'm again encountering the same error we had (and previously resolved) last month, i.e.

https://www.youtube.com/get_video_info is failing w/ 404 error again
^^ specifically in my application calls to e.g. '[XCDYouTubeClient getVideoWithIdentifier:' fail.

For the past month the addition of parameter html5=1, i.e. as per @jatin19121990 was working, but as of the past ~12 hours it stopped working again, see:
8389cd3

I re-applied the following, i.e. specifically @fightveryexplosion retry fix, see:
#525 (comment)

^^ The retry fix seems to work for almost videos I've so far tried, I'm assuming Youtube has again added (or removed) a parameter requirement for their 'get_video_info' endpoint, but until another fix comes along applying the @fightveryexplosion fix as per 525#issuecomment-843923468 resolves the issue, i.e. quoting @fightveryexplosion (thank you again, @fightveryexplosion):

XCDYouTubeVideoOperation.m

around row 373 or so), it is possible to retry when this error happens.

if ([(NSHTTPURLResponse *)response statusCode] == 429)
{
// error handling for 429 errors
}

/** ↓ Insert from here */
if ([(NSHTTPURLResponse )response statusCode] == 404 && responseString.length == 0)
{
[self handleConnectionError:[NSError errorWithDomain:XCDYouTubeVideoErrorDomain code:XCDYouTubeErrorEmptyResponse userInfo:@{NSLocalizedDescriptionKey : @"The response is empty."}] requestType:requestType];
return;
}
/
↑ Insert end **/

if (responseString.length == 0)
{

Same here :(

Same

I'm experiencing the same issue. This PR 8389cd3 has been working as of a couple of days ago but now I'm experiencing this again. Video plays sometimes, but sometimes not and when not this is the error message I keep seeing:

[XCDYouTubeKit] Video operation finished with error: The operation couldn’t be completed. (XCDYouTubeVideoErrorDomain error -3.)
Domain: XCDYouTubeVideoErrorDomain
Code:   -3

I'm experiencing the same issue. It worked but now I see the error again: "Error Domain=XCDYouTubeVideoErrorDomain Code=-3". Please help

same issue. it worked before and I am not getting error but doesn't play the video today.
Common videos work fine but only "LIVE NOW" videos don't work

Same here, it's not working once again.

This post https://stackoverflow.com/a/68054873/3937348 covered this issue, too.

The currently working url for get_video_info seems to be https://www.youtube.com/get_video_info?video_id={{videoId}}&eurl=https%3A%2F%2Fyoutube.googleapis.com%2Fv%2F{{videoId}}&html5=1&c=TVHTML5&cver=6.20180913

a small fix (XCDYouTubeVideoOperation.m), version 2.15.2

- (void) startNextRequest
{
	if (self.eventLabels.count == 0)
	{
		if (self.requestType == XCDYouTubeRequestTypeWatchPage || self.webpage)
		{
			if (self.ranLastEmbedPage == NO) {
				[self startLastEmbedPageRequest];
				return;
			}
			[self finishWithError];
		}
		else
		{
			[self startWatchPageRequest];
		}
	}
	else
	{
		NSString *eventLabel = [self.eventLabels objectAtIndex:0];
		[self.eventLabels removeObjectAtIndex:0];
		
        NSDictionary *query = @{ @"video_id": self.videoIdentifier, @"eurl": @"https%3A%2F%2Fyoutube.googleapis.com%2Fv%2Fonz2k4zoLjQ", @"html5": @"1", @"c": @"TVHTML5", @"cver": @"6.20180913" }; // only this is new
		NSString *queryString = XCDQueryStringWithDictionary(query);
		NSURL *videoInfoURL = [NSURL URLWithString:[@"https://www.youtube.com/get_video_info?" stringByAppendingString:queryString]];
		[self startRequestWithURL:videoInfoURL type:XCDYouTubeRequestTypeGetVideoInfo];
	}
}