Error: YoutubeExplode.Exceptions.VideoUnavailableException
Dopamax opened this issue · 6 comments
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
- 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
- I have not read any of the above and just checked all the boxes to submit the issue
same here. Locally works fine, but on azure server got VideoUnavailableException. Any ideas ?
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
My assumption, this is a duplicate of: #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:
- Bot Detection: YouTube is recognizing the request as coming from a bot, likely due to certain heuristics like the request frequency, user agent, or IP address.
- IP Sensitivity: Some machines (or networks) may be flagged more easily due to IP reputation or rate-limiting.
- Geographical/Network Factors: Machines in different locations or behind different IPs may trigger bot detection differently.
Potential Solutions:
- Throttle Requests: Slow down the number of requests to avoid hitting YouTube's bot detection limits.
- Use Proxies/VPN: Rotate IP addresses or use proxies to reduce the likelihood of being flagged.
- Simulate Human-Like Behavior: Modify the request headers (e.g., user-agent, referrer) to better mimic a browser.
- Handling Sign-In: Unfortunately, YoutubeExplode does not support authenticated sessions, so bypassing CAPTCHA or signing in programmatically is not straightforward.
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
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:
- Create an authenticated session by supplying the corresponding cookies
- Use a proxy server to mask the origin of your requests
- Host your application elsewhere
None of these are easy, but that's kind of the point.