SharpGrabber icon indicating copy to clipboard operation
SharpGrabber copied to clipboard

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

Open Jeager2 opened this issue 4 years ago • 3 comments

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.

Jeager2 avatar Oct 18 '21 03:10 Jeager2

What is the use of downloading with an account?

javidsho avatar Oct 18 '21 09:10 javidsho

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.

Jeager2 avatar Oct 25 '21 11:10 Jeager2

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.

javidsho avatar Nov 10 '21 11:11 javidsho