Example #1
0
        // ex: " 3.5  gb   "
        public static long GetBytes(string str)
        {
            var valStr = new string(str.Where(c => char.IsDigit(c) || c == '.').ToArray());
            var unit   = new string(str.Where(char.IsLetter).ToArray());
            var val    = ParseUtil.CoerceFloat(valStr);

            return(GetBytes(unit, val));
        }
Example #2
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();
            var results  = await PostDataWithCookiesAndRetry(SearchUrl, GetSearchFormData(query.GetQueryString()));

            try
            {
                CQ dom = results.Content;

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

                foreach (var row in rows)
                {
                    CQ qRow = row.Cq();

                    release = new ReleaseInfo();
                    var torrentTxt = qRow.Find(".torrent_txt").Find("a").Get(0);
                    if (torrentTxt == null)
                    {
                        continue;
                    }
                    release.Title                = torrentTxt.GetAttribute("title");
                    release.Description          = release.Title;
                    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);
                    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;
                    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 cat = qRow.Find("img[class='categ_link']").First().Attr("title").Trim();
                    release.Category = MapTrackerCatToNewznab(cat);

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


            return(releases.ToArray());
        }
Example #3
0
        // ex: " 3.5  gb   " -> "3758096384" , "3,5GB" -> "3758096384" ,  "296,98 MB" -> "311406100.48" , "1.018,29 MB" -> "1067754455.04"
        // ex:  "1.018.29mb" -> "1067754455.04" , "-" -> "0" , "---" -> "0"
        public static long GetBytes(string str)
        {
            var valStr = new string(str.Where(c => char.IsDigit(c) || c == '.' || c == ',').ToArray());

            valStr = (valStr.Length == 0) ? "0" : valStr.Replace(",", ".");
            if (valStr.Count(c => c == '.') > 1)
            {
                var lastOcc = valStr.LastIndexOf('.');
                valStr = valStr.Substring(0, lastOcc).Replace(".", string.Empty) + valStr.Substring(lastOcc);
            }
            var unit = new string(str.Where(char.IsLetter).ToArray());
            var val  = ParseUtil.CoerceFloat(valStr);

            return(GetBytes(unit, val));
        }
Example #4
0
        List <ReleaseInfo> parseTorrents(WebClientStringResult results, String seasonep, TorznabQuery query, int already_founded, int limit)
        {
            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) < limit)); i++)
                {
                    try
                    {
                        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 (FormatException ex)
                    {
                        logger.Error("Problem of parsing Torrent:" + rows[i].InnerHTML);
                        logger.Error("Exception was the following:" + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
Example #5
0
        private List <ReleaseInfo> ParseTorrents(WebResult results, string episodeString, TorznabQuery query,
                                                 int alreadyFound, int limit, int previouslyParsedOnPage)
        {
            var releases = new List <ReleaseInfo>();

            try
            {
                var parser = new HtmlParser();
                var dom    = parser.ParseDocument(results.ContentString);
                var rows   = dom.QuerySelectorAll(".box_torrent").Skip(previouslyParsedOnPage).Take(limit - alreadyFound);

                var key = ParseUtil.GetArgumentFromQueryString(
                    dom.QuerySelector("link[rel=alternate]").GetAttribute("href"), "key");
                // Check torrents only till we reach the query Limit
                foreach (var row in rows)
                {
                    try
                    {
                        var torrentTxt = row.QuerySelector(".torrent_txt, .torrent_txt2").QuerySelector("a");
                        //if (torrentTxt == null) continue;
                        var infoLink = row.QuerySelector("a.infolink");
                        var imdbId   = ParseUtil.GetLongFromString(infoLink?.GetAttribute("href"));
                        var desc     = row.QuerySelector("span")?.GetAttribute("title") + " " +
                                       infoLink?.TextContent;
                        var torrentLink = SiteLink + torrentTxt.GetAttribute("href");
                        var downloadId  = ParseUtil.GetArgumentFromQueryString(torrentLink, "id");

                        //Build site links
                        var baseLink     = SiteLink + "torrents.php?action=details&id=" + downloadId;
                        var downloadLink = SiteLink + "torrents.php?action=download&id=" + downloadId;
                        var commentsUri  = new Uri(baseLink + "#comments");
                        var guidUri      = new Uri(baseLink);
                        var linkUri      = new Uri(QueryHelpers.AddQueryString(downloadLink, "key", key));

                        var seeders     = ParseUtil.CoerceInt(row.QuerySelector(".box_s2 a").TextContent);
                        var leechers    = ParseUtil.CoerceInt(row.QuerySelector(".box_l2 a").TextContent);
                        var publishDate = DateTime.Parse(
                            row.QuerySelector(".box_feltoltve2").InnerHtml.Replace("<br>", " "),
                            CultureInfo.InvariantCulture);
                        var sizeSplit = row.QuerySelector(".box_meret2").TextContent.Split(' ');
                        var size      = ReleaseInfo.GetBytes(sizeSplit[1].ToLower(), ParseUtil.CoerceFloat(sizeSplit[0]));
                        var catLink   = row.QuerySelector("a:has(img[class='categ_link'])").GetAttribute("href");
                        var cat       = ParseUtil.GetArgumentFromQueryString(catLink, "tipus");
                        var title     = torrentTxt.GetAttribute("title");
                        // if the release name does not contain the language we add from the category
                        if (cat.Contains("hun") && !title.ToLower().Contains("hun"))
                        {
                            title += ".hun";
                        }

                        // Minimum seed time is 48 hours + 24 minutes (.4 hours) per GB of torrent size if downloaded in full.
                        // Or a 1.0 ratio on the torrent
                        var seedTime = TimeSpan.FromHours(48) +
                                       TimeSpan.FromMinutes(24 * ReleaseInfo.GigabytesFromBytes(size).Value);

                        var release = new ReleaseInfo
                        {
                            Title                = title,
                            Description          = desc.Trim(),
                            MinimumRatio         = 1,
                            MinimumSeedTime      = (long)seedTime.TotalSeconds,
                            DownloadVolumeFactor = 0,
                            UploadVolumeFactor   = 1,
                            Link        = linkUri,
                            Comments    = commentsUri,
                            Guid        = guidUri,
                            Seeders     = seeders,
                            Peers       = leechers + seeders,
                            Imdb        = imdbId,
                            PublishDate = publishDate,
                            Size        = size,
                            Category    = MapTrackerCatToNewznab(cat)
                        };
                        var banner = row.QuerySelector("img.infobar_ico")?.GetAttribute("onmouseover");
                        if (banner != null)
                        {
                            // static call to Regex.Match caches the pattern, so we aren't recompiling every loop.
                            var bannerMatch = Regex.Match(banner, @"mutat\('(.*?)', '", RegexOptions.Compiled);
                            release.BannerUrl = new Uri(bannerMatch.Groups[1].Value);
                        }

                        //TODO there is room for improvement here.
                        if (episodeString != null &&
                            query.MatchQueryStringAND(release.Title, queryStringOverride: episodeString) &&
                            !query.IsImdbQuery)
                        {
                            // For Sonarr if the search query was english the title must be english also
                            // The description holds the alternate language name
                            // so we need to swap title and description names
                            var tempTitle = release.Title;

                            // releaseData everything after Name.S0Xe0X
                            var releaseIndex = tempTitle.IndexOf(episodeString, StringComparison.OrdinalIgnoreCase) +
                                               episodeString.Length;
                            var releaseData = tempTitle.Substring(releaseIndex).Trim();

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

                            var match = Regex.Match(releaseData, @"^E\d\d?");
                            // if search is done for S0X than we don't want to put . between S0X and E0X
                            var episodeSeparator = episodeString.Length == 3 && match.Success ? null : ".";
                            release.Title =
                                (description[0].Trim() + "." + episodeString.Trim() + episodeSeparator +
                                 releaseData.Trim('.')).Replace(' ', '.');

                            // add back imdb points to the description [imdb: 8.7]
                            release.Description = tempTitle + " " + description[1];
                            release.Description = release.Description.Trim();
                        }

                        releases.Add(release);
                    }
                    catch (FormatException ex)
                    {
                        logger.Error("Problem of parsing Torrent:" + row.InnerHtml);
                        logger.Error("Exception was the following:" + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.ContentString, ex);
            }

            return(releases);
        }
Example #6
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchString = query.GetQueryString();
            var pairs        = new List <KeyValuePair <string, string> >();

            pairs.Add(new KeyValuePair <string, string>("nyit_sorozat_resz", "true"));
            pairs.Add(new KeyValuePair <string, string>("miben", "name"));
            pairs.Add(new KeyValuePair <string, string>("tipus", "kivalasztottak_kozott"));
            pairs.Add(new KeyValuePair <string, string>("submit.x", "1"));
            pairs.Add(new KeyValuePair <string, string>("submit.y", "1"));
            pairs.Add(new KeyValuePair <string, string>("submit", "Ok"));
            pairs.Add(new KeyValuePair <string, string>("mire", searchString));

            var cats = MapTorznabCapsToTrackers(query);

            if (cats.Count == 0)
            {
                cats = GetAllTrackerCategories();
            }

            foreach (var lcat in LanguageCats)
            {
                if (!configData.Hungarian.Value)
                {
                    cats.Remove(lcat + "_hun");
                }
                if (!configData.English.Value)
                {
                    cats.Remove(lcat);
                }
            }

            foreach (var cat in cats)
            {
                pairs.Add(new KeyValuePair <string, string>("kivalasztott_tipus[]", cat));
            }

            var results = await PostDataWithCookiesAndRetry(SearchUrl, pairs);

            try
            {
                CQ dom = results.Content;

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

                foreach (var row in rows)
                {
                    CQ qRow = row.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("div.siterank").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);

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

            return(releases);
        }
Example #7
0
        protected async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query, String seasonep)
        {
            var releases     = new List <ReleaseInfo>();
            var searchString = query.GetQueryString();
            var pairs        = new List <KeyValuePair <string, string> >();

            if (seasonep != null)
            {
                searchString = query.SanitizedSearchTerm;
            }

            pairs.Add(new KeyValuePair <string, string>("nyit_sorozat_resz", "true"));
            pairs.Add(new KeyValuePair <string, string>("miben", "name"));
            pairs.Add(new KeyValuePair <string, string>("tipus", "kivalasztottak_kozott"));
            pairs.Add(new KeyValuePair <string, string>("submit.x", "1"));
            pairs.Add(new KeyValuePair <string, string>("submit.y", "1"));
            pairs.Add(new KeyValuePair <string, string>("submit", "Ok"));
            pairs.Add(new KeyValuePair <string, string>("mire", searchString));

            var cats = MapTorznabCapsToTrackers(query);

            if (cats.Count == 0)
            {
                cats = GetAllTrackerCategories();
            }

            foreach (var lcat in LanguageCats)
            {
                if (!configData.Hungarian.Value)
                {
                    cats.Remove(lcat + "_hun");
                }
                if (!configData.English.Value)
                {
                    cats.Remove(lcat);
                }
            }

            foreach (var cat in cats)
            {
                pairs.Add(new KeyValuePair <string, string>("kivalasztott_tipus[]", cat));
            }

            var results = await PostDataWithCookiesAndRetry(SearchUrl, pairs);

            try
            {
                CQ dom = results.Content;

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

                foreach (var row in rows)
                {
                    CQ qRow = row.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("div.siterank").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 (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);
        }
Example #8
0
        // private readonly int CAT_OTHER = 3;

        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases       = new List <ReleaseInfo>();
            var searchString   = query.GetQueryString();
            var searchCategory = CAT_ANY;

            if (query.Categories.Contains(TorznabCatType.TV.ID) ||
                query.Categories.Contains(TorznabCatType.TVHD.ID) ||
                query.Categories.Contains(TorznabCatType.TVSD.ID))
            {
                searchCategory = CAT_TV_SERIES;
            }

            if ((searchCategory == CAT_ANY) &&
                (query.Categories.Contains(TorznabCatType.Movies.ID) ||
                 query.Categories.Contains(TorznabCatType.MoviesForeign.ID) ||
                 query.Categories.Contains(TorznabCatType.MoviesHD.ID) ||
                 query.Categories.Contains(TorznabCatType.MoviesSD.ID)))
            {
                searchCategory = CAT_FOREIGN_MOVIE;
            }

            if ((searchCategory == CAT_ANY) &&
                (query.Categories.Contains(TorznabCatType.TVAnime.ID)))
            {
                searchCategory = CAT_ANIME;
            }

            if ((searchCategory == CAT_ANY) &&
                (query.Categories.Contains(TorznabCatType.Books.ID)))
            {
                searchCategory = CAT_BOOKS;
            }

            if ((searchCategory == CAT_ANY) &&
                (query.Categories.Contains(TorznabCatType.Audio.ID) ||
                 query.Categories.Contains(TorznabCatType.AudioLossless.ID) ||
                 query.Categories.Contains(TorznabCatType.AudioMP3.ID)))
            {
                searchCategory = CAT_MUSIC;
            }

            string queryUrl = string.Empty;

            if (string.IsNullOrWhiteSpace(searchString))
            {
                queryUrl = string.Format(BrowseUrl, searchCategory);
            }
            else
            {
                queryUrl = string.Format(SearchUrl, searchCategory, HttpUtility.UrlEncode(searchString.Trim()));
            }

            var results = await RequestStringWithCookiesAndRetry(queryUrl, string.Empty);

            try
            {
                CQ  dom  = results.Content;
                var rows = dom["#index table tr"];
                foreach (var row in rows.Skip(1))
                {
                    var release = new ReleaseInfo();

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

                    var date = StringUtil.StripNonAlphaNumeric(row.Cq().Find("td:eq(0)").Text().Trim()
                                                               .Replace("Янв", "01")
                                                               .Replace("Фев", "02")
                                                               .Replace("Мар", "03")
                                                               .Replace("Апр", "04")
                                                               .Replace("Май", "05")
                                                               .Replace("Июн", "06")
                                                               .Replace("Июл", "07")
                                                               .Replace("Авг", "08")
                                                               .Replace("Сен", "09")
                                                               .Replace("Окт", "10")
                                                               .Replace("Ноя", "11")
                                                               .Replace("Дек", "12"));

                    release.PublishDate = DateTime.ParseExact(date, "ddMMyy", CultureInfo.InvariantCulture);

                    var hasTorrent = row.Cq().Find("td:eq(1) a").Length == 3;
                    var titleIndex = 1;
                    if (hasTorrent)
                    {
                        titleIndex++;
                    }

                    release.Title = row.Cq().Find("td:eq(" + titleIndex + ")").Text().Trim();
                    if (configData.StripRussian.Value)
                    {
                        var split = release.Title.IndexOf('/');
                        if (split > -1)
                        {
                            release.Title = release.Title.Substring(split + 1).Trim();
                        }
                    }

                    release.Description = release.Title;

                    var hasComments = row.Cq().Find("td:eq(2) img").Length > 0;
                    var sizeCol     = 2;

                    if (hasComments)
                    {
                        sizeCol++;
                    }

                    var      sizeStr   = StringUtil.StripRegex(row.Cq().Find("td:eq(" + sizeCol + ")").Text(), "[^a-zA-Z0-9\\. -]", " ").Trim();
                    string[] sizeSplit = sizeStr.Split(' ');
                    release.Size = ReleaseInfo.GetBytes(sizeSplit[1].ToLower(), ParseUtil.CoerceFloat(sizeSplit[0]));

                    release.Seeders = ParseUtil.CoerceInt(row.Cq().Find(".green").Text().Trim());
                    release.Peers   = ParseUtil.CoerceInt(row.Cq().Find(".red").Text().Trim()) + release.Seeders;

                    release.Guid     = new Uri(configData.Url.Value + row.Cq().Find("td:eq(1) a:eq(" + titleIndex + ")").Attr("href").Substring(1));
                    release.Comments = release.Guid;

                    if (hasTorrent)
                    {
                        release.Link      = new Uri(row.Cq().Find("td:eq(1) a:eq(0)").Attr("href"));
                        release.MagnetUri = new Uri(row.Cq().Find("td:eq(1) a:eq(1)").Attr("href"));
                    }
                    else
                    {
                        release.MagnetUri = new Uri(row.Cq().Find("td:eq(1) a:eq(0)").Attr("href"));
                    }

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

            return(releases);
        }