Exemplo n.º 1
0
        private async Task <List <ReleaseInfo> > FollowTrackerRedirection(string url, TrackerUrlDetails details)
        {
            logger.Debug("FollowTrackerRedirection: " + url);
            var results = await RequestStringWithCookies(url);

            var releases = new List <ReleaseInfo>();

            try
            {
                var parser   = new HtmlParser();
                var document = parser.Parse(results.Content);
                var rows     = document.QuerySelectorAll("div.inner-box--item");

                logger.Debug("> Parsing " + rows.Count().ToString() + " releases");

                var serieTitle = document.QuerySelector("div.inner-box--subtitle").TextContent;
                serieTitle = serieTitle.Substring(0, serieTitle.LastIndexOf(','));

                var episodeInfo = document.QuerySelector("div.inner-box--text").TextContent;
                var episodeName = TrimString(episodeInfo, '(', ')');

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

                        release.Category = new int[] { TorznabCatType.TV.ID };

                        var detailsInfo    = row.QuerySelector("div.inner-box--desc").TextContent;
                        var releaseDetails = parseReleaseDetailsRegex.Match(detailsInfo);
                        if (releaseDetails == null)
                        {
                            throw new FormatException("Failed to map release details string: " + detailsInfo);
                        }

                        /*
                         * For supported qualities see:
                         *  - TvCategoryParser.cs
                         *  - https://github.com/SickRage/SickRage/wiki/Quality-Settings#quality-names-to-recognize-the-quality-of-a-file
                         */
                        var quality = releaseDetails.Groups["quality"].Value.Trim();
                        // Adapt shitty quality format for common algorythms
                        quality = Regex.Replace(quality, "-Rip", "Rip", RegexOptions.IgnoreCase);
                        quality = Regex.Replace(quality, "WEB-DLRip", "WEBDL", RegexOptions.IgnoreCase);
                        quality = Regex.Replace(quality, "WEB-DL", "WEBDL", RegexOptions.IgnoreCase);
                        quality = Regex.Replace(quality, "HDTVRip", "HDTV", RegexOptions.IgnoreCase);
                        // Fix forgotten p-Progressive suffix in resolution index
                        quality = Regex.Replace(quality, "1080 ", "1080p ", RegexOptions.IgnoreCase);
                        quality = Regex.Replace(quality, "720 ", "720p ", RegexOptions.IgnoreCase);

                        var techComponents = new string[] {
                            "rus", quality
                        };
                        var techInfo = string.Join(" ", techComponents.Where(s => !string.IsNullOrEmpty(s)));

                        // Ru title: downloadLink.TextContent.Replace("\n", "");
                        // En title should be manually constructed.
                        var titleComponents = new string[] {
                            serieTitle, details.GetEpisodeString(), episodeName, techInfo
                        };
                        release.Title = string.Join(" - ", titleComponents.Where(s => !string.IsNullOrEmpty(s)));

                        var downloadLink = row.QuerySelector("div.inner-box--link > a");
                        release.Link = new Uri(downloadLink.GetAttribute("href"));
                        release.Guid = release.Link;

                        var sizeString = releaseDetails.Groups["size"].Value.ToUpper();
                        sizeString   = sizeString.Replace("ТБ", "TB"); // untested
                        sizeString   = sizeString.Replace("ГБ", "GB");
                        sizeString   = sizeString.Replace("МБ", "MB");
                        sizeString   = sizeString.Replace("КБ", "KB"); // untested
                        release.Size = ReleaseInfo.GetBytes(sizeString);

                        logger.Debug("> Add: " + release.Title);
                        releases.Add(release);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(string.Format("{0}: Error while parsing row '{1}':\n\n{2}", ID, row.OuterHtml, ex));
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
Exemplo n.º 2
0
        private async Task <List <ReleaseInfo> > FollowTrackerRedirection(string url, TrackerUrlDetails details)
        {
            logger.Info("FollowTrackerRedirection: " + url);
            var results = await RequestStringWithCookies(url);

            var releases = new List <ReleaseInfo>();

            try
            {
                var parser   = new HtmlParser();
                var document = parser.Parse(results.Content);
                var rows     = document.QuerySelectorAll("div.inner-box--item");

                logger.Info("> Parsing " + rows.Count().ToString() + " releases");

                var serieTitle = document.QuerySelector("div.inner-box--subtitle").TextContent;
                serieTitle = serieTitle.Substring(0, serieTitle.LastIndexOf(','));

                var episodeInfo = document.QuerySelector("div.inner-box--text").TextContent;
                var episodeName = TrimString(episodeInfo, '(', ')');

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

                        release.Category = new int[] { TorznabCatType.TV.ID };

                        var detailsInfo    = row.QuerySelector("div.inner-box--desc").TextContent;
                        var releaseDetails = parseReleaseDetailsRegex.Match(detailsInfo);
                        if (releaseDetails == null)
                        {
                            throw new FormatException("Failed to map release details string: " + detailsInfo);
                        }

                        // Ru title: downloadLink.TextContent.Replace("\n", "");
                        // En title should be manually constructed.
                        var titleComponents = new string[] {
                            serieTitle, details.GetEpisodeString(), episodeName, releaseDetails.Groups["quality"].Value
                        };
                        release.Title = string.Join(" - ", titleComponents.Where(s => !string.IsNullOrEmpty(s)));

                        var downloadLink = row.QuerySelector("div.inner-box--link > a");
                        release.Link = new Uri(downloadLink.GetAttribute("href"));
                        release.Guid = release.Link;

                        var sizeString = releaseDetails.Groups["size"].Value;
                        sizeString   = sizeString.Replace("ТБ", "TB"); // untested
                        sizeString   = sizeString.Replace("ГБ", "GB");
                        sizeString   = sizeString.Replace("МБ", "MB");
                        sizeString   = sizeString.Replace("КБ", "KB"); // untested
                        release.Size = ReleaseInfo.GetBytes(sizeString);

                        logger.Info("> Add: " + release.Title);
                        releases.Add(release);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(string.Format("{0}: Error while parsing row '{1}':\n\n{2}", ID, row.OuterHtml, ex));
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }