SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.IO; | |
3 | using System.Net; | |
4 | using System.Text; | |
5 | using System.Text.RegularExpressions; | |
6 | using System.Globalization; | |
7 | using System.Diagnostics; | |
8 | using System.Windows.Forms; | |
9 | ||
10 | public class AutoClosingMessageBox | |
11 | { | |
12 | System.Threading.Timer _timeoutTimer; | |
13 | string _caption; | |
14 | AutoClosingMessageBox(string text, string caption, int timeout) | |
15 | { | |
16 | _caption = caption; | |
17 | _timeoutTimer = new System.Threading.Timer(OnTimerElapsed, | |
18 | null, timeout, System.Threading.Timeout.Infinite); | |
19 | MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); | |
20 | } | |
21 | public static void Show(string text, string caption, int timeout) | |
22 | { | |
23 | new AutoClosingMessageBox(text, caption, timeout); | |
24 | } | |
25 | void OnTimerElapsed(object state) | |
26 | { | |
27 | IntPtr mbWnd = FindWindow(null, _caption); | |
28 | if (mbWnd != IntPtr.Zero) | |
29 | SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); | |
30 | _timeoutTimer.Dispose(); | |
31 | } | |
32 | const int WM_CLOSE = 0x0010; | |
33 | [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] | |
34 | static extern IntPtr FindWindow(string lpClassName, string lpWindowName); | |
35 | [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)] | |
36 | static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); | |
37 | } | |
38 | ||
39 | ||
40 | class Program | |
41 | { | |
42 | ||
43 | static void Main() | |
44 | { | |
45 | ||
46 | /*Вычисляем номер серии*/ | |
47 | DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo; | |
48 | DateTime date1 = DateTime.Now; | |
49 | Calendar cal = dfi.Calendar; | |
50 | var week = cal.GetWeekOfYear(date1, dfi.CalendarWeekRule, dfi.FirstDayOfWeek); | |
51 | var day = (int)cal.GetDayOfWeek(date1) == 0 ? 6 : (int)cal.GetDayOfWeek(date1) - 1; | |
52 | var epnumber = week + 79 - ((day < 5) ? 1 : 0); | |
53 | /*********/ | |
54 | ||
55 | /*Проверяем наличие флешки*/ | |
56 | string letter = ""; | |
57 | foreach (DriveInfo i in System.IO.DriveInfo.GetDrives()) | |
58 | { | |
59 | ||
60 | ||
61 | try | |
62 | { | |
63 | if (i.DriveType.ToString() == "Removable" && i.ToString() != "A:\\") | |
64 | { | |
65 | if (i.TotalFreeSpace < 3000000000) | |
66 | { | |
67 | MessageBox.Show("На флешке мало место, нужно 3гб!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
68 | return; | |
69 | } | |
70 | ||
71 | letter = String.Copy(i.ToString()); | |
72 | break; | |
73 | } | |
74 | //Console.WriteLine(i.DriveType); | |
75 | ||
76 | } | |
77 | catch (Exception E) | |
78 | { | |
79 | return; | |
80 | } | |
81 | } | |
82 | if (letter == "") | |
83 | { | |
84 | MessageBox.Show("Вставь флешку!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
85 | return; | |
86 | } | |
87 | /*********/ | |
88 | ||
89 | /*Авторизируемся*/ | |
90 | byte[] buffer = Encoding.ASCII.GetBytes("login_username=ВАШ_ЛОГИН&login_password=ВАШ_ПАРОЛЬ&login=%C2%F5%EE%E4"); | |
91 | 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; | |
92 | HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://login.rutracker.org/forum/login.php"); | |
93 | var cc = new CookieContainer(); | |
94 | WebReq.CookieContainer = cc; | |
95 | WebReq.AllowAutoRedirect = false; | |
96 | WebReq.Method = "POST"; | |
97 | WebReq.ContentType = "application/x-www-form-urlencoded"; | |
98 | WebReq.ContentLength = buffer.Length; | |
99 | HttpWebResponse WebResp; | |
100 | ||
101 | try | |
102 | { | |
103 | Stream PostData = WebReq.GetRequestStream(); | |
104 | PostData.Write(buffer, 0, buffer.Length); | |
105 | PostData.Close(); | |
106 | WebResp = (HttpWebResponse)WebReq.GetResponse(); | |
107 | } | |
108 | catch (Exception e) | |
109 | { | |
110 | MessageBox.Show("Ошибка сети", "Заголовок сообщения", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
111 | return; | |
112 | } | |
113 | ||
114 | /*Запрашиваем страницу поиска*/ | |
115 | WebReq = (HttpWebRequest)WebRequest.Create(url); | |
116 | WebReq.CookieContainer = cc; | |
117 | WebReq.AllowAutoRedirect = false; | |
118 | WebReq.Method = "GET"; | |
119 | WebReq.ContentType = "application/x-www-form-urlencoded"; | |
120 | WebResp = (HttpWebResponse)WebReq.GetResponse(); | |
121 | ||
122 | /*Находим на странице поиска ссылку на торрент*/ | |
123 | string result; | |
124 | Encoding responseEncoding = Encoding.GetEncoding(WebResp.CharacterSet); | |
125 | try | |
126 | { | |
127 | using (StreamReader sr = new StreamReader(WebResp.GetResponseStream(), responseEncoding)) | |
128 | { | |
129 | result = sr.ReadToEnd(); | |
130 | } | |
131 | } | |
132 | catch (Exception e) | |
133 | { | |
134 | MessageBox.Show("Ошибка сети", "Заголовок сообщения", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
135 | return; | |
136 | } | |
137 | ||
138 | string pattern = @"http://dl.rutracker.org/forum/dl.php\?t=\d+"; | |
139 | Regex regex = new Regex(pattern); | |
140 | Match match = regex.Match(result); | |
141 | if (match.Length == 0) | |
142 | { | |
143 | ||
144 | MessageBox.Show("Новая серия еще не вышла!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
145 | return; | |
146 | } | |
147 | else | |
148 | AutoClosingMessageBox.Show("Новая серия вышла! Начинаем закачку.", "Caption", 3000); | |
149 | ||
150 | /*Скачиваем торрент-файл*/ | |
151 | try | |
152 | { | |
153 | WebReq = (HttpWebRequest)WebRequest.Create(match.ToString()); | |
154 | WebReq.CookieContainer = cc; | |
155 | WebReq.AllowAutoRedirect = false; | |
156 | WebReq.Method = "POST"; | |
157 | WebReq.Referer = url; | |
158 | WebReq.ContentType = "application/x-www-form-urlencoded"; | |
159 | ||
160 | /*Пишем его в файл*/ | |
161 | Stream ReceiveStream = WebReq.GetResponse().GetResponseStream(); | |
162 | string filename = @"C:\123.torrent"; | |
163 | byte[] buffer1 = new byte[1024]; | |
164 | FileStream outFile = new FileStream(filename, FileMode.Create); | |
165 | int bytesRead; | |
166 | while ((bytesRead = ReceiveStream.Read(buffer1, 0, buffer.Length)) != 0) | |
167 | outFile.Write(buffer1, 0, bytesRead); | |
168 | outFile.Close(); | |
169 | ReceiveStream.Close(); | |
170 | ||
171 | ||
172 | } | |
173 | catch (Exception e) | |
174 | { | |
175 | MessageBox.Show("Ошибка при скачке торрент-файла!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
176 | return; | |
177 | } | |
178 | ||
179 | ||
180 | ||
181 | - | string par = @"--seed-time=0 -d " + letter + @" ""C:\123.torrent"" "; |
181 | + | string par = @"--seed-time=0 -d " + letter + " --select-file="+(epnumber-3)+ @" ""C:\123.torrent"" "; |
182 | Process P = Process.Start(@"C:\aria2-1.17.0-win-32bit-build1\aria2-1.17.0-win-32bit-build1\aria2c.exe", par); | |
183 | P.WaitForExit(); | |
184 | int result1 = P.ExitCode; | |
185 | Console.WriteLine(result1); | |
186 | if (result1 == 0) | |
187 | { | |
188 | MessageBox.Show("Фильм скачан! Можно вытаскивать флешку!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); | |
189 | } | |
190 | else | |
191 | { | |
192 | MessageBox.Show("Неизвестная ошибка!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); | |
193 | } | |
194 | } | |
195 | } |