Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Globalization;
- using System.Diagnostics;
- using System.Windows.Forms;
- public class AutoClosingMessageBox
- {
- System.Threading.Timer _timeoutTimer;
- string _caption;
- AutoClosingMessageBox(string text, string caption, int timeout)
- {
- _caption = caption;
- _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
- null, timeout, System.Threading.Timeout.Infinite);
- MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- public static void Show(string text, string caption, int timeout)
- {
- new AutoClosingMessageBox(text, caption, timeout);
- }
- void OnTimerElapsed(object state)
- {
- IntPtr mbWnd = FindWindow(null, _caption);
- if (mbWnd != IntPtr.Zero)
- SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
- _timeoutTimer.Dispose();
- }
- const int WM_CLOSE = 0x0010;
- [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
- static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
- static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
- }
- class Program
- {
- static void Main()
- {
- /*Вычисляем номер серии*/
- 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;
- var epnumber = week + 79 - ((day < 5) ? 1 : 0);
- /*********/
- /*Проверяем наличие флешки*/
- 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;
- }
- /*********/
- /*Авторизируемся*/
- byte[] buffer = Encoding.ASCII.GetBytes("login_username=ВАШ_ЛОГИН&login_password=ВАШ_ПАРОЛЬ&login=%C2%F5%EE%E4");
- 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;
- HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://login.rutracker.org/forum/login.php");
- var cc = new CookieContainer();
- WebReq.CookieContainer = cc;
- WebReq.AllowAutoRedirect = false;
- 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;
- }
- /*Запрашиваем страницу поиска*/
- WebReq = (HttpWebRequest)WebRequest.Create(url);
- WebReq.CookieContainer = cc;
- WebReq.AllowAutoRedirect = false;
- 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 par = @"--seed-time=0 -d " + letter + @" ""C:\123.torrent"" ";
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement