DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo; DateTime date1 = DateTime.Now; Calendar cal = dfi.Calendar; var week = cal.GetWeekOfYear(date1, dfi.CalendarWeekRule, dfi.FirstDayOfWeek); var day = (int)cal.GetDayOfWeek(date1) == 0 ? 6 : (int)cal.GetDayOfWeek(date1) - 1; // , GetDayOfWeek 0 , . GetWeekOfYear , var epnumber = week + 79 - ((day < 5) ? 1 : 0);
byte[] buffer = Encoding.ASCII.GetBytes("login_username=_&login_password=_&login=%C2%F5%EE%E4"); HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://login.rutracker.org/forum/login.php");// Post- var cc = new CookieContainer(); WebReq.CookieContainer = cc;// WebReq.Method = "POST"; WebReq.ContentType = "application/x-www-form-urlencoded"; WebReq.ContentLength = buffer.Length; HttpWebResponse WebResp; try { Stream PostData = WebReq.GetRequestStream(); PostData.Write(buffer, 0, buffer.Length); PostData.Close(); WebResp = (HttpWebResponse)WebReq.GetResponse(); } catch (Exception e) { MessageBox.Show(" ", " ", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
var url = @"http://rutracker.org/forum/tracker.php?nm=%D0%92%D0%B5%D0%BB%D0%B8%D0%BA%D0%BE%D0%BB%D0%B5%D0%BF%D0%BD%D1%8B%D0%B9%20%D0%B2%D0%B5%D0%BA%20sub%20"+epnumber; WebReq = (HttpWebRequest)WebRequest.Create(url); WebReq.CookieContainer = cc; WebReq.Method = "GET"; WebReq.ContentType = "application/x-www-form-urlencoded"; WebResp = (HttpWebResponse)WebReq.GetResponse(); string result; Encoding responseEncoding = Encoding.GetEncoding(WebResp.CharacterSet); try { using (StreamReader sr = new StreamReader(WebResp.GetResponseStream(), responseEncoding)) { result = sr.ReadToEnd(); } } catch (Exception e) { MessageBox.Show(" ", " ", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
string pattern = @"http://dl.rutracker.org/forum/dl.php\?t=\d+"; Regex regex = new Regex(pattern); Match match = regex.Match(result); if (match.Length == 0) { MessageBox.Show(" !", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else AutoClosingMessageBox.Show(" ! .", "Caption", 3000);
try { WebReq = (HttpWebRequest)WebRequest.Create(match.ToString()); WebReq.CookieContainer = cc; WebReq.AllowAutoRedirect = false; WebReq.Method = "POST"; WebReq.Referer = url; WebReq.ContentType = "application/x-www-form-urlencoded"; /* */ Stream ReceiveStream = WebReq.GetResponse().GetResponseStream(); string filename = @"C:\123.torrent"; byte[] buffer1 = new byte[1024]; FileStream outFile = new FileStream(filename, FileMode.Create); int bytesRead; while ((bytesRead = ReceiveStream.Read(buffer1, 0, buffer.Length)) != 0) outFile.Write(buffer1, 0, bytesRead); outFile.Close(); ReceiveStream.Close(); } catch (Exception e) { MessageBox.Show(" -!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
string letter = ""; foreach (DriveInfo i in System.IO.DriveInfo.GetDrives()) { try { if (i.DriveType.ToString() == "Removable" && i.ToString() != "A:\\") { if (i.TotalFreeSpace < 3000000000) { MessageBox.Show(" , 3!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } letter = String.Copy(i.ToString()); break; } //Console.WriteLine(i.DriveType); } catch (Exception E) { return; } } if (letter == "") { MessageBox.Show(" !", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
string par = @"--seed-time=0 -d " + letter + " --select-file="+(epnumber-3)+ @" ""C:\123.torrent"" "; //--seed-time=0 - , . , . //-d - //--select-file - , . , 3. Process P = Process.Start(@"C:\aria2-1.17.0-win-32bit-build1\aria2-1.17.0-win-32bit-build1\aria2c.exe", par); P.WaitForExit(); int result1 = P.ExitCode; Console.WriteLine(result1); if (result1 == 0) { MessageBox.Show(" ! !", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(" !", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
Source: https://habr.com/ru/post/178493/
All Articles