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

Get age restricted YouTube videos by querying using a user credentials #195

Open
taqabubaker opened this issue Mar 1, 2021 · 6 comments
Assignees
Labels

Comments

@taqabubaker
Copy link

Whenever you try to get a video has an age restriction you get the below exception where YouTube asks you to login to confirm your age. It would be great if we can get the video using a user credentials.

VideoLibrary.Exceptions.UnavailableStreamException
  HResult=0x80131500
  Message=Error caused by Youtube.(Sign in to confirm your age.))
  Source=libvideo
  StackTrace:
   at VideoLibrary.YouTube.<ParseVideos>d__7.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at VideoLibrary.ServiceBase`1.VideoSelector(IEnumerable`1 videos)
   at VideoLibrary.ServiceBase`1.<GetVideoAsync>d__6.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at VideoLibrary.ServiceBase`1.<GetVideoAsync>d__5.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ConsoleApp1.Program.<GetYouTubeVideo>d__3.MoveNext() in D:\Tariq's Blog\TranslateYourVideos\Code\ConsoleApp1\ConsoleApp1\Program.cs:line 65
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at ConsoleApp1.Program.<RunTask>d__1.MoveNext() in D:\Tariq's Blog\TranslateYourVideos\Code\ConsoleApp1\ConsoleApp1\Program.cs:line 31
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at ConsoleApp1.Program.<Main>d__0.MoveNext() in D:\Tariq's Blog\TranslateYourVideos\Code\ConsoleApp1\ConsoleApp1\Program.cs:line 17

  This exception was originally thrown at this call stack:
    [External Code]
    ConsoleApp1.Program.GetYouTubeVideo(string, string) in Program.cs
    [External Code]
    ConsoleApp1.Program.RunTask(string) in Program.cs
    [External Code]
    ConsoleApp1.Program.Main(string[]) in Program.cs
@omansak omansak self-assigned this Mar 8, 2021
@omansak omansak added the todo label Mar 8, 2021
@sepp89117
Copy link
Contributor

Hi, maybe can this code be integrated relatively easily?
@omansak @zerodytrash
zerodytrash/Simple-YouTube-Age-Restriction-Bypass

@sepp89117
Copy link
Contributor

Got it!

  1. Set target framework to .NET Standard 2.0
  2. Add
var status = playerResponseJson.SelectToken("playabilityStatus.status")?.Value<string>(); 
if (status == "AGE_VERIFICATION_REQUIRED" || status == "AGE_CHECK_REQUIRED" || status == "LOGIN_REQUIRED")
{
    var videoId = playerResponseJson.SelectToken("videoDetails.videoId")?.Value<string>();
    string postData = "{context:{client:{clientName:\"WEB\",clientVersion:\"2.20210827.01.00\",clientScreen:\"EMBED\"},thirdParty:{embedUrl:\"https://www.youtube.com/\"}},playbackContext:{contentPlaybackContext:{signatureTimestamp:18865}},videoId:\""+ videoId + "\"}";
    var data = Encoding.ASCII.GetBytes(postData);
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8");
    request.Method = "POST";
    request.ContentLength = data.Length;

    using (var stream = request.GetRequestStream())
    {
        stream.Write(data, 0, data.Length);
    }

    var response = (HttpWebResponse)request.GetResponse();
    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

    Console.WriteLine(responseString);

    playerResponseJson = JToken.Parse(Json.Extract(responseString));
}

under line 72 in YouTube.cs.

It works for me

@marnagy
Copy link

marnagy commented Apr 3, 2022

@sepp89117 , did you create a pull request?

@marnagy
Copy link

marnagy commented Apr 4, 2022

@89z , would you mind sharing the method?

@zerodytrash
Copy link

@marnagy see yt-dlp/yt-dlp#3233

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

No branches or pull requests

6 participants
@omansak @taqabubaker @sepp89117 @marnagy @zerodytrash and others