Exemplo n.º 1
0
        public QBitTorrentClient(string host, int port, string username, string password)
        {
            _baseUri     = new Uri($"http://{host}:{port}/");
            _uriTemplate = new UriTemplate("api/v2/{section}/{methodName}");
            _client      = new TloWebClient(Encoding.UTF8, "TLO", "text/*,application/*", true);
            _host        = host;
            _port        = port;
            _username    = username;
            _password    = password;
            _client.Headers.Add("Referer", _baseUri.ToString());
            _client.UseDefaultCredentials = true;

            // if (this.Ping())
            // {
            //     authorize();
            // }
        }
Exemplo n.º 2
0
        public void SavePage(string topicId, string folder)
        {
            var str =
                new TloWebClient(enableProxy: true).DownloadString(string.Format(
                                                                       "https://rutracker.org/forum/viewtopic.php?t={0}",
                                                                       topicId));

            if (str.Contains("Тема не найдена"))
            {
                return;
            }
            using (var fileStream = File.Create(Path.Combine(folder, string.Format("{0}.html", topicId))))
            {
                using (var streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding(1251)))
                {
                    streamWriter.Write(str);
                }
            }
        }
Exemplo n.º 3
0
        public byte[] DownloadArchiveData(string page)
        {
            for (var index = 0; index < 1; ++index)
            {
                var numArray = new byte[0];
                var empty    = string.Empty;
                if (_webClient == null)
                {
                    _webClient = new TloWebClient(enableProxy: true);
                }
                byte[] bytes;
                try
                {
                    bytes = _webClient.DownloadData(page);
                }
                catch
                {
                    Thread.Sleep(index * 200);
                    continue;
                }

                var 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-страницу за 1 попытку");
        }
Exemplo n.º 4
0
        public UTorrentClient(string serverName, int port, string userName, string userPass)
        {
            if (_logger == null)
            {
                _logger = LogManager.GetLogger("uTorrentClient");
            }
            _webClient          = new TloWebClient();
            _webClient.Encoding = Encoding.UTF8;
            var svcCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + userPass));

            _webClient.Headers.Add("Authorization", "Basic " + svcCredentials);
            _serverName = serverName;
            _serverPort = port;
            try
            {
                Ping();
            }
            catch
            {
                _logger.Debug(string.Format("Имя сервера: {0}; Порт сервера: {1}", _serverName, _serverPort));
                throw;
            }
        }
Exemplo n.º 5
0
        public TransmissionClient(string serverName, int port, string userName, string userPass)
        {
            if (_logger == null)
            {
                _logger = LogManager.GetLogger("TransmissionClient");
            }
            _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);
            _webClient.Encoding = Encoding.UTF8;
            var svcCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + userPass));

            _webClient.Headers.Add("Authorization", "Basic " + svcCredentials);
            _url = string.Format("http://{0}:{1}/transmission/rpc", serverName, port);
            // try
            // {
            //     Ping();
            // }
            // catch
            // {
            //     _logger.Debug(string.Format("Имя сервера: {0}; Порт сервера: {1}", serverName, port));
            //     throw;
            // }
        }
Exemplo n.º 6
0
        public byte[] DownloadWebPages(string page)
        {
            for (var index = 0; index < 1; ++index)
            {
                var          empty        = string.Empty;
                TloWebClient tloWebClient = null;
                try
                {
                    if (_webClient == null)
                    {
                        tloWebClient = new TloWebClient(Encoding.GetEncoding(1251));
                        if (!string.IsNullOrWhiteSpace(_userName) && !string.IsNullOrWhiteSpace(_userPass))
                        {
                            var s = string.Format("login_username={0}&login_password={1}&login={2}",
                                                  HttpUtility.UrlEncode(_userName, Encoding.GetEncoding(1251)),
                                                  HttpUtility.UrlEncode(_userPass, Encoding.GetEncoding(1251)), "вход");
                            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.Error(ex.Message);
                    _logger.Error(ex.StackTrace);
                    _logger.Error(ex);
                }

                if (!string.IsNullOrWhiteSpace(empty) && !string.IsNullOrWhiteSpace(_userName) &&
                    !string.IsNullOrWhiteSpace(_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("Не удалось авторизоваться, проверьте логин и пароль");
                    }
                    _webClient = tloWebClient;
                }

                byte[] bytes;
                try
                {
                    bytes = _webClient.DownloadData(page);
                }
                catch (Exception e)
                {
                    _logger.Error(e);
                    _logger.Error(e.StackTrace);
                    continue;
                }

                var 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 (_webClient != null)
                {
                    _webClient.Dispose();
                }
                _webClient = null;
            }

            throw new Exception("Не удалось скачать WEB-страницу за 1 попытку");
        }
Exemplo n.º 7
0
        public byte[] DownloadTorrentFile(int id)
        {
            for (var index = 0; index < 100; ++index)
            {
                var          numArray1    = new byte[0];
                var          empty        = string.Empty;
                TloWebClient tloWebClient = null;
                try
                {
                    if (_webClient == null)
                    {
                        tloWebClient = new TloWebClient(enableProxy: true);
                        var s = string.Format("login_username={0}&login_password={1}&login={2}",
                                              HttpUtility.UrlEncode(_userName, Encoding.GetEncoding(1251)),
                                              HttpUtility.UrlEncode(_userPass, Encoding.GetEncoding(1251)), "Вход");
                        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)
                {
                    _logger.Warn(ex.Message);
                    _logger.Warn(ex);
                    _logger.Trace(ex.StackTrace);
                }

                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("Не удалось авторизоваться, проверьте логин и пароль");
                    }
                    _webClient = tloWebClient;
                }

                byte[] numArray2;
                if (string.IsNullOrWhiteSpace(_apiId))
                {
                    var str =
                        DownloadWebPage(string.Format(
                                            "https://" + Settings.Current.HostRuTrackerOrg + "/forum/viewtopic.php?t={0}", id))
                        .Split(new char[2]
                    {
                        '\r',
                        '\n'
                    }, StringSplitOptions.RemoveEmptyEntries).Where(x => x.Contains("form_token: '"))
                        .FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(str))
                    {
                        str = str.Split(new char[1] {
                            '\''
                        }, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    var s = string.Format("form_token={0}", str);
                    numArray2 = _webClient.UploadData(
                        string.Format("https://" + Settings.Current.HostRuTrackerOrg + "/forum/dl.php?t={0}",
                                      id), "POST", Encoding.GetEncoding(1251).GetBytes(s));
                }
                else
                {
                    numArray2 = _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", _keeperId, _apiId,
                                                                id)));
                }

                var 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 (_webClient != null)
                    {
                        _webClient.Dispose();
                    }
                    _webClient = null;
                }
                else
                {
                    if (lower[0] == 'd')
                    {
                        return(numArray2);
                    }
                    var path = Path.Combine(Settings.Folder, "error_" + id + ".html");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    using (var fileStream = File.Create(path))
                    {
                        fileStream.Write(numArray2, 0, numArray2.Length);
                    }

                    return(null);
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        private string DownloadArchivePage(string page)
        {
            var tloWebClient = new TloWebClient(enableProxy: true);

            return(tloWebClient.DownloadString(page));
        }