Youtubeexplode: Unable to process age-restricted video

Created on 17 Apr 2018  路  17Comments  路  Source: Tyrrrz/YoutubeExplode

I found a problem that should be solved (V4.0 updated Dec. 2017) but its still there:
The link to the video will cause an exception with message:
{"Video [yLnmR6PXzGY] is not available and cannot be processed.\r\nError code: 150\r\nError reason: Sign in to confirm your age"}
https://www.youtube.com/watch?v=yLnmR6PXzGY

Any solution for that ? - Or / How can I give the credentials of my "logged in yt-user" where I confirmed my age ? some example code would be nice... so I could solve myself ... I think. Thanx in advanced !

bug caused by youtube

Most helpful comment

Gonna wait 4 more days and close this if we're still unable to reproduce this.

All 17 comments

I had this to when trying to download a playlist. I added a try catch around everything so it wouldn't crash the program. It just skips those videos though.

I hope there is a way to sign in with a users details to solve this. and then the user could manage their account from outside of YouTube possibly.

Interesting, maybe they've changed something again.

You can theoretically log in using an HttpClient beforehand and then pass it as a constructor parameter to YoutubeClient so that it re-uses the stored cookies.

That would make for a nifty sample project :P

And a great pull request too 馃槢

Indeed it would be :D .. I only found out about this wonder YouTubeExplode a few weeks ago and only started using it recently. Don't know much about Http stuff in C# yet sadly :(

Busy messing around with my own WPF app now for video/music downloading... then after maybe I'll give it a try :P

I was going to give it a go but it seems alright with the latest version of the code. Perhaps, there is more to the problem?

The video in OP has been removed: https://www.youtube.com/watch?v=yLnmR6PXzGY

That video has been removed as well, but yes, I actually tried with multiple age restricted videos on DemoWpf and they all worked fine. Example link:
youtube.com/watch?v=6LZM3_wp2ps

image

Has anyone been able to reproduce this?

Nope:

#! "netcoreapp2.0"

#r "nuget: YoutubeExplode, *"

using YoutubeExplode;
using YoutubeExplode.Models.MediaStreams;
var yt = new YoutubeClient();

var streams = await yt.GetVideoMediaStreamInfosAsync("6LZM3_wp2ps");
var videoStream = streams.Video.WithHighestVideoQuality();
await yt.DownloadMediaStreamAsync(videoStream, "6LZM3_wp2ps." + videoStream.Container);

Worked perfectly fine for me.

Gonna wait 4 more days and close this if we're still unable to reproduce this.

I was able to reproduce this on:

YoutubeExplode.Exceptions.VideoUnavailableException: Video [hySoCSoH-g8] is not available and cannot be processed.
Error code: 150
Error reason: Sign in to confirm your age

I'm able to reproduce the issue when it is used in ASP.Net MVC application, hosted on the third-party server. But it is working fine when I debug on my local machine. Below are the exception details:

Error Message:
Video [OOQlCD5qMPY] is not available and cannot be processed. Error code: 150 Error reason: Sign in to confirm your age

StackTrace:

at YoutubeExplode.YoutubeClient.d__35.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at YoutubeExplode.YoutubeClient.d__38.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Web.Controllers.YoutubeController.

Sample Code:

````// Client
var client = new YoutubeClient();
// Get Video Info
Video details = await client.GetVideoAsync(id);
// Get media stream info set
MediaStreamInfoSet mediaStreamInfoSet = await client.GetVideoMediaStreamInfosAsync(id);
return View("Index", new YoutubeVideo(id, mediaStreamInfoSet, details));

@Tyrrrz I have analyzed the code in youtube-dl and found the way to access age-restricted videos. You just need to simulate the inner request. Use this code in YutubeClient.Video.cs:

The new method:

        private async Task<string> GetVideoInfoSimulatedAsync(string videoId, string sts = "")
        {
            var url = $"https://www.youtube.com/get_video_info?video_id={videoId}&eurl={Uri.EscapeDataString($"https://youtube.googleapis.com/v/{videoId}")}&sts={sts}&hl=en";
            return await _httpClient.GetStringAsync(url).ConfigureAwait(false);
        }

and some checks in GetVideoInfoAsync:

                // A not so good way to check for age restriction, still works for our purposes
                if (videoInfo.ContainsKey("errorcode") && videoInfo["reason"].Contains("age"))
                {
                    raw = await GetVideoInfoSimulatedAsync(videoId, sts).ConfigureAwait(false);
                    videoInfo = UrlEx.SplitQuery(raw);
                }

@InkyQuill what does simulate inner request mean?

It seems that youtube can read info for restricted videos, but needs to pass a certain url as eurl parameter with the https://youtube.googleapis.com/v/<videoid> data. Nothing more. I just use the same words that youtube-dl author used for this.

Here's the link to the code in youtube-dl repo: https://github.com/rg3/youtube-dl/blob/98998cded6e179b35055177f75fc921d99ee5938/youtube_dl/extractor/youtube.py#L828-L845

@InkyQuill can confirm this helped, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vsjtechnologies picture vsjtechnologies  路  7Comments

SlowLogicBoy picture SlowLogicBoy  路  7Comments

Tyrrrz picture Tyrrrz  路  3Comments

NoobInTraining picture NoobInTraining  路  5Comments

ShaiPreter picture ShaiPreter  路  3Comments