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

Is there a way to connect for downloads thru an authenticated youtube account? (Cookie) #50

Open
Jeager2 opened this issue Oct 18, 2021 · 3 comments

Comments

@Jeager2
Copy link

Jeager2 commented Oct 18, 2021

This may be of help... ??

// Found here: https://bytes.com/topic/c-sharp/answers/870187-login-youtube-using-c

private void login() {

      CookieContainer cookieContainer = new CookieContainer();
      HttpWebRequest PreRequest = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/ServiceLogin?utm_source=/places&utm_medium=van&utm_campaign=en&continue=http://www.google.com/local/add/businessCenter%3Fservice%3Dlbc%26gl%3DUS%26hl%3Den-US&service=lbc&hl=en-US&gl=US");
      PreRequest.CookieContainer = cookieContainer;
      PreRequest.AllowAutoRedirect = true;
      HttpWebResponse PreResponse = (HttpWebResponse)PreRequest.GetResponse();
      Stream PreResponseStream = PreResponse.GetResponseStream();
      PreResponse.Cookies = PreRequest.CookieContainer.GetCookies(PreRequest.RequestUri);
      Encoding PreEnc = System.Text.Encoding.UTF8;
      StreamReader PreResponseStreamReader = new StreamReader(PreResponse.GetResponseStream(), PreEnc, true);
      String PreMyHTML = PreResponseStreamReader.ReadToEnd();
 
      String Pattern = "name=\"GALX\"[\\s]*value=\"([a-zA-Z0-9-_\\.]*)\"";
      Match MyMatch = Regex.Match(PreMyHTML, Pattern);
      String GALX = MyMatch.Groups[1].ToString();
 
      HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/ServiceLoginAuth?service=lbc&ltmpl=sso&continue=http%3A%2F%2Fwww.google.com%2Flocal%2Fadd%2FbusinessCenter%3Fservice%3Dlbc%26gl%3DUS%26hl%3Den-US&service=lbc&uilel=3&ltmpl=sso&hl=en_US&ltmpl=sso&GALX=" + GALX + "&Email=USERNAME%40gmail.com&Passwd=PASSWORD&rmShown=1&signIn=Sign+in&asts=");
      Request.CookieContainer = cookieContainer;
      Request.Method = "POST";
      Request.Referer = "https://www.google.com/accounts/ServiceLogin?utm_source=/places&utm_medium=van&utm_campaign=en&continue=http://www.google.com/local/add/businessCenter%3Fservice%3Dlbc%26gl%3DUS%26hl%3Den-US&service=lbc&hl=en-US&gl=US";
      Request.MaximumAutomaticRedirections = 50;
      Request.AllowAutoRedirect = true;
      Request.KeepAlive = true;
      Request.ContentLength = 0;
 
      // Get the response
      HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
 
      Stream ResponseStream = Response.GetResponseStream();
      Response.Cookies = Request.CookieContainer.GetCookies(Request.RequestUri);
 
      // Read the response from the stream
      Encoding Enc = System.Text.Encoding.UTF8;
      StreamReader ResponseStreamReader = new StreamReader(Response.GetResponseStream(), Enc, true);
 
      String MyHTML = ResponseStreamReader.ReadToEnd();
      this.Cookies = cookieContainer;
      this.Response.Write(MyHTML);
 
      String Pattern2 = "location\\.replace\\(\"(http:\\/\\/www\\.google\\.com\\/local\\/add\\/businessCenter[a-zA-Z0-9\\\\\\?\\%_-]*)\"\\)";
      Match MyMatch2 = Regex.Match(MyHTML, Pattern2);
      String YTRedirect = MyMatch2.Groups[1].ToString();
      String Temp = YTRedirect.Replace("\\x3d", "=");
      String Temp2 = Temp.Replace("\\x26", "&");
      YTRedirect = Temp2;
 
      HttpWebRequest PosterRequest = (HttpWebRequest)WebRequest.Create(YTRedirect);
      PosterRequest.CookieContainer = cookieContainer;
      PosterRequest.Method = "GET";
      HttpWebResponse PosterResponse = (HttpWebResponse)PosterRequest.GetResponse();
      Stream PosterResponseStream = PosterResponse.GetResponseStream();
      PosterResponse.Cookies = PosterRequest.CookieContainer.GetCookies(PosterRequest.RequestUri);
      Encoding PosterEnc = System.Text.Encoding.UTF8;
      StreamReader PosterResponseStreamReader = new StreamReader(PosterResponse.GetResponseStream(), PosterEnc, true);
      String PosterMyHTML = PosterResponseStreamReader.ReadToEnd();
 
    }

But I don't know how or where to best integrate this and thought I'd ask before digging into the code.

@javidsho
Copy link
Contributor

What is the use of downloading with an account?

@Jeager2
Copy link
Author

Jeager2 commented Oct 25, 2021

For things like this:
https://stackoverflow.com/questions/54053185/why-does-download-captions-return-login-required

I also believe that the download quotas are higher if you are an authenticated user.

@javidsho
Copy link
Contributor

I'll work on this part. Authentication is sometimes vital as well. For example, Instagram requires authentication for some regions.
In the meantime, if you have to add authentication, you can always implement IGrabberServices and add cookies to the HttpClient.

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

No branches or pull requests

2 participants