Esempio n. 1
0
        private async Task <IEnumerable <ReleaseInfo> > PerformQueryWithRetry(TorznabQuery query, bool retry)
        {
            var releases = new List <ReleaseInfo>();

            // check the token and renewal if necessary
            await RenewalTokenAsync();

            var response = await RequestWithCookiesAndRetryAsync(BuildSearchUrl(query));

            var jsonContent = JObject.Parse(response.ContentString);
            var errorCode   = jsonContent.Value <int>("error_code");

            switch (errorCode)
            {
            case 0:     // valid response with results
                break;

            case 2:
            case 4:                            // invalid token
                await RenewalTokenAsync(true); // force renewal token

                response = await RequestWithCookiesAndRetryAsync(BuildSearchUrl(query));

                jsonContent = JObject.Parse(response.ContentString);
                break;

            case 5:     // Too many requests per second. Maximum requests allowed are 1req/2sec Please try again later!
                return(await PerformQueryWithRetry(query, false));

            case 8:     // imdb not found, see issue #12466
            case 10:    // imdb not found, see issue #1486
            case 20:    // no results found
                if (jsonContent.ContainsKey("rate_limit"))
                {
                    logger.Warn("Rate Limit exceeded. Retry will be performed.");
                    return(await PerformQueryWithRetry(query, false));
                }
                // the api returns "no results" in some valid queries. we do one retry on this case but we can't do more
                // because we can't distinguish between search without results and api malfunction
                return(retry ? await PerformQueryWithRetry(query, false) : releases);

            default:
                throw new Exception("Unknown error code: " + errorCode + " response: " + response.ContentString);
            }

            try
            {
                foreach (var item in jsonContent.Value <JArray>("torrent_results"))
                {
                    var title = WebUtility.HtmlDecode(item.Value <string>("title"));

                    var magnetStr = item.Value <string>("download");
                    var magnetUri = new Uri(magnetStr);

                    // #11021 we can't use the magnet link as guid because they are using random ports
                    var infoHash = magnetStr.Split(':')[3].Split('&')[0];
                    var guid     = new Uri(SiteLink + "infohash/" + infoHash);

                    // append app_id to prevent api server returning 403 forbidden
                    var details = new Uri(item.Value <string>("info_page") + "&app_id=" + _appId);

                    // ex: 2015-08-16 21:25:08 +0000
                    var dateStr     = item.Value <string>("pubdate").Replace(" +0000", "");
                    var dateTime    = DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                    var publishDate = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc).ToLocalTime();

                    var size     = item.Value <long>("size");
                    var seeders  = item.Value <int>("seeders");
                    var leechers = item.Value <int>("leechers");

                    var release = new ReleaseInfo
                    {
                        Title                = title,
                        Category             = MapTrackerCatDescToNewznab(item.Value <string>("category")),
                        MagnetUri            = magnetUri,
                        InfoHash             = infoHash,
                        Details              = details,
                        PublishDate          = publishDate,
                        Guid                 = guid,
                        Seeders              = seeders,
                        Peers                = leechers + seeders,
                        Size                 = size,
                        DownloadVolumeFactor = 0,
                        UploadVolumeFactor   = 1
                    };

                    var episodeInfo = item.Value <JToken>("episode_info");
                    if (episodeInfo.HasValues)
                    {
                        release.Imdb   = ParseUtil.GetImdbID(episodeInfo.Value <string>("imdb"));
                        release.TVDBId = episodeInfo.Value <long?>("tvdb");
                        release.RageID = episodeInfo.Value <long?>("tvrage");
                        release.TMDb   = episodeInfo.Value <long?>("themoviedb");
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.ContentString, ex);
            }

            return(releases);
        }
Esempio n. 2
0
    private static Table ConstructTable(string text)
    {
        Table    t            = new Table(null);
        int      inOtherTable = 0;
        string   currentValue = "";
        DynValue valueName    = null;

        bool inString = false, inSlashEffect1 = false, inSlashEffect2 = false;

        foreach (char c in text)
        {
            if (inSlashEffect1)
            {
                inSlashEffect1 = false;
            }
            else if (inSlashEffect2)
            {
                inSlashEffect2 = false;
            }

            if (!inSlashEffect2)
            {
                if (c == '{' && !inString)
                {
                    if (inOtherTable != 1)
                    {
                        currentValue += c;
                    }
                    inOtherTable++;
                }
                else if (c == '}' && !inString)
                {
                    inOtherTable--;
                    if (inOtherTable == 0)
                    {
                        if (valueName == null)
                        {
                            t.Append(DynValue.NewTable(ConstructTable(currentValue)));
                        }
                        else
                        {
                            t.Set(valueName, DynValue.NewTable(ConstructTable(currentValue)));
                        }
                        currentValue = "";
                        valueName    = null;
                    }
                    else
                    {
                        currentValue += c;
                    }
                }
                else if (c == '"' && inOtherTable != 0)
                {
                    inString = !inString;
                }
                else if (c == '\\')
                {
                    inSlashEffect1 = true;
                    inSlashEffect2 = true;
                }
                else if (c == ',' && (!inString || inOtherTable != 0))
                {
                    currentValue = currentValue.Trim();
                    Type     type = CheckRealType(currentValue);
                    DynValue dv;
                    if (type == typeof(bool))
                    {
                        dv = DynValue.NewBoolean(currentValue == "true");
                    }
                    else if (type == typeof(float))
                    {
                        dv = DynValue.NewNumber(ParseUtil.GetFloat(currentValue));
                    }
                    else
                    {
                        dv = DynValue.NewString(currentValue.Trim('"'));
                    }
                    if (valueName == null)
                    {
                        t.Append(dv);
                    }
                    else
                    {
                        t.Set(valueName, dv);
                    }
                    valueName    = null;
                    currentValue = "";
                }
                else if (c == '=' && (!inString || inOtherTable != 0))
                {
                    currentValue = currentValue.Trim();
                    Type type = CheckRealType(currentValue);
                    if (type == typeof(bool))
                    {
                        valueName = DynValue.NewBoolean(currentValue == "true");
                    }
                    else if (type == typeof(float))
                    {
                        valueName = DynValue.NewNumber(ParseUtil.GetFloat(currentValue));
                    }
                    else
                    {
                        valueName = DynValue.NewString(currentValue.Trim('"'));
                    }
                }
                else
                {
                    currentValue += c;
                }
            }
            else
            {
                currentValue += c;
            }
        }

        // Parse one final time for the end of the string
        Type     typey = CheckRealType(currentValue);
        DynValue dynv;

        if (typey == typeof(bool))
        {
            dynv = DynValue.NewBoolean(currentValue == "true");
        }
        else if (typey == typeof(float))
        {
            dynv = DynValue.NewNumber(ParseUtil.GetFloat(currentValue));
        }
        else
        {
            dynv = DynValue.NewString(currentValue.Trim('"'));
        }
        if (valueName == null)
        {
            t.Append(dynv);
        }
        else
        {
            t.Set(valueName, dynv);
        }

        return(t);
    }
Esempio n. 3
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            var qc = new List <KeyValuePair <string, string> > // NameValueCollection don't support cat[]=19&cat[]=6
            {
                { "tpage", "1" }
            };

            if (query.IsImdbQuery)
            {
                qc.Add("search", query.ImdbID);
                qc.Add("nfo", "true");
            }
            else if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
            {
                qc.Add("search", query.GetQueryString());
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                qc.Add("cat[]", cat);
            }

            var searchUrl = SearchUrl + "?" + qc.GetQueryString();
            var result    = await RequestWithCookiesAndRetryAsync(searchUrl, referer : SearchUrl);

            if (result.IsRedirect)
            {
                throw new Exception($"Your cookie did not work. Please, configure the tracker again. Message: {result.ContentString}");
            }

            if (!result.ContentString.StartsWith("{")) // not JSON => error
            {
                throw new ExceptionWithConfigData(result.ContentString, configData);
            }

            var json = JsonConvert.DeserializeObject <dynamic>(result.ContentString);

            try
            {
                var torrents = json["torrents"]; // latest torrents
                if (json["hits"] != null)        // is search result
                {
                    torrents = json.SelectTokens("$.hits[?(@._type == 'torrent')]._source");
                }
                foreach (var torrent in torrents)
                {
                    var torrentId   = (long)torrent.id;
                    var details     = new Uri(SiteLink + "torrents/" + torrentId);
                    var link        = new Uri(SiteLink + "download/" + torrentId);
                    var publishDate = DateTime.Parse(torrent.added.ToString());
                    var imdbId      = ParseUtil.GetImdbID(torrent.imdb_id.ToString());

                    Uri poster = null;
                    if ((bool)torrent.poster)
                    {
                        if (torrent["imdb_id"] != null)
                        {
                            poster = new Uri(CdnUrl + "images/torrents/poster/imd/l/" + torrent["imdb_id"] + ".jpg");
                        }
                        else if (torrent["cdu_id"] != null)
                        {
                            poster = new Uri(CdnUrl + "images/torrents/poster/cdu/b/" + torrent["cdu_id"] + "_front.jpg");
                        }
                        else if (torrent["steam_id"] != null)
                        {
                            poster = new Uri(CdnUrl + "images/torrents/poster/ste/l/" + torrent["steam_id"] + ".jpg");
                        }
                    }

                    var title = torrent.name.ToString();

                    var descriptions = new List <string>();
                    var language     = (string)torrent.language;
                    if (!string.IsNullOrEmpty(language))
                    {
                        descriptions.Add("Language: " + language);
                    }
                    else if ((bool?)torrent.polish == true)
                    {
                        descriptions.Add("Language: pl");
                    }

                    if (language == "pl" && (((BoolConfigurationItem)configData.GetDynamic("LanguageTitle")).Value))
                    {
                        title += " POLISH";
                    }

                    var description = descriptions.Any() ? string.Join("<br />\n", descriptions) : null;

                    var release = new ReleaseInfo
                    {
                        Title                = title,
                        Details              = details,
                        Guid                 = details,
                        Link                 = link,
                        PublishDate          = publishDate,
                        Category             = MapTrackerCatToNewznab(torrent.category.ToString()),
                        Size                 = (long)torrent.size,
                        Grabs                = (long)torrent.completed,
                        Seeders              = (int)torrent.seeders,
                        Peers                = (int)torrent.seeders + (int)torrent.leechers,
                        Imdb                 = imdbId,
                        Poster               = poster,
                        Description          = description,
                        MinimumRatio         = 1,
                        MinimumSeedTime      = 259200, // 72 hours (I can't verify this, but this is a safe value in most trackers)
                        UploadVolumeFactor   = 1,
                        DownloadVolumeFactor = 1
                    };

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(result.ToString(), ex);
            }

            return(releases);
        }
Esempio n. 4
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases        = new List <ReleaseInfo>();
            var searchString    = query.GetQueryString();
            var queryUrl        = SearchUrl;
            var queryCollection = new NameValueCollection();

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }

            if (queryCollection.Count > 0)
            {
                queryUrl += "?" + queryCollection.GetQueryString();
            }

            var results = await RequestStringWithCookiesAndRetry(queryUrl);

            // Check for being logged out
            if (results.IsRedirect)
            {
                throw new AuthenticationException();
            }

            try
            {
                CQ  dom  = results.Content;
                var rows = dom["#torrentTable > tbody > tr.browse"];
                foreach (var row in rows)
                {
                    CQ  qRow    = row.Cq();
                    var release = new ReleaseInfo();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;
                    release.Title           = qRow.Find(".torrentName").Text();
                    release.Description     = release.Title;
                    release.Guid            = new Uri(SiteLink + qRow.Find(".torrentName").Attr("href"));
                    release.Comments        = release.Guid;
                    release.Link            = new Uri(SiteLink + qRow.Find(".dlLinksInfo > a").Attr("href"));

                    var sizeStr = qRow.Find(".sizeInfo").Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    var dateStr = qRow.Find(".ulInfo").Text().Split('|').Last().Trim();
                    var agoIdx  = dateStr.IndexOf("ago");
                    if (agoIdx > -1)
                    {
                        dateStr = dateStr.Substring(0, agoIdx);
                    }
                    release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);

                    release.Seeders = ParseUtil.CoerceInt(qRow.Find(".seedersInfo").Text());
                    release.Peers   = ParseUtil.CoerceInt(qRow.Find(".leechersInfo").Text()) + release.Seeders;

                    var cat = qRow.Find("td:eq(0) a").First().Attr("href").Substring(15);//browse.php?cat=24
                    release.Category = MapTrackerCatToNewznab(cat);

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }
            return(releases);
        }
Esempio n. 5
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases         = new List <ReleaseInfo>();
            var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(query.GetQueryString()));
            var response         = await RequestStringWithCookiesAndRetry(episodeSearchUrl);

            var results = response.Content;

            try
            {
                CQ  dom  = results;
                var rows = dom["table.lista > tbody > tr"];
                foreach (var row in rows)
                {
                    // this tracker has horrible markup, find the result rows by looking for the style tag before each one
                    var prev = row.PreviousElementSibling;
                    if (prev == null || prev.NodeName.ToLowerInvariant() != "style")
                    {
                        continue;
                    }

                    CQ  qRow    = row.Cq();
                    var release = new ReleaseInfo();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    var qLink = row.ChildElements.ElementAt(1).FirstElementChild.Cq();
                    release.Title    = qLink.Text().Trim();
                    release.Comments = new Uri(SiteLink + qLink.Attr("href"));
                    release.Guid     = release.Comments;

                    var qDownload = row.ChildElements.ElementAt(3).FirstElementChild.Cq();
                    release.Link = new Uri(SiteLink + qDownload.Attr("href"));

                    //"July 11, 2015, 13:34:09", "Today at 20:04:23"
                    var dateStr = row.ChildElements.ElementAt(4).Cq().Text().Trim();
                    if (dateStr.StartsWith("Today"))
                    {
                        release.PublishDate = DateTime.Today + TimeSpan.ParseExact(dateStr.Replace("Today at ", ""), "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
                    }
                    else if (dateStr.StartsWith("Yesterday"))
                    {
                        release.PublishDate = DateTime.Today - TimeSpan.FromDays(1) + TimeSpan.ParseExact(dateStr.Replace("Yesterday at ", ""), "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        release.PublishDate = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "MMMM dd, yyyy, HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Local);
                    }

                    var sizeStr = row.ChildElements.ElementAt(5).Cq().Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text());
                    release.Peers   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(8).Cq().Text()) + release.Seeders;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }
            return(releases);
        }
Esempio n. 6
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            // remove dashes at the beginning of keywords as they exclude search strings (see issue #3096)
            var searchString = query.GetQueryString();

            searchString = Regex.Replace(searchString, @"(^|\s)-", " ");

            var searchUrl = SearchUrl;

            if (query.IsImdbQuery)
            {
                searchUrl += "imdbID/" + query.ImdbID + "/";
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                searchUrl += "exact/1/query/" + WebUtility.UrlEncode(searchString) + "/";
            }

            var cats = MapTorznabCapsToTrackers(query);

            if (cats.Count > 0)
            {
                searchUrl += "categories/" + string.Join(",", cats);
            }
            else
            {
                searchUrl += "newfilter/2"; // include 0day and music
            }
            var results = await RequestWithCookiesAndRetryAsync(searchUrl);

            if (results.ContentString.Contains("/user/account/login")) // re-login
            {
                await DoLogin();

                results = await RequestWithCookiesAndRetryAsync(searchUrl);
            }

            try
            {
                var rows = (JArray)((JObject)JsonConvert.DeserializeObject(results.ContentString))["torrentList"];
                foreach (var row in rows)
                {
                    var title = row["name"].ToString();
                    if (!query.MatchQueryStringAND(title))
                    {
                        continue;
                    }

                    var torrentId   = row["fid"].ToString();
                    var comments    = new Uri(SiteLink + "torrent/" + torrentId);
                    var link        = new Uri(SiteLink + "download/" + torrentId + "/" + row["filename"]);
                    var publishDate = DateTime.ParseExact(row["addedTimestamp"].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                    var seeders     = (int)row["seeders"];

                    // freeleech #6579 #6624 #7367
                    var dlMultiplier   = row["download_multiplier"].ToString();
                    var dlVolumeFactor = string.IsNullOrEmpty(dlMultiplier) ? 1 : ParseUtil.CoerceInt(dlMultiplier);

                    var release = new ReleaseInfo
                    {
                        Title                = title,
                        Comments             = comments,
                        Guid                 = comments,
                        Link                 = link,
                        PublishDate          = publishDate,
                        Category             = MapTrackerCatToNewznab(row["categoryID"].ToString()),
                        Size                 = (long)row["size"],
                        Grabs                = (int)row["completed"],
                        Seeders              = seeders,
                        Peers                = seeders + (int)row["leechers"],
                        Imdb                 = ParseUtil.GetImdbID(row["imdbID"].ToString()),
                        UploadVolumeFactor   = 1,
                        DownloadVolumeFactor = dlVolumeFactor,
                        MinimumRatio         = 1,
                        MinimumSeedTime      = 172800 // 48 hours
                    };

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.ContentString, ex);
            }

            return(releases);
        }
Esempio n. 7
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases        = new List <ReleaseInfo>();
            var queryUrl        = SearchUrl;
            var queryCollection = new NameValueCollection();
            var cats            = MapTorznabCapsToTrackers(query);
            var tags            = string.Empty;
            var catGroups       = new List <string>();

            foreach (var cat in cats)
            {
                //"cat[]=7&tags=x264"
                var cSplit = cat.Split('&');
                if (cSplit.Length > 0)
                {
                    var gsplit = cSplit[0].Split('=');
                    if (gsplit.Length > 1)
                    {
                        catGroups.Add(gsplit[1]);
                    }
                }

                if (cSplit.Length > 1)
                {
                    var gsplit = cSplit[1].Split('=');
                    if (gsplit.Length > 1)
                    {
                        if (tags != string.Empty)
                        {
                            tags += ",";
                        }
                        tags += gsplit[1];
                    }
                }
            }

            if (catGroups.Distinct().Count() == 1)
            {
                queryCollection.Add("cat[]", catGroups.First());
            }

            if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
            {
                queryCollection.Add("st", "1");
                queryCollection.Add("search", query.GetQueryString());
            }

            // Do not include too many tags as it'll mess with their servers.
            if (tags.Split(',').Length < 7)
            {
                queryCollection.Add("tags", tags);
                if (!string.IsNullOrWhiteSpace(tags))
                {
                    // if tags are specified match any
                    queryCollection.Add("tf", "any");
                }
                else
                {
                    // if no tags are specified match all, with any we get random results
                    queryCollection.Add("tf", "all");
                }
            }

            if (queryCollection.Count > 0)
            {
                queryUrl += "?" + queryCollection.GetQueryString();
            }

            var response = await RequestStringWithCookiesAndRetry(queryUrl);

            if (response.IsRedirect)
            {
                await ApplyConfiguration(null);

                response = await RequestStringWithCookiesAndRetry(queryUrl);
            }

            try
            {
                CQ  dom  = response.Content;
                var rows = dom["table > tbody > tr.browse"];
                foreach (var row in rows)
                {
                    CQ  qRow    = row.Cq();
                    var release = new ReleaseInfo();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    var qLink = row.ChildElements.ElementAt(1).Cq().Find("a").First();
                    release.Title = qLink.Text().Trim();
                    if (qLink.Find("span").Count() == 1 && release.Title.StartsWith("NEW! |"))
                    {
                        release.Title = release.Title.Substring(6).Trim();
                    }

                    release.Comments = new Uri(SiteLink + qLink.Attr("href"));
                    release.Guid     = release.Comments;

                    var qDownload = row.ChildElements.ElementAt(2).Cq().Find("a").First();
                    release.Link = new Uri(SiteLink + qDownload.Attr("href"));

                    var dateStr = Regex.Replace(row.ChildElements.ElementAt(5).InnerHTML, @"\<br[\s]{0,1}[\/]{0,1}\>", " ");
                    release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);

                    var sizeStr = row.ChildElements.ElementAt(7).Cq().Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(9).InnerText);
                    release.Peers   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(10).InnerText) + release.Seeders;

                    var cat = row.ChildElements.ElementAt(0).ChildElements.ElementAt(0).GetAttribute("href").Replace("browse.php?", string.Empty);
                    release.Category = MapTrackerCatToNewznab(cat);

                    var files = qRow.Find("td:nth-child(4)").Text();
                    release.Files = ParseUtil.CoerceInt(files);

                    var grabs = qRow.Find("td:nth-child(9)").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    release.DownloadVolumeFactor = 0; // ratioless
                    release.UploadVolumeFactor   = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }
            return(releases);
        }
Esempio n. 8
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchString = query.GetQueryString();

            var queryCollection = new Dictionary <string, string>();

            queryCollection.Add("search_type", "t_name");
            queryCollection.Add("do", "search");
            queryCollection.Add("keywords", searchString);
            queryCollection.Add("category", "0"); // multi cat search not supported

            var results = await PostDataWithCookies(BrowseUrl, queryCollection);

            if (results.IsRedirect)
            {
                // re-login
                await ApplyConfiguration(null);

                results = await PostDataWithCookies(BrowseUrl, queryCollection);
            }

            try
            {
                var RowsSelector         = "table[id='sortabletable'] > tbody > tr";
                var SearchResultParser   = new HtmlParser();
                var SearchResultDocument = SearchResultParser.ParseDocument(results.Content);
                var Rows     = SearchResultDocument.QuerySelectorAll(RowsSelector);
                var lastDate = DateTime.Now;

                foreach (var Row in Rows.Skip(1))
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 0;

                    var category = Row.QuerySelector("td:nth-child(1) > a");
                    var title    = Row.QuerySelector("td:nth-child(2) a");
                    var added    = Row.QuerySelector("td:nth-child(2) > div:has(span[style=\"float: right;\"])");
                    if (added == null) // not a torrent line
                    {
                        continue;
                    }
                    var pretime = added.QuerySelector("font.mkprettytime");
                    var tooltip = Row.QuerySelector("td:nth-child(2) > div.tooltip-content");

                    var link     = Row.QuerySelector("td:nth-child(3)").QuerySelector("a");
                    var comments = Row.QuerySelector("td:nth-child(2)").QuerySelector("a");
                    var Size     = Row.QuerySelector("td:nth-child(5)");
                    var Grabs    = Row.QuerySelector("td:nth-child(6)").QuerySelector("a");
                    var Seeders  = Row.QuerySelector("td:nth-child(7)").QuerySelector("a");
                    var Leechers = Row.QuerySelector("td:nth-child(8)").QuerySelector("a");

                    var categoryId = category.GetAttribute("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(categoryId);

                    release.Title    = title.TextContent;
                    release.Category = MapTrackerCatToNewznab(categoryId);
                    release.Link     = new Uri(link.GetAttribute("href"));
                    release.Comments = new Uri(comments.GetAttribute("href"));
                    release.Guid     = release.Link;
                    release.Size     = ReleaseInfo.GetBytes(Size.TextContent);
                    release.Seeders  = ParseUtil.CoerceInt(Seeders.TextContent);
                    release.Peers    = ParseUtil.CoerceInt(Leechers.TextContent) + release.Seeders;
                    release.Grabs    = ParseUtil.CoerceLong(Grabs.TextContent);

                    if (TorrentHTTPSMode)
                    {
                        var linkHttps = Row.QuerySelector("td:nth-child(4)").QuerySelector("a").GetAttribute("href");
                        var idTorrent = ParseUtil.GetArgumentFromQueryString(linkHttps, "id");
                        release.Link = new Uri($"{SiteLink}download.php?id={idTorrent}&type=ssl");
                    }

                    if (added.QuerySelector("img[alt^=\"TORRENT GRATUIT\"]") != null)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (added.QuerySelector("img[alt^=\"TORRENT SILVER\"]") != null)
                    {
                        release.DownloadVolumeFactor = 0.5;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    if (added.QuerySelector("img[alt^=\"TORRENT X2\"]") != null)
                    {
                        release.UploadVolumeFactor = 2;
                    }
                    else
                    {
                        release.UploadVolumeFactor = 1;
                    }

                    if (tooltip != null)
                    {
                        var banner = tooltip.QuerySelector("img");
                        if (banner != null)
                        {
                            release.BannerUrl = new Uri(banner.GetAttribute("src"));
                            banner.Remove();
                        }

                        tooltip.QuerySelector("div:contains(\"Total Hits\")").Remove();

                        var longtitle = tooltip.QuerySelectorAll("div").First();
                        release.Title = longtitle.TextContent;
                        longtitle.Remove();

                        var desc = tooltip.TextContent.Trim();
                        if (!string.IsNullOrWhiteSpace(desc))
                        {
                            release.Description = desc;
                        }
                    }

                    //issue #5064 replace multi keyword
                    if (!string.IsNullOrEmpty(ReplaceMulti))
                    {
                        var regex = new Regex("(?i)([\\.\\- ])MULTI([\\.\\- ])");
                        release.Title = regex.Replace(release.Title, "$1" + ReplaceMulti + "$2");
                    }
                    // issue #6855 Replace VOSTFR with ENGLISH
                    if (configData.Vostfr.Value)
                    {
                        release.Title = release.Title.Replace("VOSTFR", "ENGLISH");
                    }

                    if (pretime != null)
                    {
                        if (release.Description == null)
                        {
                            release.Description = pretime.TextContent;
                        }
                        else
                        {
                            release.Description += "<br>\n" + pretime.TextContent;
                        }
                        release.PublishDate = lastDate;
                    }
                    else
                    {
                        release.PublishDate = DateTime.ParseExact(added.TextContent.Trim(), "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture);
                        lastDate            = release.PublishDate;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
Esempio n. 9
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            var qc = new NameValueCollection
            {
                { "incldead", "1" }
            };

            if (query.IsImdbQuery)
            {
                qc.Add("search", query.ImdbID);
                qc.Add("sc", "2"); // search in description
            }
            else
            {
                qc.Add("search", query.GetQueryString());
                qc.Add("sc", "1"); // search in title
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                qc.Add("c" + cat, "1");
            }

            var searchUrl = SearchUrl + "?" + qc.GetQueryString();
            var response  = await RequestWithCookiesAndRetryAsync(searchUrl, referer : SearchUrl);

            if (response.IsRedirect) // re-login
            {
                await ApplyConfiguration(null);

                response = await RequestWithCookiesAndRetryAsync(searchUrl, referer : SearchUrl);
            }

            try
            {
                var parser = new HtmlParser();
                var dom    = parser.ParseDocument(response.ContentString);
                var rows   = dom.QuerySelectorAll("table > tbody:has(tr > td.colhead) > tr:not(:has(td.colhead))");
                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    var link    = row.QuerySelector("td:nth-of-type(2) a:nth-of-type(2)");
                    release.Guid     = new Uri(SiteLink + link.GetAttribute("href"));
                    release.Comments = release.Guid;
                    release.Title    = link.GetAttribute("title");

                    // There isn't a title attribute if the release name isn't truncated.
                    if (string.IsNullOrWhiteSpace(release.Title))
                    {
                        release.Title = link.FirstChild.TextContent.Trim();
                    }
                    release.Description = release.Title;

                    // If we search an get no results, we still get a table just with no info.
                    if (string.IsNullOrWhiteSpace(release.Title))
                    {
                        break;
                    }

                    // Check if the release has been assigned a category
                    var qCat = row.QuerySelector("td:nth-of-type(1) a");
                    if (qCat != null)
                    {
                        var cat = qCat.GetAttribute("href").Substring(15);
                        release.Category = MapTrackerCatToNewznab(cat);
                    }

                    var qLink = row.QuerySelector("td:nth-of-type(2) a");
                    release.Link = new Uri(SiteLink + qLink.GetAttribute("href"));
                    var added = row.QuerySelector("td:nth-of-type(5)").TextContent.Trim();
                    release.PublishDate = DateTime.ParseExact(added, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture);
                    var sizeStr = row.QuerySelector("td:nth-of-type(7)").TextContent.Trim();
                    release.Size    = ReleaseInfo.GetBytes(sizeStr);
                    release.Seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)").TextContent.Trim());
                    release.Peers   = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)").TextContent.Trim()) +
                                      release.Seeders;
                    var files = row.QuerySelector("td:nth-child(3)").TextContent;
                    release.Files = ParseUtil.CoerceInt(files);
                    var grabs = row.QuerySelector("td:nth-child(8)").TextContent;
                    if (grabs != "----")
                    {
                        release.Grabs = ParseUtil.CoerceInt(grabs);
                    }
                    release.DownloadVolumeFactor =
                        row.QuerySelector("font[color=\"green\"]:contains(\"F\"):contains(\"L\")") != null ? 0 : 1;
                    release.UploadVolumeFactor = 1;
                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.ContentString, ex);
            }

            return(releases);
        }
Esempio n. 10
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases        = new List <ReleaseInfo>();
            var searchurls      = new List <string>();
            var searchUrl       = SearchUrl;// string.Format(SearchUrl, HttpUtility.UrlEncode()));
            var queryCollection = new NameValueCollection();
            var searchString    = query.GetQueryString();


            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                searchUrl += "category%5B%5D=" + cat + "&";
            }


            if (query.ImdbID != null)
            {
                queryCollection.Add("search", query.ImdbID);
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }



            queryCollection.Add("active", "0");
            queryCollection.Add("options", "0");

            searchUrl += queryCollection.GetQueryString().Replace("(", "%28").Replace(")", "%29"); // maually url encode brackets to prevent "hacking" detection


            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            try
            {
                CQ          dom = results.Content;
                ReleaseInfo release;

                var rows = dom[".mainblockcontenttt > tbody > tr:has(a[href^=\"details.php?id=\"])"];
                foreach (var row in rows)
                {
                    CQ qRow = row.Cq();

                    release = new ReleaseInfo();

                    release.Title       = qRow.Find("td.mainblockcontent b a").Text();
                    release.Description = qRow.Find("td:nth-child(3) > span").Text();

                    if (0 != qRow.Find("td.mainblockcontent u").Length)
                    {
                        var  imdbStr = qRow.Find("td.mainblockcontent u").Parent().First().Attr("href").Replace("http://www.imdb.com/title/tt", "").Replace("/", "");
                        long imdb;
                        if (ParseUtil.TryCoerceLong(imdbStr, out imdb))
                        {
                            release.Imdb = imdb;
                        }
                    }

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;



                    int seeders, peers;
                    if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(9).FirstChild.FirstChild.InnerText, out seeders))
                    {
                        release.Seeders = seeders;
                        if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(10).FirstChild.FirstChild.InnerText, out peers))
                        {
                            release.Peers = peers + release.Seeders;
                        }
                    }

                    release.Grabs = ParseUtil.CoerceLong(qRow.Find("td:nth-child(12)").Text());

                    string fullSize = qRow.Find("td.mainblockcontent").Get(6).InnerText;
                    release.Size = ReleaseInfo.GetBytes(fullSize);

                    release.Guid     = new Uri(SiteLink + qRow.Find("td.mainblockcontent b a").Attr("href"));
                    release.Link     = new Uri(SiteLink + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href"));
                    release.Comments = new Uri(SiteLink + qRow.Find("td.mainblockcontent b a").Attr("href"));

                    string[] dateSplit  = qRow.Find("td.mainblockcontent").Get(5).InnerHTML.Split(',');
                    string   dateString = dateSplit[1].Substring(0, dateSplit[1].IndexOf('>')).Trim();
                    release.PublishDate = DateTime.ParseExact(dateString, "dd MMM yyyy HH:mm:ss zz00", CultureInfo.InvariantCulture).ToLocalTime();

                    string category = qRow.Find("td:eq(0) a").Attr("href").Replace("torrents.php?category=", "");
                    release.Category = MapTrackerCatToNewznab(category);

                    release.UploadVolumeFactor = 1;

                    if (qRow.Find("img[alt=\"Free Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                        release.UploadVolumeFactor   = 0;
                    }
                    else if (qRow.Find("img[alt=\"Silver Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.5;
                    }
                    else if (qRow.Find("img[alt=\"Bronze Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.75;
                    }
                    else if (qRow.Find("img[alt=\"Blue Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.25;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
Esempio n. 11
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday);
            TimeZoneInfo.TransitionTime endTransition   = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday);
            TimeSpan delta = new TimeSpan(1, 0, 0);

            TimeZoneInfo.AdjustmentRule   adjustment  = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition);
            TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment };
            TimeZoneInfo germanyTz = TimeZoneInfo.CreateCustomTimeZone("W. Europe Standard Time", new TimeSpan(1, 0, 0), "(GMT+01:00) W. Europe Standard Time", "W. Europe Standard Time", "W. Europe DST Time", adjustments);

            var releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = BrowseUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("showsearch", "1");
            queryCollection.Add("incldead", "1");
            queryCollection.Add("orderby", "added");
            queryCollection.Add("sort", "desc");

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }
            searchUrl += "?" + queryCollection.GetQueryString();

            var response = await RequestStringWithCookies(searchUrl);

            var results = response.Content;

            try
            {
                CQ  dom             = results;
                var globalFreeleech = dom.Find("div > img[alt=\"Only Upload\"][title^=\"ONLY UPLOAD \"]").Any();
                var rows            = dom["table.tableinborder > tbody > tr:has(td.tableb)"];

                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    var qRow    = row.Cq();

                    var qDetailsLink = qRow.Find("a[href^=details.php?id=]").First();
                    release.Title = qDetailsLink.Attr("title");

                    if (!query.MatchQueryStringAND(release.Title))
                    {
                        continue;
                    }

                    var qCatLink    = qRow.Find("a[href^=browse.php?cat=]").First();
                    var qDLLink     = qRow.Find("a[href^=download.php?torrent=]").First();
                    var qSeeders    = qRow.Find("span:contains(Seeder) > b:eq(0)");
                    var qLeechers   = qRow.Find("span:contains(Seeder) > b:eq(1)");
                    var qDateStr    = qRow.Find("td > table > tbody > tr > td:eq(7)").First();
                    var qSize       = qRow.Find("span:contains(Volumen) > b:eq(0)").First();
                    var qOnlyUpload = qRow.Find("img[title=OnlyUpload]");

                    if (qOnlyUpload.Any())
                    {
                        release.MinimumRatio    = 2;
                        release.MinimumSeedTime = 144 * 60 * 60;
                    }
                    else
                    {
                        release.MinimumRatio    = 1;
                        release.MinimumSeedTime = 72 * 60 * 60;
                    }

                    var catStr = qCatLink.Attr("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    release.Link     = new Uri(SiteLink + qDLLink.Attr("href"));
                    release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href"));
                    release.Guid     = release.Link;

                    var sizeStr = qSize.Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qSeeders.Text());
                    release.Peers   = ParseUtil.CoerceInt(qLeechers.Text()) + release.Seeders;

                    var      dateStr    = qDateStr.Text().Trim().Replace('\xA0', ' ');
                    DateTime dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);

                    DateTime pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz);
                    release.PublishDate = pubDateUtc.ToLocalTime();

                    var files = qRow.Find("a[href*=\"&filelist=1\"] ~ font ~ b").Text();
                    release.Files = ParseUtil.CoerceInt(files);

                    var grabs = qRow.Find("a[href*=\"&tosnatchers=1\"] ~ font ~ b").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (globalFreeleech)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (qRow.Find("img[alt=\"OU\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
Esempio n. 12
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();
            var passkey  = configData.Passkey.Value;

            var qc = new NameValueCollection
            {
                { "api", "" },
                { "passkey", passkey },
                { "search", query.IsImdbQuery ? query.ImdbID : query.GetQueryString() }
            };

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                qc.Add("categories[" + cat + "]", "1");
            }

            var searchUrl = SearchUrl + qc.GetQueryString();
            var response  = await RequestWithCookiesAndRetryAsync(searchUrl);

            if (response.ContentString?.Contains("User not found or passkey not set") == true)
            {
                throw new Exception("The passkey is invalid. Check the indexer configuration.");
            }

            try
            {
                var jsonContent = JArray.Parse(response.ContentString);
                foreach (var item in jsonContent)
                {
                    var title = item.Value <string>("name");
                    if (!query.IsImdbQuery && !query.MatchQueryStringAND(title))
                    {
                        continue;
                    }

                    var id             = item.Value <long>("id");
                    var details        = new Uri(DetailsUrl + "id=" + id);
                    var link           = new Uri(DownloadUrl + "id=" + id + "&passkey=" + passkey);
                    var publishDate    = DateTime.ParseExact(item.Value <string>("added"), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                    var dlVolumeFactor = item.Value <int>("is_freeleech") == 1 ? 0 : 1;

                    var release = new ReleaseInfo
                    {
                        Title                = title,
                        Link                 = link,
                        Details              = details,
                        Guid                 = details,
                        Category             = MapTrackerCatToNewznab(item.Value <string>("category")),
                        PublishDate          = publishDate,
                        Size                 = item.Value <long>("size"),
                        Grabs                = item.Value <long>("times_completed"),
                        Files                = item.Value <long>("numfiles"),
                        Seeders              = item.Value <int>("seeders"),
                        Peers                = item.Value <int>("leechers") + item.Value <int>("seeders"),
                        Imdb                 = ParseUtil.GetImdbID(item.Value <string>("imdbid")),
                        MinimumRatio         = 1,
                        MinimumSeedTime      = 0,
                        DownloadVolumeFactor = dlVolumeFactor,
                        UploadVolumeFactor   = 1
                    };

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.ContentString, ex);
            }

            return(releases);
        }
Esempio n. 13
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchString = query.GetQueryString();
            var searchUrl    = SearchUrl;

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                searchUrl += "&search=" + WebUtilityHelpers.UrlEncode(searchString, Encoding);
            }
            string.Format(SearchUrl, WebUtilityHelpers.UrlEncode(searchString, Encoding));

            var cats = MapTorznabCapsToTrackers(query);

            if (cats.Count > 0)
            {
                foreach (var cat in cats)
                {
                    searchUrl += "&c" + cat + "=1";
                }
            }

            var response = await RequestStringWithCookies(searchUrl);

            try
            {
                CQ dom = response.Content;

                CQ qRows = dom[".browse > div > div"];

                foreach (var row in qRows)
                {
                    var release = new ReleaseInfo();

                    var qRow = row.Cq();

                    var debug = qRow.Html();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800; // 48 hours

                    var qTitle     = qRow.Find(".bTitle");
                    var titleParts = qTitle.Text().Split('/');
                    if (titleParts.Length >= 2)
                    {
                        release.Title = titleParts[1].Trim();
                    }
                    else
                    {
                        release.Title = titleParts[0].Trim();
                    }

                    var qDetailsLink = qTitle.Find("a[href^=\"details.php\"]");
                    release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href"));
                    release.Link     = new Uri(SiteLink + qRow.Find("a[href^=\"download.php\"]").Attr("href"));
                    release.Guid     = release.Link;

                    var dateString = qRow.Find("div:last-child").Text().Trim();
                    var pattern    = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}";
                    var match      = Regex.Match(dateString, pattern);
                    if (match.Success)
                    {
                        release.PublishDate = DateTime.ParseExact(match.Value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                    }

                    var sizeStr = qRow.Find(".bSize").Text();
                    release.Size    = ReleaseInfo.GetBytes(sizeStr);
                    release.Seeders = ParseUtil.CoerceInt(qRow.Find(".bUping").Text().Trim());
                    release.Peers   = release.Seeders + ParseUtil.CoerceInt(qRow.Find(".bDowning").Text().Trim());

                    var files = qRow.Find("div.bFiles").Get(0).LastChild.ToString();
                    release.Files = ParseUtil.CoerceInt(files);

                    var grabs = qRow.Find("div.bFinish").Get(0).LastChild.ToString();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (qRow.Find("img[src=\"/pic/free.jpg\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    if (qRow.Find("img[src=\"/pic/triple.jpg\"]").Length >= 1)
                    {
                        release.UploadVolumeFactor = 3;
                    }
                    else if (qRow.Find("img[src=\"/pic/double.jpg\"]").Length >= 1)
                    {
                        release.UploadVolumeFactor = 2;
                    }
                    else
                    {
                        release.UploadVolumeFactor = 1;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }

            return(releases);
        }
Esempio n. 14
0
        protected override bool ReleaseInfoPostParse(ReleaseInfo release, JObject torrent, JObject result)
        {
            // override release title
            var groupName    = WebUtility.HtmlDecode((string)result["groupName"]);
            var groupSubName = WebUtility.HtmlDecode((string)result["groupSubName"]);
            var groupYear    = (string)result["groupYear"];
            var title        = new StringBuilder();

            title.Append(groupName);
            if (!string.IsNullOrEmpty(groupSubName))
            {
                title.Append(" " + groupSubName + " ");
            }

            if (!string.IsNullOrEmpty(groupYear) && groupYear != "0")
            {
                title.Append(" [" + groupYear + "]");
            }


            var torrentId = torrent["torrentId"];

            var flags = new List <string>();

            var codec = (string)torrent["codec"];

            if (!string.IsNullOrEmpty(codec))
            {
                flags.Add(codec);
            }

            var source = (string)torrent["source"];

            if (!string.IsNullOrEmpty(source))
            {
                flags.Add(source);
            }

            var resolution = (string)torrent["resolution"];

            if (!string.IsNullOrEmpty(resolution))
            {
                flags.Add(resolution);
            }

            var container = (string)torrent["container"];

            if (!string.IsNullOrEmpty(container))
            {
                flags.Add(container);
            }

            var processing = (string)torrent["processing"];

            if (!string.IsNullOrEmpty(processing))
            {
                flags.Add(processing);
            }

            if (flags.Count > 0)
            {
                title.Append(" " + string.Join(" / ", flags));
            }

            release.Title = title.ToString();
            switch ((string)torrent["freeType"])
            {
            case "11":
                release.DownloadVolumeFactor = 0.75;
                break;

            case "12":
                release.DownloadVolumeFactor = 0.5;
                break;

            case "13":
                release.DownloadVolumeFactor = 0.25;
                break;

            case "1":
                release.DownloadVolumeFactor = 0;
                break;

            case "2":
                release.DownloadVolumeFactor = 0;
                release.UploadVolumeFactor   = 0;
                break;
            }

            var isPersonalFreeleech = (bool?)torrent["isPersonalFreeleech"];

            if (isPersonalFreeleech != null && isPersonalFreeleech == true)
            {
                release.DownloadVolumeFactor = 0;
            }

            var imdbID = (string)result["imdbId"];

            if (!string.IsNullOrEmpty(imdbID))
            {
                release.Imdb = ParseUtil.GetImdbID(imdbID);
            }

            release.MinimumRatio    = 1;
            release.MinimumSeedTime = 172800; // 48 hours
                                              // tag each results with Movie cats.
            release.Category = new List <int> {
                TorznabCatType.Movies.ID
            };
            return(true);
        }
Esempio n. 15
0
        List <ReleaseInfo> parseTorrents(WebClientStringResult results, String seasonep, TorznabQuery query, int already_founded)
        {
            var releases = new List <ReleaseInfo>();

            try
            {
                CQ dom = results.Content;

                ReleaseInfo release;
                var         rows = dom[".box_torrent_all"].Find(".box_torrent");

                // Check torrents only till we reach the query Limit
                for (int i = 0; (i < rows.Length && (already_founded + releases.Count) < query.Limit); i++)
                {
                    CQ qRow = rows[i].Cq();

                    var key = dom["link[rel=alternate]"].First().Attr("href").Split('=').Last();

                    release = new ReleaseInfo();
                    var torrentTxt = qRow.Find(".torrent_txt, .torrent_txt2").Find("a").Get(0);
                    //if (torrentTxt == null) continue;
                    release.Title       = torrentTxt.GetAttribute("title");
                    release.Description = qRow.Find("span").Get(0).GetAttribute("title") + " " + qRow.Find("a.infolink").Text();

                    release.MinimumRatio         = 1;
                    release.MinimumSeedTime      = 172800;
                    release.DownloadVolumeFactor = 0;
                    release.UploadVolumeFactor   = 1;

                    string downloadLink = SiteLink + torrentTxt.GetAttribute("href");
                    string downloadId   = downloadLink.Substring(downloadLink.IndexOf("&id=") + 4);

                    release.Link     = new Uri(SiteLink.ToString() + "torrents.php?action=download&id=" + downloadId + "&key=" + key);
                    release.Comments = new Uri(SiteLink.ToString() + "torrents.php?action=details&id=" + downloadId);
                    release.Guid     = new Uri(release.Comments.ToString() + "#comments");;
                    release.Seeders  = ParseUtil.CoerceInt(qRow.Find(".box_s2").Find("a").First().Text());
                    release.Peers    = ParseUtil.CoerceInt(qRow.Find(".box_l2").Find("a").First().Text()) + release.Seeders;
                    var imdblink = qRow.Find("a[href*=\".imdb.com/title\"]").Attr("href");
                    release.Imdb = ParseUtil.GetLongFromString(imdblink);
                    var banner = qRow.Find("img.infobar_ico").Attr("onmouseover");
                    if (banner != null)
                    {
                        Regex BannerRegEx = new Regex(@"mutat\('(.*?)', '", RegexOptions.Compiled);
                        var   BannerMatch = BannerRegEx.Match(banner);
                        var   bannerurl   = BannerMatch.Groups[1].Value;
                        release.BannerUrl = new Uri(bannerurl);
                    }
                    release.PublishDate = DateTime.Parse(qRow.Find(".box_feltoltve2").Get(0).InnerHTML.Replace("<br />", " "), CultureInfo.InvariantCulture);
                    string[] sizeSplit = qRow.Find(".box_meret2").Get(0).InnerText.Split(' ');
                    release.Size = ReleaseInfo.GetBytes(sizeSplit[1].ToLower(), ParseUtil.CoerceFloat(sizeSplit[0]));
                    string catlink = qRow.Find("a:has(img[class='categ_link'])").First().Attr("href");
                    string cat     = ParseUtil.GetArgumentFromQueryString(catlink, "tipus");
                    release.Category = MapTrackerCatToNewznab(cat);

                    /* if the release name not contains the language we add it because it is know from category */
                    if (cat.Contains("hun") && !release.Title.Contains("hun"))
                    {
                        release.Title += ".hun";
                    }

                    if (seasonep == null)
                    {
                        releases.Add(release);
                    }

                    else
                    {
                        if (query.MatchQueryStringAND(release.Title, null, seasonep))
                        {
                            /* For sonnar if the search querry was english the title must be english also so we need to change the Description and Title */
                            var temp = release.Title;

                            // releasedata everithing after Name.S0Xe0X
                            String releasedata = release.Title.Split(new[] { seasonep }, StringSplitOptions.None)[1].Trim();

                            /* if the release name not contains the language we add it because it is know from category */
                            if (cat.Contains("hun") && !releasedata.Contains("hun"))
                            {
                                releasedata += ".hun";
                            }

                            // release description contains [imdb: ****] but we only need the data before it for title
                            String[] description = { release.Description, "" };
                            if (release.Description.Contains("[imdb:"))
                            {
                                description    = release.Description.Split('[');
                                description[1] = "[" + description[1];
                            }

                            release.Title = (description[0].Trim() + "." + seasonep.Trim() + "." + releasedata.Trim('.')).Replace(' ', '.');

                            // if search is done for S0X than we dont want to put . between S0X and E0X
                            Match match = Regex.Match(releasedata, @"^E\d\d?");
                            if (seasonep.Length == 3 && match.Success)
                            {
                                release.Title = (description[0].Trim() + "." + seasonep.Trim() + releasedata.Trim('.')).Replace(' ', '.');
                            }

                            // add back imdb points to the description [imdb: 8.7]
                            release.Description = temp + " " + description[1];
                            release.Description = release.Description.Trim();
                            releases.Add(release);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
Esempio n. 16
0
        public List <ReleaseInfo> ParseResponse(string htmlResponse)
        {
            List <ReleaseInfo> releases = new List <ReleaseInfo>();

            try
            {
                var globalFreeleech = false;
                var parser          = new HtmlParser();
                var document        = parser.Parse(htmlResponse);

                if (document.QuerySelector("div.nicebar > span:contains(\"Personal Freeleech\")") != null)
                {
                    globalFreeleech = true;
                }

                var rows = document.QuerySelectorAll(".torrent_table > tbody > tr[class^='torrent row']");

                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();

                    string title = row.QuerySelector("a[data-src]").GetAttribute("data-src");
                    if (string.IsNullOrEmpty(title) || title == "0")
                    {
                        title = row.QuerySelector("a[data-src]").TextContent;
                        title = Regex.Replace(title, @"[\[\]\/]", "");
                    }
                    else
                    {
                        if (title.Length > 5 && title.Substring(title.Length - 5).Contains("."))
                        {
                            title = title.Remove(title.LastIndexOf("."));
                        }
                    }

                    release.Title       = title;
                    release.Description = release.Title;
                    release.Guid        = new Uri(SiteLink + row.QuerySelector("a[data-src]").GetAttribute("href"));
                    release.Comments    = release.Guid;
                    release.Link        = new Uri(SiteLink + row.QuerySelector("a[href*='action=download']").GetAttribute("href"));
                    release.Category    = new List <int> {
                        TvCategoryParser.ParseTvShowQuality(release.Title)
                    };

                    var timeAnchor = row.QuerySelector("span[class='time']");
                    release.PublishDate     = DateTime.ParseExact(timeAnchor.GetAttribute("title"), "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
                    release.Seeders         = ParseUtil.CoerceInt(timeAnchor.ParentElement.NextElementSibling.NextElementSibling.TextContent.Trim());
                    release.Peers           = ParseUtil.CoerceInt(timeAnchor.ParentElement.NextElementSibling.NextElementSibling.NextElementSibling.TextContent.Trim()) + release.Seeders;
                    release.Size            = ReleaseInfo.GetBytes(timeAnchor.ParentElement.PreviousElementSibling.TextContent);
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    release.Files = ParseUtil.CoerceLong(row.QuerySelector("td > div:contains(\"Files:\")").TextContent.Split(':')[1].Trim());
                    release.Grabs = ParseUtil.CoerceLong(row.QuerySelector("td:nth-last-child(3)").TextContent);

                    if (globalFreeleech)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (row.QuerySelector("img[alt=\"Freeleech\"]") != null)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;


                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(htmlResponse, ex);
            }

            return(releases);
        }
Esempio n. 17
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            // remove operator characters
            var cleanSearchString = Regex.Replace(query.GetQueryString().Trim(), "[ _.+-]+", " ", RegexOptions.Compiled);

            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection
            {
                { "search_in", "name" },
                { "search_mode", "all" },
                { "order_by", "added" },
                { "order_way", "desc" }
            };

            if (!string.IsNullOrWhiteSpace(cleanSearchString))
            {
                queryCollection.Add("query", cleanSearchString);
            }
            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add($"cat[{cat}]", "1");
            }
            searchUrl += "?" + queryCollection.GetQueryString();
            var response = await RequestWithCookiesAndRetryAsync(searchUrl);

            var results = response.ContentString;

            if (!results.Contains("/logout.php?"))
            {
                await ApplyConfiguration(null);

                response = await RequestWithCookiesAndRetryAsync(searchUrl);

                results = response.ContentString;
            }

            try
            {
                var parser = new HtmlParser();
                var dom    = parser.ParseDocument(results);
                var rows   = dom.QuerySelectorAll("table.table-bordered > tbody > tr[class*=\"torrent_row_\"]");
                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 72 * 60 * 60;
                    var qCatLink = row.QuerySelector("a[href^=\"/browse_elastic.php?cat=\"]");
                    var catStr   = qCatLink.GetAttribute("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);
                    var qDetailsLink  = row.QuerySelector("a[href^=\"/details.php?id=\"]");
                    var qDetailsTitle = row.QuerySelector("td:has(a[href^=\"/details.php?id=\"]) b");
                    release.Title = qDetailsTitle.TextContent.Trim();
                    var qDlLink = row.QuerySelector("a[href^=\"/download.php?torrent=\"]");

                    release.Link     = new Uri(SiteLink + qDlLink.GetAttribute("href").TrimStart('/'));
                    release.Comments = new Uri(SiteLink + qDetailsLink.GetAttribute("href").TrimStart('/'));
                    release.Guid     = release.Comments;

                    var qColumns = row.QuerySelectorAll("td");
                    release.Files       = ParseUtil.CoerceInt(qColumns[3].TextContent);
                    release.PublishDate = DateTimeUtil.FromUnknown(qColumns[5].TextContent);
                    release.Size        = ReleaseInfo.GetBytes(qColumns[6].TextContent);
                    release.Grabs       = ParseUtil.CoerceInt(qColumns[7].TextContent.Replace("Times", ""));
                    release.Seeders     = ParseUtil.CoerceInt(qColumns[8].TextContent);
                    release.Peers       = ParseUtil.CoerceInt(qColumns[9].TextContent) + release.Seeders;

                    var qImdb = row.QuerySelector("a[href*=\"www.imdb.com\"]");
                    if (qImdb != null)
                    {
                        var deRefUrl = qImdb.GetAttribute("href");
                        release.Imdb = ParseUtil.GetImdbID(WebUtility.UrlDecode(deRefUrl).Split('/').Last());
                    }

                    release.DownloadVolumeFactor = row.QuerySelector("span.freeleech") != null ? 0 : 1;
                    release.UploadVolumeFactor   = 1;
                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
Esempio n. 18
0
        public virtual IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var torrentInfos = new List <TorrentInfo>();

            if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request");
            }

            if (!indexerResponse.HttpResponse.Headers.ContentType.Contains(HttpAccept.Json.Value))
            {
                throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}");
            }

            var jsonResponse = new HttpResponse <Unit3dResponse>(indexerResponse.HttpResponse);

            foreach (var row in jsonResponse.Resource.Data)
            {
                var details = row.Attributes.DetailsLink;
                var link    = row.Attributes.DownloadLink;

                var release = new TorrentInfo
                {
                    Title                = row.Attributes.Name,
                    DownloadUrl          = link,
                    InfoHash             = row.Id,
                    InfoUrl              = details,
                    Guid                 = details,
                    Categories           = _categories.MapTrackerCatDescToNewznab(row.Attributes.Category),
                    PublishDate          = DateTime.Parse(row.Attributes.CreatedAt, CultureInfo.InvariantCulture),
                    Size                 = row.Attributes.Size,
                    Files                = row.Attributes.Files,
                    Grabs                = row.Attributes.Grabs,
                    Seeders              = row.Attributes.Seeders,
                    ImdbId               = ParseUtil.GetImdbID(row.Attributes.ImdbId).GetValueOrDefault(),
                    TmdbId               = row.Attributes.TmdbId.IsNullOrWhiteSpace() ? 0 : ParseUtil.CoerceInt(row.Attributes.TmdbId),
                    TvdbId               = row.Attributes.TvdbId.IsNullOrWhiteSpace() ? 0 : ParseUtil.CoerceInt(row.Attributes.TvdbId),
                    Peers                = row.Attributes.Leechers + row.Attributes.Seeders,
                    DownloadVolumeFactor = row.Attributes.Freeleech ? 0 : 1,
                    UploadVolumeFactor   = row.Attributes.DoubleUpload ? 2 : 1,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 172800, // 48 hours
                };

                torrentInfos.Add(release);
            }

            // order by date
            return(torrentInfos.OrderByDescending(o => o.PublishDate).ToArray());
        }
Esempio n. 19
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases         = new List <ReleaseInfo>();
            var trackerCats      = MapTorznabCapsToTrackers(query);
            var cat              = (trackerCats.Count == 1 ? trackerCats.ElementAt(0) : "0");
            var episodeSearchUrl = string.Format(SearchUrl, cat, HttpUtility.UrlEncode(query.GetQueryString()));
            var results          = await RequestStringWithCookiesAndRetry(episodeSearchUrl);


            if (results.Content.Contains("No torrents found"))
            {
                return(releases);
            }

            try
            {
                CQ       dom          = results.Content;
                var      rows         = dom[".ctable_content_no_pad > table > tbody > tr"].ToArray();
                DateTime lastDateTime = default(DateTime);
                for (var i = 0; i < rows.Length; i++)
                {
                    var rowA   = rows[i];
                    var rAlign = rowA.Attributes["align"];
                    if (rAlign == "right" || rAlign == "center")
                    {
                        continue;
                    }
                    if (rAlign == "left")
                    {
                        // ex: "Monday, Jun 01, 2015", "Monday, Aug 03, 2015"
                        var dateStr = rowA.Cq().Text().Trim().Replace("Added on ", "");
                        if (dateStr.ToLowerInvariant().Contains("today"))
                        {
                            lastDateTime = DateTime.Now;
                        }
                        else
                        {
                            lastDateTime = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "dddd, MMM dd, yyyy", CultureInfo.InvariantCulture), DateTimeKind.Utc).ToLocalTime();
                        }
                        continue;
                    }
                    if (rowA.ChildElements.Count() < 2)
                    {
                        continue;
                    }

                    var rowB = rows[++i];

                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    release.PublishDate = lastDateTime;

                    var qLink = rowA.ChildElements.ElementAt(1).FirstElementChild.Cq();
                    release.Title       = qLink.Text().Trim();
                    release.Description = release.Title;

                    release.Comments = new Uri(SiteLink + qLink.Attr("href"));
                    release.Guid     = release.Comments;

                    var qDownload = rowB.ChildElements.ElementAt(2).ChildElements.ElementAt(0).Cq();
                    release.Link = new Uri(SiteLink + qDownload.Attr("href"));

                    var sizeStr = rowB.ChildElements.ElementAt(3).Cq().Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(rowB.ChildElements.ElementAt(6).Cq().Text());
                    release.Peers   = ParseUtil.CoerceInt(rowB.ChildElements.ElementAt(6).Cq().Text()) + release.Seeders;

                    var grabs = rowB.Cq().Find("td:nth-child(6)").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    release.DownloadVolumeFactor = 0; // ratioless
                    release.UploadVolumeFactor   = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }
            return(releases);
        }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        //添加-->

        string                  piid    = ddlPayIncome.SelectedItem.Value;
        int                     piidInt = common.IntSafeConvert(piid);
        BG_BudgetConCell        cell    = null;
        List <BG_BudgetConCell> list    = new List <BG_BudgetConCell>();

        if (ckA.Checked)
        {
            //A启用
            cell           = new BG_BudgetConCell();
            cell.PIID      = piidInt;
            cell.BCCName   = common.RemoveUnsafeHtml(tbA.Text.Trim());
            cell.BCCStan   = ParseUtil.ToDecimal(tbCtrA.Text.Trim(), 0);
            cell.BCCUseSta = "启用";
            list.Add(cell);
        }

        if (ckB.Checked)
        {
            //B启用
            cell           = new BG_BudgetConCell();
            cell.PIID      = piidInt;
            cell.BCCName   = common.RemoveUnsafeHtml(tbB.Text.Trim());
            cell.BCCStan   = ParseUtil.ToDecimal(tbCtrB.Text.Trim(), 0);
            cell.BCCUseSta = "启用";
            list.Add(cell);
        }
        if (ckC.Checked)
        {
            //C启用
            cell           = new BG_BudgetConCell();
            cell.PIID      = piidInt;
            cell.BCCName   = common.RemoveUnsafeHtml(tbC.Text.Trim());
            cell.BCCStan   = ParseUtil.ToDecimal(tbCtrC.Text.Trim(), 0);
            cell.BCCUseSta = "启用";
            list.Add(cell);
        }
        if (ckD.Checked)
        {
            //D启用
            cell           = new BG_BudgetConCell();
            cell.PIID      = piidInt;
            cell.BCCName   = common.RemoveUnsafeHtml(tbD.Text.Trim());
            cell.BCCStan   = ParseUtil.ToDecimal(tbCtrD.Text.Trim(), 0);
            cell.BCCUseSta = "启用";
            list.Add(cell);
        }
        if (ckE.Checked)
        {
            //E启用
            cell           = new BG_BudgetConCell();
            cell.PIID      = piidInt;
            cell.BCCName   = common.RemoveUnsafeHtml(tbE.Text.Trim());
            cell.BCCStan   = ParseUtil.ToDecimal(tbCtrE.Text.Trim(), 0);
            cell.BCCUseSta = "启用";
            list.Add(cell);
        }
        if (ckF.Checked)
        {
            //F启用
            cell           = new BG_BudgetConCell();
            cell.PIID      = piidInt;
            cell.BCCName   = common.RemoveUnsafeHtml(tbF.Text.Trim());
            cell.BCCStan   = ParseUtil.ToDecimal(tbCtrF.Text.Trim(), 0);
            cell.BCCUseSta = "启用";
            list.Add(cell);
        }


        //添加项目预算控制记录
        BG_BudgetCon bgBudget = new BG_BudgetCon();

        bgBudget.PIID     = piidInt;
        bgBudget.YNUse    = "启用";
        bgBudget.BCRemark = "备注";
        BGBudgetConManager.AddBudgetCon(bgBudget);

        //批量添加项目预算控制单元记录
        BGBudgetConCellManager.AddBudgetConCell(list);
        Response.Redirect("BudProjectList.aspx", true);
    }
Esempio n. 21
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();
            var qc       = new NameValueCollection
            {
                { "cat", MapTorznabCapsToTrackers(query, true).FirstIfSingleOrDefault("0") }
            };
            var results = new List <WebResult>();
            var search  = new UriBuilder(SearchUrl);

            if (query.IsImdbQuery)
            {
                qc.Add("search", query.ImdbID);
                qc.Add("options", "4"); //Search URL field for IMDB link
                search.Query = qc.GetQueryString();
                results.Add(await RequestWithCookiesAndRetryAsync(search.ToString()));
                qc["Options"] = "1"; //Search Title and Description
                search.Query  = qc.GetQueryString();
                results.Add(await RequestWithCookiesAndRetryAsync(search.ToString()));
            }
            else
            {
                //Site handles empty string on search param. No need to check for IsNullOrEmpty()
                qc.Add("search", query.GetQueryString());
                qc.Add("options", "0"); //Search Title Only
                search.Query = qc.GetQueryString();
                results.Add(await RequestWithCookiesAndRetryAsync(search.ToString()));
            }

            var parser = new HtmlParser();

            foreach (var result in results)
            {
                try
                {
                    var dom = parser.ParseDocument(result.ContentString);
                    foreach (var child in dom.QuerySelectorAll("#needseed"))
                    {
                        child.Remove();
                    }
                    var table = dom.QuerySelector("table[align=center] + br + table > tbody");
                    if (table == null) // No results, so skip this search
                    {
                        continue;
                    }
                    foreach (var row in table.Children.Skip(1))
                    {
                        var release = new ReleaseInfo();
                        var qLink   = row.Children[2].QuerySelector("a");
                        release.MinimumRatio    = 1;
                        release.MinimumSeedTime = 172800; // 48 hours
                        release.Title           = qLink.GetAttribute("title");
                        var detailsLink = new Uri(qLink.GetAttribute("href"));
                        //Skip irrelevant and duplicate entries
                        if (!query.MatchQueryStringAND(release.Title) || releases.Any(r => r.Guid == detailsLink))
                        {
                            continue;
                        }
                        release.Files   = ParseUtil.CoerceLong(row.Children[3].TextContent);
                        release.Grabs   = ParseUtil.CoerceLong(row.Children[7].TextContent);
                        release.Guid    = detailsLink;
                        release.Details = release.Guid;
                        release.Link    = new Uri(SiteLink + row.QuerySelector("a[href^=\"download.php\"]").GetAttribute("href"));
                        var catUrl   = new Uri(SiteLink + row.Children[1].FirstElementChild.GetAttribute("href"));
                        var catQuery = HttpUtility.ParseQueryString(catUrl.Query);
                        var catNum   = catQuery["cat"];
                        release.Category = MapTrackerCatToNewznab(catNum);

                        var dateString = row.Children[5].TextContent.Trim();
                        var pubDate    = DateTime.ParseExact(dateString, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture);
                        release.PublishDate = DateTime.SpecifyKind(pubDate, DateTimeKind.Local);
                        var sizeStr = row.Children[6].TextContent;
                        release.Size    = ReleaseInfo.GetBytes(sizeStr);
                        release.Seeders = ParseUtil.CoerceInt(row.Children[8].TextContent.Trim());
                        release.Peers   = ParseUtil.CoerceInt(row.Children[9].TextContent.Trim()) + release.Seeders;
                        switch (row.GetAttribute("bgcolor"))
                        {
                        case "#DDDDDD":
                            release.DownloadVolumeFactor = 1;
                            release.UploadVolumeFactor   = 2;
                            break;

                        case "#FFFF99":
                            release.DownloadVolumeFactor = 0;
                            release.UploadVolumeFactor   = 1;
                            break;

                        case "#CCFF99":
                            release.DownloadVolumeFactor = 0;
                            release.UploadVolumeFactor   = 2;
                            break;

                        default:
                            release.DownloadVolumeFactor = 1;
                            release.UploadVolumeFactor   = 1;
                            break;
                        }

                        releases.Add(release);
                    }
                }
                catch (Exception ex)
                {
                    OnParseError(result.ContentString, ex);
                }
            }

            return(releases);
        }
Esempio n. 22
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            var searchUrl       = TorrentApiUrl;
            var searchString    = query.GetQueryString();
            var queryCollection = new List <KeyValuePair <string, string> >();

            queryCollection.Add("tpage", "1");
            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("cat[]", cat);
            }

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            searchUrl += "?" + queryCollection.GetQueryString();

            var result = await RequestStringWithCookiesAndRetry(searchUrl, null, TorrentApiUrl);

            if (result.IsRedirect)
            {
                // re-login
                await ApplyConfiguration(null);

                result = await RequestStringWithCookiesAndRetry(searchUrl, null, TorrentApiUrl);
            }

            if (!result.Content.StartsWith("{")) // not JSON => error
            {
                throw new ExceptionWithConfigData(result.Content, configData);
            }
            dynamic json = JsonConvert.DeserializeObject <dynamic>(result.Content);

            try
            {
                dynamic torrents = json["torrents"]; // latest torrents

                if (json["hits"] != null)            // is search result
                {
                    torrents = json.SelectTokens("$.hits[?(@._type == 'torrent')]._source");
                }

                /*
                 * {
                 *  "id":426868,
                 *  "name":"Realease-nameE",
                 *  "size":"2885494332",
                 *  "category":11,
                 *  "added":"2017-09-11T11:36:26.936Z",
                 *  "comments":0,
                 *  "leechers":0,
                 *  "seeders":1,
                 *  "completed":0,
                 *  "poster":true,
                 *  "imdb_id":"3743822",
                 *  "cdu_id":null,
                 *  "steam_id":null,
                 *  "subs":null,
                 *  "language":"en"
                 * },
                 */

                foreach (var torrent in torrents)
                {
                    var release      = new ReleaseInfo();
                    var descriptions = new List <string>();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 0;

                    release.Category = MapTrackerCatToNewznab(torrent.category.ToString());
                    release.Title    = torrent.name.ToString();
                    var torrentID = (long)torrent.id;
                    release.Comments = new Uri(SiteLink + "torrents/" + torrentID);
                    release.Guid     = release.Comments;
                    release.Link     = new Uri(SiteLink + "download/" + torrentID);
                    var date = (DateTime)torrent.added;
                    release.PublishDate = date;
                    release.Size        = ParseUtil.CoerceLong(torrent.size.ToString());
                    release.Seeders     = (int)torrent.seeders;
                    release.Peers       = release.Seeders + (int)torrent.leechers;
                    var imdbid = torrent.imdb_id.ToString();
                    if (!string.IsNullOrEmpty(imdbid))
                    {
                        release.Imdb = ParseUtil.CoerceLong(imdbid);
                    }

                    if ((bool)torrent.poster == true)
                    {
                        if (release.Imdb != null)
                        {
                            release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/imd/l/" + imdbid + ".jpg");
                        }
                        else if (torrent["cdu_id"] != null)
                        {
                            release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/cdu/b/" + torrent["cdu_id"] + "_front.jpg");
                        }
                        else if (torrent["steam_id"] != null)
                        {
                            release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/ste/l/" + torrent["steam_id"] + ".jpg");
                        }
                    }

                    release.UploadVolumeFactor   = 1;
                    release.DownloadVolumeFactor = 1;

                    release.Grabs = (long)torrent.completed;

                    var language = (string)torrent.language;
                    if (!string.IsNullOrEmpty(language))
                    {
                        descriptions.Add("Language: " + language);
                    }
                    else if ((bool?)torrent.polish == true)
                    {
                        descriptions.Add("Language: pl");
                    }

                    if (descriptions.Count > 0)
                    {
                        release.Description = string.Join("<br />\n", descriptions);
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(result.ToString(), ex);
            }

            return(releases);
        }
Esempio n. 23
0
        public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var torrentInfos = new List <ReleaseInfo>();

            var parser = new HtmlParser();
            var doc    = parser.ParseDocument(indexerResponse.Content);
            var rows   = doc.QuerySelectorAll("table.torrent_table > tbody > tr.torrent");

            foreach (var row in rows)
            {
                var qDetailsLink = row.QuerySelector("a.torrent_name");
                var year         = qDetailsLink.NextSibling.TextContent.Replace("[", "").Replace("]", "").Trim();
                var tags         = row.QuerySelector("div.torrent_info").FirstChild.TextContent.Replace(" / ", " ").Trim();
                var title        = $"{qDetailsLink.TextContent} {year} {tags}";
                var description  = row.QuerySelector("div.tags").TextContent.Trim();
                var details      = _settings.BaseUrl + qDetailsLink.GetAttribute("href");
                var torrentId    = qDetailsLink.GetAttribute("href").Split('=').Last();
                var link         = _settings.BaseUrl + "torrents.php?action=download&id=" + torrentId;
                var posterStr    = qDetailsLink.GetAttribute("data-cover");
                var poster       = !string.IsNullOrWhiteSpace(posterStr) ? posterStr : null;

                var files       = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(3)").TextContent);
                var publishDate = DateTimeUtil.FromTimeAgo(row.QuerySelector("td:nth-child(4)").TextContent);
                var size        = ParseUtil.GetBytes(row.QuerySelector("td:nth-child(5)").FirstChild.TextContent);
                var grabs       = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(6)").TextContent);
                var seeders     = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(7)").TextContent);
                var leechers    = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(8)").TextContent);

                var dlVolumeFactor = row.QuerySelector("strong.tl_free") != null ? 0 : 1;

                var cat      = row.QuerySelector("td.cats_col > div").GetAttribute("class").Replace("tooltip cats_", "");
                var category = new List <IndexerCategory>
                {
                    cat switch
                    {
                        "featurefilm" => NewznabStandardCategory.Movies,
                        "shortfilm" => NewznabStandardCategory.Movies,
                        "miniseries" => NewznabStandardCategory.TV,
                        "other" => NewznabStandardCategory.Other,
                        _ => throw new Exception($"Unknown category: {cat}")
                    }
                };

                // TODO: TMDb is also available
                var qImdb = row.QuerySelector("a[href^=\"https://www.imdb.com\"]");
                var imdb  = qImdb != null?ParseUtil.GetImdbID(qImdb.GetAttribute("href").Split('/').Last()) : null;

                var release = new TorrentInfo
                {
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 259200,
                    Description          = description,
                    Title                = title,
                    PublishDate          = publishDate,
                    Categories           = category,
                    DownloadUrl          = link,
                    InfoUrl              = details,
                    PosterUrl            = poster,
                    Guid                 = link,
                    ImdbId               = imdb.GetValueOrDefault(),
                    Seeders              = seeders,
                    Peers                = leechers + seeders,
                    Size                 = size,
                    Grabs                = grabs,
                    Files                = files,
                    DownloadVolumeFactor = dlVolumeFactor,
                    UploadVolumeFactor   = 1
                };

                torrentInfos.Add(release);
            }

            return(torrentInfos.ToArray());
        }
Esempio n. 24
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            List <ReleaseInfo> releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("incldead", "1");
            queryCollection.Add("xtype", "0");
            queryCollection.Add("stype", "0");

            if (query.ImdbID != null)
            {
                queryCollection.Add("search", query.ImdbID);
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }

            searchUrl += "?" + queryCollection.GetQueryString();

            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            try
            {
                CQ dom = results.Content;

                var sideWideFreeLeech = false;
                if (dom.Find("td > b > font[color=\"white\"]:contains(Free Leech)").Length >= 1)
                {
                    sideWideFreeLeech = true;
                }

                var rows = dom["table > tbody > tr[height=36]"];
                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 7 * 24 * 60 * 60;

                    var qRow          = row.Cq();
                    var qCatLink      = qRow.Find("a[href^=?cat]").First();
                    var qDetailsLink  = qRow.Find("a[href^=details.php]").First();
                    var qSeeders      = qRow.Find("td:eq(8)");
                    var qLeechers     = qRow.Find("td:eq(9)");
                    var qDownloadLink = qRow.Find("a[href^=\"download.php\"]").First();
                    var qImdbLink     = qRow.Find("a[href^=/redir.php?url=http://www.imdb.com]");
                    var qSize         = qRow.Find("td:eq(6)");

                    var catStr = qCatLink.Attr("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    release.Link     = new Uri(SiteLink + qDownloadLink.Attr("href"));
                    release.Title    = qDetailsLink.Text().Trim();
                    release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href"));
                    release.Guid     = release.Link;

                    var sizeStr = qSize.Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    if (qImdbLink.Length == 1)
                    {
                        var ImdbId = qImdbLink.Attr("href").Split('/').Last().Substring(2);
                        release.Imdb = ParseUtil.CoerceLong(ImdbId);
                    }

                    release.Seeders = ParseUtil.CoerceInt(qSeeders.Text());
                    release.Peers   = ParseUtil.CoerceInt(qLeechers.Text()) + release.Seeders;

                    var files = qRow.Find("td:nth-child(3)").Text();
                    release.Files = ParseUtil.CoerceInt(files);

                    var grabs = qRow.Find("td:nth-child(8)").Get(0).FirstChild.ToString();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (sideWideFreeLeech || qRow.Find("font[color=\"red\"]:contains(FREE)").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }
                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
Esempio n. 25
0
    public static float CalcTextWidth(TextManager txtmgr, int fromLetter = -1, int toLetter = -1, bool countEOLSpace = false, bool getLastSpace = false)
    {
        float totalWidth = 0, totalWidthSpaceTest = 0, totalMaxWidth = 0, hSpacing = txtmgr.Charset.CharSpacing;

        if (fromLetter == -1)
        {
            fromLetter = 0;
        }
        if (txtmgr.textQueue == null)
        {
            return(0);
        }
        if (txtmgr.textQueue[txtmgr.currentLine] == null)
        {
            return(0);
        }
        if (toLetter == -1)
        {
            toLetter = txtmgr.textQueue[txtmgr.currentLine].Text.Length - 1;
        }
        if (fromLetter > toLetter || fromLetter < 0 || toLetter > txtmgr.textQueue[txtmgr.currentLine].Text.Length)
        {
            return(-1);
        }

        for (int i = fromLetter; i <= toLetter; i++)
        {
            switch (txtmgr.textQueue[txtmgr.currentLine].Text[i])
            {
            case '[':

                string str = ParseCommandInline(txtmgr.textQueue[txtmgr.currentLine].Text, ref i);
                if (str == null)
                {
                    if (txtmgr.Charset.Letters.ContainsKey(txtmgr.textQueue[txtmgr.currentLine].Text[i]))
                    {
                        totalWidth += txtmgr.Charset.Letters[txtmgr.textQueue[txtmgr.currentLine].Text[i]].textureRect.size.x + hSpacing;
                    }
                }
                else if (str.Split(':')[0] == "charspacing")
                {
                    hSpacing = str.Split(':')[1].ToLower() == "default" ? txtmgr.Charset.CharSpacing : ParseUtil.GetFloat(str.Split(':')[1]);
                }
                break;

            case '\r':
            case '\n':
                if (totalMaxWidth < totalWidthSpaceTest - hSpacing)
                {
                    totalMaxWidth = totalWidthSpaceTest - hSpacing;
                }
                totalWidth          = 0;
                totalWidthSpaceTest = 0;
                break;

            default:
                if (txtmgr.Charset.Letters.ContainsKey(txtmgr.textQueue[txtmgr.currentLine].Text[i]))
                {
                    totalWidth += txtmgr.Charset.Letters[txtmgr.textQueue[txtmgr.currentLine].Text[i]].textureRect.size.x + hSpacing;
                    // Do not count end of line spaces
                    if (txtmgr.textQueue[txtmgr.currentLine].Text[i] != ' ' || countEOLSpace)
                    {
                        totalWidthSpaceTest = totalWidth;
                    }
                }
                break;
            }
        }
        if (totalMaxWidth < totalWidthSpaceTest - hSpacing)
        {
            totalMaxWidth = totalWidthSpaceTest - hSpacing;
        }
        return(totalMaxWidth + (getLastSpace ? hSpacing : 0));
    }
Esempio n. 26
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            List <ReleaseInfo> releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection();

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }

            searchUrl += queryCollection.GetQueryString();

            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            await FollowIfRedirect(results);

            try
            {
                CQ  dom  = results.Content;
                var rows = dom["table.torrenttable > tbody > tr.browse_color"];
                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    var qRow = row.Cq();

                    var catStr = row.ChildElements.ElementAt(0).FirstElementChild.GetAttribute("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    var qLink = row.ChildElements.ElementAt(2).FirstChild.Cq();
                    release.Link = new Uri(SiteLink + "/" + qLink.Attr("href"));
                    var torrentId = qLink.Attr("href").Split('=').Last();

                    var descCol      = row.ChildElements.ElementAt(3);
                    var qCommentLink = descCol.FirstChild.Cq();
                    release.Title       = qCommentLink.Text();
                    release.Description = release.Title;
                    release.Comments    = new Uri(SiteLink + "/" + qCommentLink.Attr("href"));
                    release.Guid        = release.Comments;
                    release.Link        = new Uri($"{SiteLink}download.php?torrent={torrentId}");

                    var dateStr = descCol.ChildElements.Last().Cq().Text().Split('|').Last().ToLowerInvariant().Replace("ago.", "").Trim();
                    release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);

                    var sizeStr = row.ChildElements.ElementAt(7).Cq().Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(9).Cq().Text());
                    release.Peers   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(10).Cq().Text()) + release.Seeders;

                    var files = qRow.Find("td:nth-child(6)").Text();
                    release.Files = ParseUtil.CoerceInt(files);

                    var grabs = qRow.Find("td:nth-child(9) > a").Get(0).FirstChild.ToString();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    release.DownloadVolumeFactor = 0; // ratioless
                    release.UploadVolumeFactor   = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
Esempio n. 27
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchUrl    = BrowseUrl;
            var searchString = query.GetQueryString();

            var    cats = MapTorznabCapsToTrackers(query);
            string cat  = "0";

            if (cats.Count == 1)
            {
                cat = cats[0];
            }

            var queryCollection = new NameValueCollection();

            if (query.ImdbID != null)
            {
                queryCollection.Add("search", query.ImdbID);
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            queryCollection.Add("cat", cat);
            queryCollection.Add("searchin", "0");
            queryCollection.Add("sort", "0");

            searchUrl += "?" + queryCollection.GetQueryString();

            var response = await RequestStringWithCookiesAndRetry(searchUrl, null, BrowseUrl);

            var results = response.Content;

            try
            {
                CQ  dom             = results;
                var globalFreeLeech = dom.Find("div.globalFreeLeech").Any();
                var rows            = dom[".torrentrow"];
                foreach (var row in rows)
                {
                    var release    = new ReleaseInfo();
                    var qRow       = row.Cq();
                    var qTitleLink = qRow.Find(".torrenttable:eq(1) a").First();
                    release.Title = qRow.Find(".torrenttable:eq(1) a").Attr("title");

                    if (query.ImdbID == null && !query.MatchQueryStringAND(release.Title))
                    {
                        continue;
                    }

                    release.Description = qRow.Find(".torrenttable:eq(1) > span > font.small").First().Text();

                    release.Guid     = new Uri(SiteLink + qTitleLink.Attr("href"));
                    release.Comments = release.Guid;

                    //22:05:3716/02/2013
                    var dateStr = qRow.Find(".torrenttable:eq(5)").Text().Trim() + " +0200";
                    release.PublishDate = DateTime.ParseExact(dateStr, "H:mm:ssdd/MM/yyyy zzz", CultureInfo.InvariantCulture);

                    var qLink = qRow.Find("a[href^=\"download.php?id=\"]").First();
                    release.Link = new Uri(SiteLink + qLink.Attr("href"));

                    var sizeStr = qRow.Find(".torrenttable:eq(6)").Text().Trim();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qRow.Find(".torrenttable:eq(8)").Text().Trim());
                    release.Peers   = ParseUtil.CoerceInt(qRow.Find(".torrenttable:eq(9)").Text().Trim()) + release.Seeders;

                    var catId = qRow.Find(".torrenttable:eq(0) a").First().Attr("href").Substring(15);
                    release.Category = MapTrackerCatToNewznab(catId);

                    var grabs = qRow.Find(".torrenttable:eq(7)").First().Get(0).FirstChild;
                    release.Grabs = ParseUtil.CoerceLong(catId);

                    if (globalFreeLeech || row.Cq().Find("img[alt=\"FreeLeech\"]").Any())
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    // Skip Romanian releases
                    if (release.Category == TorznabCatType.MoviesForeign.ID && !configData.IncludeRomanianReleases.Value)
                    {
                        continue;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
Esempio n. 28
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday);
            TimeZoneInfo.TransitionTime endTransition   = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday);
            TimeSpan delta = new TimeSpan(1, 0, 0);

            TimeZoneInfo.AdjustmentRule   adjustment  = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition);
            TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment };
            TimeZoneInfo germanyTz = TimeZoneInfo.CreateCustomTimeZone("W. Europe Standard Time", new TimeSpan(1, 0, 0), "(GMT+01:00) W. Europe Standard Time", "W. Europe Standard Time", "W. Europe DST Time", adjustments);

            var releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = BrowseUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("incldead", "1");
            queryCollection.Add("freeleech", "0");
            queryCollection.Add("inclexternal", "0");
            queryCollection.Add("lang", "0");

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }
            searchUrl += "?" + queryCollection.GetQueryString();

            var response = await RequestBytesWithCookies(searchUrl);

            var results = Encoding.UTF8.GetString(response.Content);

            try
            {
                CQ  dom  = results;
                var rows = dom["table.ttable_headinner > tbody > tr.t-row"];

                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 90 * 60;

                    var qRow = row.Cq();

                    var qDetailsLink = qRow.Find("a[href^=torrents-details.php?id=]").First();
                    release.Title = qDetailsLink.Attr("title");

                    if (!query.MatchQueryStringAND(release.Title))
                    {
                        continue;
                    }

                    var qCatLink  = qRow.Find("a[href^=torrents.php?cat=]").First();
                    var qDLLink   = qRow.Find("a[href^=download.php]").First();
                    var qSeeders  = qRow.Find("td:eq(6)");
                    var qLeechers = qRow.Find("td:eq(7)");
                    var qDateStr  = qRow.Find("td:eq(9)").First();
                    var qSize     = qRow.Find("td:eq(4)").First();

                    var catStr = qCatLink.Attr("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    release.Link     = new Uri(SiteLink + qDLLink.Attr("href"));
                    release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href"));
                    release.Guid     = release.Link;

                    var sizeStr = qSize.Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qSeeders.Text());
                    release.Peers   = ParseUtil.CoerceInt(qLeechers.Text()) + release.Seeders;

                    var      dateStr    = qDateStr.Text().Trim();
                    DateTime dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "dd.MM.yy HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);

                    DateTime pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz);
                    release.PublishDate = pubDateUtc.ToLocalTime();

                    var grabs = qRow.Find("td:nth-child(6)").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (qRow.Find("img[src=\"images/free.gif\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
Esempio n. 29
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday);
            TimeZoneInfo.TransitionTime endTransition   = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday);
            TimeSpan delta = new TimeSpan(1, 0, 0);

            TimeZoneInfo.AdjustmentRule   adjustment  = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition);
            TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment };
            TimeZoneInfo germanyTz = TimeZoneInfo.CreateCustomTimeZone("W. Europe Standard Time", new TimeSpan(1, 0, 0), "(GMT+01:00) W. Europe Standard Time", "W. Europe Standard Time", "W. Europe DST Time", adjustments);

            var releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = IndexUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("strWebValue", "torrent");
            queryCollection.Add("strWebAction", "search");
            queryCollection.Add("sort", "torrent_added");
            queryCollection.Add("by", "d");
            queryCollection.Add("type", "0");
            queryCollection.Add("do_search", "suchen");
            queryCollection.Add("time", "0");
            queryCollection.Add("details", "title");

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("searchstring", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("dirs" + cat, "1");
            }
            searchUrl += "?" + queryCollection.GetQueryString();

            var response = await RequestBytesWithCookies(searchUrl);

            var results     = Encoding.GetEncoding("iso-8859-1").GetString(response.Content);
            var TitleRegexp = new Regex(@"^return buildTable\('(.*?)',\s+");

            try
            {
                CQ  dom  = results;
                var rows = dom["table.torrenttable > tbody > tr"];

                foreach (var row in rows.Skip(1))
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 0.8;
                    release.MinimumSeedTime = 0;
                    var qRow = row.Cq();

                    var qDetailsLink = qRow.Find("a[href^=index.php?strWebValue=torrent&strWebAction=details]").First();
                    release.Title = TitleRegexp.Match(qDetailsLink.Attr("onmouseover")).Groups[1].Value;

                    var qCatLink  = qRow.Find("a[href^=index.php?strWebValue=torrent&strWebAction=search&dir=]").First();
                    var qDLLink   = qRow.Find("a[href^=index.php?strWebValue=torrent&strWebAction=download&id=]").First();
                    var qSeeders  = qRow.Find("td.column1:eq(3)");
                    var qLeechers = qRow.Find("td.column2:eq(3)");
                    var qDateStr  = qRow.Find("font:has(a)").First();
                    var qSize     = qRow.Find("td.column2[align=center]").First();

                    var catStr = qCatLink.Attr("href").Split('=')[3].Split('#')[0];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    release.Link     = new Uri(SiteLink + qDLLink.Attr("href"));
                    release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href"));
                    release.Guid     = release.Link;

                    var sizeStr = qSize.Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qSeeders.Text());
                    release.Peers   = ParseUtil.CoerceInt(qLeechers.Text()) + release.Seeders;

                    var      dateStr      = qDateStr.Text().Trim();
                    var      dateStrParts = dateStr.Split();
                    DateTime dateGerman;
                    if (dateStrParts[0] == "Heute")
                    {
                        dateGerman = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStrParts[1]);
                    }
                    else if (dateStrParts[0] == "Gestern")
                    {
                        dateGerman = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStrParts[1]) - TimeSpan.FromDays(1);
                    }
                    else
                    {
                        dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStrParts[0] + dateStrParts[1], "dd.MM.yyyyHH:mm", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);
                    }

                    DateTime pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz);
                    release.PublishDate = pubDateUtc.ToLocalTime();

                    var grabs = qRow.Find("td:nth-child(7)").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (qRow.Find("img[src=\"themes/images/freeleech.png\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (qRow.Find("img[src=\"themes/images/DL50.png\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.5;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
Esempio n. 30
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases        = new List <ReleaseInfo>();
            var searchString    = query.GetQueryString();
            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("order_by", "time");
            queryCollection.Add("order_way", "desc");

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("searchstr", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("filter_cat[" + cat + "]", "1");
            }

            searchUrl += "?" + queryCollection.GetQueryString();
            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            if (results.Content.Contains("Din søgning gav intet resultat."))
            {
                return(releases);
            }
            try
            {
                CQ dom = results.Content;

                var rows = dom["#torrent_table > tbody > tr"].ToArray();

                foreach (var row in rows.Skip(1))
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    var qCat   = row.ChildElements.ElementAt(0).ChildElements.ElementAt(0).Cq();
                    var catUrl = qCat.Attr("href");
                    var cat    = catUrl.Substring(catUrl.LastIndexOf('[') + 1).Trim(']');
                    release.Category = MapTrackerCatToNewznab(cat);

                    var qAdded   = row.ChildElements.ElementAt(4).ChildElements.ElementAt(0).Cq();
                    var addedStr = qAdded.Attr("title");
                    release.PublishDate = DateTime.ParseExact(addedStr, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture);

                    var qLink = row.ChildElements.ElementAt(1).ChildElements.ElementAt(2).Cq();
                    release.Title       = qLink.Text().Trim();
                    release.Description = release.Title;

                    release.Comments = new Uri(SiteLink + qLink.Attr("href"));
                    release.Guid     = release.Comments;

                    var qDownload = row.ChildElements.ElementAt(1).ChildElements.ElementAt(1).ChildElements.ElementAt(0).Cq();
                    release.Link = new Uri(SiteLink + qDownload.Attr("href"));

                    var sizeStr = row.ChildElements.ElementAt(5).Cq().Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(6).Cq().Text());
                    release.Peers   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text()) + release.Seeders;

                    var files = row.Cq().Find("td:nth-child(4)").Text();
                    release.Files = ParseUtil.CoerceInt(files);

                    if (row.Cq().Find("img[src=\"/static//common/browse/freeleech.png\"]").Any())
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }