public byte[] DownloadWebPages(string page) { for (int index = 0; index < 20; ++index) { string empty = string.Empty; TLOWebClient tloWebClient = null; try { if (this._webClient == null) { tloWebClient = new TLOWebClient(Encoding.GetEncoding(1251)); if (!string.IsNullOrWhiteSpace(this._userName) && !string.IsNullOrWhiteSpace(this._userPass)) { string s = string.Format("login_username={0}&login_password={1}&login={2}", (object)HttpUtility.UrlEncode(this._userName, Encoding.GetEncoding(1251)), (object)HttpUtility.UrlEncode(this._userPass, Encoding.GetEncoding(1251)), (object)"вход"); empty = Encoding.GetEncoding("windows-1251").GetString(tloWebClient.UploadData($"https://{Settings.Current.HostRuTrackerOrg}/forum/login.php".Replace("rutracker.org", Settings.Current.HostRuTrackerOrg), "POST", Encoding.GetEncoding(1251).GetBytes(s))); } Thread.Sleep(500); } } catch (Exception ex) { _logger.Warn(ex.Message); } if (!string.IsNullOrWhiteSpace(empty) && !string.IsNullOrWhiteSpace(this._userName) && !string.IsNullOrWhiteSpace(this._userPass)) { if (empty.Contains($"https://static.{Settings.Current.HostRuTrackerOrg}/captcha".Replace("rutracker.org", Settings.Current.HostRuTrackerOrg))) { throw new Exception("При авторизации требуется ввести текст с картинки. Авторизуйтесь на WEB-сайте, а потом повторите попытку"); } if (empty.Contains("<a href=\"profile.php?mode=register\"><b>Регистрация</b></a>")) { throw new Exception("Не удалось авторизоваться, проверьте логин и пароль"); } this._webClient = tloWebClient; } byte[] bytes; try { bytes = this._webClient.DownloadData(page); } catch (Exception e) { _logger.Warn(e.Message); Thread.Sleep(index * 1000); continue; } string str = Encoding.GetEncoding("windows-1251").GetString(bytes); if (str.ToLower().Contains("форум временно отключен") || str.ToLower().Contains("форум временно отключен")) { throw new Exception("Форум временно отключен"); } if (!str.Contains($"https://static.{Settings.Current.HostRuTrackerOrg}/captcha".Replace("rutracker.org", Settings.Current.HostRuTrackerOrg)) && !str.Contains("<a href=\"profile.php?mode=register\"><b>Регистрация</b></a>")) { return(bytes); } if (this._webClient != null) { this._webClient.Dispose(); } this._webClient = (TLOWebClient)null; } throw new Exception("Не удалось скачать WEB-страницу за 20 попыток"); }
public byte[] DownloadTorrentFile(int id) { for (int index = 0; index < 100; ++index) { byte[] numArray1 = new byte[0]; string empty = string.Empty; TLOWebClient tloWebClient = (TLOWebClient)null; try { if (this._webClient == null) { tloWebClient = new TLOWebClient(); string s = string.Format("login_username={0}&login_password={1}&login={2}", (object)HttpUtility.UrlEncode(this._userName, Encoding.GetEncoding(1251)), (object)HttpUtility.UrlEncode(this._userPass, Encoding.GetEncoding(1251)), (object)"Вход"); empty = Encoding.GetEncoding("windows-1251").GetString(tloWebClient.UploadData("https://" + Settings.Current.HostRuTrackerOrg + "/forum/login.php", "POST", Encoding.GetEncoding(1251).GetBytes(s))); Thread.Sleep(500); } } catch (Exception ex) { this._logger.Warn(ex.Message); this._logger.Warn <Exception>(ex); } if (!string.IsNullOrWhiteSpace(empty)) { if (empty.Contains("https://static." + Settings.Current.HostRuTrackerOrg + "/captcha")) { throw new Exception("При авторизации требуется ввести текст с картинки. Авторизуйтесь на WEB-сайте, а потом повторите попытку"); } if (empty.Contains("<a href=\"profile.php?mode=register\"><b>Регистрация</b></a>")) { throw new Exception("Не удалось авторизоваться, проверьте логин и пароль"); } this._webClient = tloWebClient; } byte[] numArray2; try { if (string.IsNullOrWhiteSpace(this._apiid)) { string str = ((IEnumerable <string>) this.DownloadWebPage(string.Format("https://" + Settings.Current.HostRuTrackerOrg + "/forum/viewtopic.php?t={0}", (object)id)).Split(new char[2] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)).Where <string>((Func <string, bool>)(x => x.Contains("form_token: '"))).FirstOrDefault <string>(); if (!string.IsNullOrWhiteSpace(str)) { str = str.Split(new char[1] { '\'' }, StringSplitOptions.RemoveEmptyEntries)[1]; } string s = string.Format("form_token={0}", (object)str); numArray2 = this._webClient.UploadData(string.Format("https://dl." + Settings.Current.HostRuTrackerOrg + "/forum/dl.php?t={0}", (object)id), "POST", Encoding.GetEncoding(1251).GetBytes(s)); } else { numArray2 = this._webClient.UploadData("https://" + Settings.Current.HostRuTrackerOrg + "/forum/dl.php", "POST", Encoding.GetEncoding(1251).GetBytes(string.Format("keeper_user_id={0}&keeper_api_key={1}&t={2}&add_retracker_url=0", (object)this._keeperid, (object)this._apiid, (object)id))); } } catch (Exception ex) { if (index >= 20) { throw new Exception("Не удалось скачать WEB-страницу за 20 попыток:" + ex.Message, ex); } Thread.Sleep(index * 1000); continue; } string lower = Encoding.GetEncoding(1251).GetString(numArray2).ToLower(); if (lower.ToLower().Contains("форум временно отключен") || lower.Contains("форум временно отключен")) { throw new Exception("Форум временно отключен"); } if (lower.Contains("https://static." + Settings.Current.HostRuTrackerOrg + "/captcha") || lower.Contains("<a href=\"profile.php?mode=register\"><b>регистрация</b></a>")) { if (this._webClient != null) { this._webClient.Dispose(); } this._webClient = (TLOWebClient)null; } else { if (lower[0] == 'd') { return(numArray2); } string path = Path.Combine(Settings.Current.Folder, "error_" + id.ToString() + ".html"); if (File.Exists(path)) { File.Delete(path); } using (FileStream fileStream = File.Create(path)) fileStream.Write(numArray2, 0, numArray2.Length); return((byte[])null); } } return((byte[])null); }