Tyrrrz / YoutubeExplode

Abstraction layer over YouTube's internal API
MIT License
2.97k stars 497 forks source link

Error: YoutubeExplode.Exceptions.VideoUnavailableException #808

Closed Dopamax closed 2 months ago

Dopamax commented 2 months ago

Version

v6.4.0

Platform

.NET 8 / windows 10

Steps to reproduce

My blazor app work fine in local machine, but when I deployed it on azure app service, I got this error below

Details

[2024-09-01T15:34:42.052Z] Error: YoutubeExplode.Exceptions.VideoUnavailableException: Video 'CZr3pKM44wk' is not available. at YoutubeExplode.Videos.VideoController.GetVideoWatchPageAsync(VideoId videoId, CancellationToken cancellationToken) in //YoutubeExplode/Videos/VideoController.cs:line 39 at YoutubeExplode.Videos.VideoClient.GetAsync(VideoId videoId, CancellationToken cancellationToken) in //YoutubeExplode/Videos/VideoClient.cs:line 37 at YoutaBlazorWebApp.Application.YoutubeDownloader.GetYoutaQuality720pFileStream(String videoUrl) in C:\Users\clock\source\repos\YoutaBlazorWebApp\Application\YoutubeDownloader.cs:line 165 at YoutaBlazorWebApp.Components.Pages.Home.DownloadVideoFileQuality720p() in C:\Users\clock\source\repos\YoutaBlazorWebApp\Components\Pages\Home.razor:line 77 at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Checklist

Dopamax commented 2 months ago

@Tyrrrz what's the cause of the problem, and what's the solution ?

lukaszfiszer96 commented 2 months ago

same here. Locally works fine, but on azure server got VideoUnavailableException. Any ideas ?

okansarica commented 2 months ago

In my case this is happening when the page content doesn't contain of:URL meta tag. This happens most probably because the page is not accessible when banned from youtube but still there is json data in the content which might be used

socaciumugurel commented 2 months ago

My assumption, this is a duplicate of: https://github.com/Tyrrrz/YoutubeExplode/issues/794

I managed to reproduce this locally, and digging dipper in the library, GetVideoWatchPageAsync from VideoController throws an exception with the message: Sign in to confirm you’re not a bot (Would be useful if this message is thrown to the client) This message indicates that YouTube is flagging the request as potentially coming from an automated source, which could be tied to the IP address used by the machine. This could explain why it's working on some machines and not on others—YouTube may impose stricter checks based on the IP reputation or the traffic pattern.

Key Takeaways:

Potential Solutions:

okansarica commented 2 months ago

As I checked the source the library checks for meta tags to decide if the video is available or not but there is still json data in the response. Maybe using that json data instead of parsing HTML might be a better solution

Tyrrrz commented 2 months ago

As @socaciumugurel said, this is a duplicate of #794.

This check seems to work based on IP ranges and it does not depend on how many requests you've made or how often you've made them. If your code is executing on a public platform (e.g. a hosted cloud provider like Azure, AWS, GCP, etc.) then it's probably going to be instantly flagged as suspicious. The same thing is happening with this project's CI workflow runs: https://github.com/Tyrrrz/YoutubeExplode/actions/runs/10926592976.

Immediate solutions are:

None of these are easy, but that's kind of the point.