libvideo
libvideo copied to clipboard
Get age restricted YouTube videos by querying using a user credentials
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
Hi, maybe can this code be integrated relatively easily? @omansak @zerodytrash zerodytrash/Simple-YouTube-Age-Restriction-Bypass
Got it!
- Set target framework to .NET Standard 2.0
- 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
@sepp89117 , did you create a pull request?
above method doesnt work anymore. I have a a method that works
@89z , would you mind sharing the method?
@marnagy see https://github.com/yt-dlp/yt-dlp/pull/3233