Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some streams can return 404 #759

Closed
5 tasks done
Tyrrrz opened this issue Jan 2, 2024 · 4 comments · Fixed by #760
Closed
5 tasks done

Some streams can return 404 #759

Tyrrrz opened this issue Jan 2, 2024 · 4 comments · Fixed by #760

Comments

@Tyrrrz
Copy link
Owner

Tyrrrz commented Jan 2, 2024

Version

master

Platform

.NET 8

Steps to reproduce

var streamManifest = await _youtube.Videos.Streams.GetManifestAsync("JQgKhZZyBYg");
var streamInfo = streamManifest.GetMuxedStreams().MaxBy(s => s.VideoQuality);

// This fails
await _youtube.Videos.Streams.DownloadAsync(streamInfo, "video.mp4");

Details

Looks like one of the muxed streams (720p mp4) returns 404 when accessed.

Originally reported at Tyrrrz/YoutubeDownloader#406

Checklist

  • I have looked through existing issues to make sure that this bug has not been reported before
  • I have provided a descriptive title for this issue
  • I have made sure that this bug is reproducible on the latest version of the package
  • I have provided all the information needed to reproduce this bug as efficiently as possible
  • I have sponsored this project
@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Jan 2, 2024

A bit more detail into what's happening. The stream does not immediately return 404, which is why it's not filtered out by this check in the StreamClient:

// Stream cannot be accessed
if (contentLength <= 0)
continue;

Instead, what actually happens is that the stream initially serves data, up to a certain point:

image
image

Then, at some point, the underlying ContentLengthReadStream class throws an exception, indicating that the stream has mismatched content length:

image

After that, MediaStream attempts to re-initialize the last segment, on the off chance that this is a transient error. This time, the stream returns 404 instead, most likely because the new values of the range parameter are out of bounds.

Worth noting that even Chrome fails to read this stream, due to content length mismatch:

image

The bottom line is that this stream is broken, but it's currently not filtered out because the issue appears later on in the stream's lifecycle.

@QINGCHARLES
Copy link

Wow, what a weird error. I can only guess YouTube's encoder failed for some reason and pushed out a broken file that none of their systems are set up to check for.

There is not much for you to do in your code. The best you could do is indicate to the user somehow that they should try the stream again but select a different stream type to download and it might work.

Tyrrrz added a commit that referenced this issue Jan 2, 2024
@Tyrrrz Tyrrrz changed the title Some muxed streams can return 404 Some streams can return 404 Jan 2, 2024
@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Jan 2, 2024

Looks like I found a way to filter them out. I'll release a new update on Thursday.

@QINGCHARLES
Copy link

You're a star, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants