public void SavePage(string topicID, string folder) { string str = new TLOWebClient().DownloadString(string.Format("https://rutracker.org/forum/viewtopic.php?t={0}", (object)topicID)); if (str.Contains("Тема не найдена")) { return; } using (FileStream fileStream = File.Create(Path.Combine(folder, string.Format("{0}.html", (object)topicID)))) { using (StreamWriter streamWriter = new StreamWriter((Stream)fileStream, Encoding.GetEncoding(1251))) streamWriter.Write(str); } }
public TransmissionClient(string serverName, int port, string userName, string userPass) { if (TransmissionClient._logger == null) { TransmissionClient._logger = LogManager.GetLogger("TransmissionClient"); } this._webClient = new TLOWebClient(Encoding.UTF8, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0", "application/json, text/javascript, */*; q=0.01", true); this._webClient.Encoding = Encoding.UTF8; this.svcCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + userPass)); this._webClient.Headers.Add("Authorization", "Basic " + this.svcCredentials); this._URL = string.Format("http://{0}:{1}/transmission/rpc", (object)serverName, (object)port); try { this.Ping(); } catch { TransmissionClient._logger.Debug(string.Format("Имя сервера: {0}; Порт сервера: {1}", (object)serverName, (object)port)); throw; } }
public uTorrentClient(string serverName, int port, string userName, string userPass) { if (uTorrentClient._logger == null) { uTorrentClient._logger = LogManager.GetLogger("uTorrentClient"); } this._webClient = new TLOWebClient(); this._webClient.Encoding = Encoding.UTF8; this.svcCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + userPass)); this._webClient.Headers.Add("Authorization", "Basic " + this.svcCredentials); this._ServerName = serverName; this._ServerPort = port; try { this.Ping(); } catch { uTorrentClient._logger.Debug(string.Format("Имя сервера: {0}; Порт сервера: {1}", (object)this._ServerName, (object)this._ServerPort)); throw; } }
public byte[] DownloadArchiveData(string page) { for (int index = 0; index < 20; ++index) { byte[] numArray = new byte[0]; string empty = string.Empty; if (this._webClient == null) { this._webClient = new TLOWebClient(); } byte[] bytes; try { bytes = this._webClient.DownloadData(page); } catch { Thread.Sleep(index * 1000); continue; } string lower = Encoding.GetEncoding(1251).GetString(bytes).ToLower(); if (lower.Contains("введите ваше имя и пароль")) { return(new byte[0]); } if (lower.ToLower().Contains("форум временно отключен") || lower.Contains("введите ваше имя и пароль")) { throw new Exception("Форум временно отключен"); } if (lower[0] != 'd') { return(new byte[0]); } return(bytes); } throw new Exception("Не удалось скачать WEB-страницу за 20 попыток"); }
private string DownloadArchivePage(string page) { Exception innerException = (Exception)null; for (int index = 0; index < 20; ++index) { string empty = string.Empty; TLOWebClient tloWebClient = new TLOWebClient(); try { return(tloWebClient.DownloadString(page)); } catch (Exception ex) { innerException = ex; if (ex.Message.Contains("404")) { throw ex; } Thread.Sleep(index * 1000); } } throw new Exception("Не удалось скачать WEB-страницу за 20 попыток: " + innerException.Message, innerException); }
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); }