Esempio n. 1
0
        public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var torrentInfos = new List <TorrentInfo>();

            var rows = JsonConvert.DeserializeObject <dynamic>(indexerResponse.Content);

            foreach (var row in rows)
            {
                var title = (string)row.name;

                var torrentId          = (long)row.t;
                var details            = new Uri(_settings.BaseUrl + "details.php?id=" + torrentId);
                var seeders            = (int)row.seeders;
                var imdbId             = (string)row["imdb-id"];
                var downloadMultiplier = (double?)row["download-multiplier"] ?? 1;
                var link        = new Uri(_settings.BaseUrl + "download.php/" + torrentId + "/" + torrentId + ".torrent");
                var publishDate = DateTimeUtil.UnixTimestampToDateTime((long)row.ctime).ToLocalTime();
                var imdb        = ParseUtil.GetImdbID(imdbId) ?? 0;

                var release = new TorrentInfo
                {
                    Title                = title,
                    Guid                 = details.AbsoluteUri,
                    DownloadUrl          = link.AbsoluteUri,
                    InfoUrl              = details.AbsoluteUri,
                    PublishDate          = publishDate,
                    Categories           = _categories.MapTrackerCatToNewznab(row.c.ToString()),
                    Size                 = (long)row.size,
                    Files                = (int)row.files,
                    Grabs                = (int)row.completed,
                    Seeders              = seeders,
                    Peers                = seeders + (int)row.leechers,
                    ImdbId               = imdb,
                    DownloadVolumeFactor = downloadMultiplier,
                    UploadVolumeFactor   = 1,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 172800 // 48 hours
                };

                torrentInfos.Add(release);
            }

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

            var queryResponseItems = JsonConvert.DeserializeObject <List <ThePirateBayTorrent> >(indexerResponse.Content);

            // The API returns a single item to represent a state of no results. Avoid returning this result.
            if (queryResponseItems.Count == 1 && queryResponseItems.First().Id == 0)
            {
                return(torrentInfos);
            }

            foreach (var item in queryResponseItems)
            {
                var details     = item.Id == 0 ? null : $"{_settings.BaseUrl}description.php?id={item.Id}";
                var imdbId      = string.IsNullOrEmpty(item.Imdb) ? null : ParseUtil.GetImdbID(item.Imdb);
                var torrentItem = new TorrentInfo
                {
                    Title                = item.Name,
                    Categories           = _categories.MapTrackerCatToNewznab(item.Category.ToString()),
                    Guid                 = details,
                    InfoUrl              = details,
                    InfoHash             = item.InfoHash, // magnet link is auto generated from infohash
                    PublishDate          = DateTimeUtil.UnixTimestampToDateTime(item.Added),
                    Seeders              = item.Seeders,
                    Peers                = item.Seeders + item.Leechers,
                    Size                 = item.Size,
                    Files                = item.NumFiles,
                    DownloadVolumeFactor = 0,
                    UploadVolumeFactor   = 1,
                    ImdbId               = imdbId.GetValueOrDefault()
                };

                if (item.InfoHash != null)
                {
                    torrentItem.MagnetUrl = MagnetLinkBuilder.BuildPublicMagnetLink(item.InfoHash, item.Name);
                }

                torrentInfos.Add(torrentItem);
            }

            return(torrentInfos.ToArray());
        }
Esempio n. 3
0
        public 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 <DanishBytesResponse>(indexerResponse.HttpResponse);

            foreach (var row in jsonResponse.Resource.Torrents)
            {
                var infoUrl = $"{_settings.BaseUrl}torrents/{row.Id}";

                var release = new TorrentInfo
                {
                    Title                = row.Name,
                    InfoUrl              = infoUrl,
                    DownloadUrl          = $"{_settings.BaseUrl}torrent/download/{row.Id}.{jsonResponse.Resource.Rsskey}",
                    Guid                 = infoUrl,
                    PosterUrl            = row.PosterImage,
                    PublishDate          = row.CreatedAt,
                    Categories           = _categories.MapTrackerCatToNewznab(row.CategoryId),
                    Size                 = row.Size,
                    Seeders              = row.Seeders,
                    Peers                = row.Leechers + row.Seeders,
                    Grabs                = row.TimesCompleted,
                    DownloadVolumeFactor = row.Free ? 0 : 1,
                    UploadVolumeFactor   = row.Doubleup ? 2 : 1
                };

                torrentInfos.Add(release);
            }

            // order by date
            return(torrentInfos.OrderByDescending(o => o.PublishDate).ToArray());
        }
        protected override ICollection <IndexerCategory> GetCategory(XElement item)
        {
            var cats    = TryGetMultipleNewznabAttributes(item, "category");
            var results = new List <IndexerCategory>();

            foreach (var cat in cats)
            {
                if (int.TryParse(cat, out var intCategory))
                {
                    var indexerCat = _categories.MapTrackerCatToNewznab(intCategory.ToString()) ?? null;

                    if (indexerCat != null)
                    {
                        results.AddRange(indexerCat);
                    }
                }
            }

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

            var response = JsonConvert.DeserializeObject <MilkieResponse>(indexerResponse.Content);

            var dlQueryParams = new NameValueCollection
            {
                { "key", _settings.ApiKey }
            };

            foreach (var torrent in response.Torrents)
            {
                var torrentUrl  = _settings.BaseUrl + "api/v1/torrents";
                var link        = $"{torrentUrl}/{torrent.Id}/torrent?{dlQueryParams.GetQueryString()}";
                var details     = $"{_settings.BaseUrl}browse/{torrent.Id}";
                var publishDate = DateTimeUtil.FromUnknown(torrent.CreatedAt);

                var release = new TorrentInfo
                {
                    Title                = torrent.ReleaseName,
                    DownloadUrl          = link,
                    InfoUrl              = details,
                    Guid                 = details,
                    PublishDate          = publishDate,
                    Categories           = _categories.MapTrackerCatToNewznab(torrent.Category.ToString()),
                    Size                 = torrent.Size,
                    Seeders              = torrent.Seeders,
                    Peers                = torrent.Seeders + torrent.PartialSeeders + torrent.Leechers,
                    Grabs                = torrent.Downloaded,
                    UploadVolumeFactor   = 1,
                    DownloadVolumeFactor = 0,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 172800 // 48 hours
                };

                torrentInfos.Add(release);
            }

            return(torrentInfos.ToArray());
        }
Esempio n. 6
0
        public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            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 <List <SpeedAppTorrent> >(indexerResponse.HttpResponse);

            return(jsonResponse.Resource.Select(torrent => new TorrentInfo
            {
                Guid = torrent.Id.ToString(),
                Title = torrent.Name,
                Description = torrent.ShortDescription,
                Size = torrent.Size,
                ImdbId = ParseUtil.GetImdbID(torrent.ImdbId).GetValueOrDefault(),
                DownloadUrl = $"{_settings.BaseUrl}/api/torrent/{torrent.Id}/download",
                PosterUrl = torrent.Poster,
                InfoUrl = torrent.Url,
                Grabs = torrent.TimesCompleted,
                PublishDate = torrent.CreatedAt,
                Categories = _categories.MapTrackerCatToNewznab(torrent.Category.Id.ToString()),
                InfoHash = null,
                Seeders = torrent.Seeders,
                Peers = torrent.Leechers + torrent.Seeders,
                MinimumRatio = 1,
                MinimumSeedTime = 172800,
                DownloadVolumeFactor = torrent.DownloadVolumeFactor,
                UploadVolumeFactor = torrent.UploadVolumeFactor,
            }).ToArray());
        }
        public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var results             = new List <ReleaseInfo>();
            var indexerHttpResponse = indexerResponse.HttpResponse;

            switch (indexerHttpResponse.StatusCode)
            {
            case HttpStatusCode.Unauthorized:
                throw new IndexerAuthException("API Key invalid or not authorized");

            case HttpStatusCode.NotFound:
                throw new IndexerException(indexerResponse, "Indexer API call returned NotFound, the Indexer API may have changed.");

            case HttpStatusCode.ServiceUnavailable:
                throw new RequestLimitReachedException(indexerResponse, "Cannot do more than 150 API requests per hour.");

            default:
                if (indexerHttpResponse.StatusCode != HttpStatusCode.OK)
                {
                    throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerHttpResponse.StatusCode);
                }

                break;
            }

            if (indexerHttpResponse.Headers.ContentType != null && indexerHttpResponse.Headers.ContentType.Contains("text/html"))
            {
                throw new IndexerException(indexerResponse, "Indexer responded with html content. Site is likely blocked or unavailable.");
            }

            if (indexerResponse.Content.ContainsIgnoreCase("Call Limit Exceeded"))
            {
                throw new RequestLimitReachedException(indexerResponse, "Cannot do more than 150 API requests per hour.");
            }

            if (indexerResponse.Content == "Query execution was interrupted")
            {
                throw new IndexerException(indexerResponse, "Indexer API returned an internal server error");
            }

            JsonRpcResponse <BroadcastheNetTorrents> jsonResponse = new HttpResponse <JsonRpcResponse <BroadcastheNetTorrents> >(indexerHttpResponse).Resource;

            if (jsonResponse.Error != null || jsonResponse.Result == null)
            {
                throw new IndexerException(indexerResponse, "Indexer API call returned an error [{0}]", jsonResponse.Error);
            }

            if (jsonResponse.Result.Results == 0)
            {
                return(results);
            }

            var protocol = indexerResponse.HttpRequest.Url.Scheme + ":";

            foreach (var torrent in jsonResponse.Result.Torrents.Values)
            {
                var torrentInfo = new TorrentInfo();

                torrentInfo.Guid        = string.Format("BTN-{0}", torrent.TorrentID);
                torrentInfo.Title       = CleanReleaseName(torrent.ReleaseName);
                torrentInfo.Size        = torrent.Size;
                torrentInfo.DownloadUrl = RegexProtocol.Replace(torrent.DownloadURL, protocol);
                torrentInfo.InfoUrl     = string.Format("{0}//broadcasthe.net/torrents.php?id={1}&torrentid={2}", protocol, torrent.GroupID, torrent.TorrentID);

                //torrentInfo.CommentUrl =
                if (torrent.TvdbID.HasValue)
                {
                    torrentInfo.TvdbId = torrent.TvdbID.Value;
                }

                if (torrent.TvrageID.HasValue)
                {
                    torrentInfo.TvRageId = torrent.TvrageID.Value;
                }

                torrentInfo.PublishDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime().AddSeconds(torrent.Time);

                //torrentInfo.MagnetUrl =
                torrentInfo.InfoHash = torrent.InfoHash;
                torrentInfo.Seeders  = torrent.Seeders;
                torrentInfo.Peers    = torrent.Leechers + torrent.Seeders;

                torrentInfo.Origin               = torrent.Origin;
                torrentInfo.Source               = torrent.Source;
                torrentInfo.Container            = torrent.Container;
                torrentInfo.Codec                = torrent.Codec;
                torrentInfo.Resolution           = torrent.Resolution;
                torrentInfo.UploadVolumeFactor   = 1;
                torrentInfo.DownloadVolumeFactor = 0;
                torrentInfo.MinimumRatio         = 1;

                torrentInfo.Categories = _categories.MapTrackerCatToNewznab(torrent.Resolution);

                // Default to TV if category could not be mapped
                if (torrentInfo.Categories == null || !torrentInfo.Categories.Any())
                {
                    torrentInfo.Categories = new List <IndexerCategory> {
                        NewznabStandardCategory.TV
                    };
                }

                results.Add(torrentInfo);
            }

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

            // TODO Deserialize to TorrentSyndikatResponse Type
            var jsonContent = JObject.Parse(indexerResponse.Content);

            foreach (var row in jsonContent.Value <JArray>("rows"))
            {
                var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

                var id      = row.Value <string>("id");
                var details = _settings.BaseUrl + "details.php?id=" + id;
                var seeders = row.Value <int>("seeders");

                var release = new TorrentInfo
                {
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 96 * 60 * 60,
                    DownloadVolumeFactor = 1,
                    UploadVolumeFactor   = 1,
                    Guid        = details,
                    InfoUrl     = details,
                    DownloadUrl = _settings.BaseUrl + "download.php?id=" + id + "&apikey=" + _settings.ApiKey,
                    Title       = row.Value <string>("name"),
                    Categories  = _categories.MapTrackerCatToNewznab(row.Value <int>("category").ToString()),
                    PublishDate = dateTime.AddSeconds(row.Value <long>("added")).ToLocalTime(),
                    Size        = row.Value <long>("size"),
                    Files       = row.Value <int>("numfiles"),
                    Seeders     = seeders,
                    Peers       = seeders + row.Value <int>("leechers"),
                    Grabs       = row.Value <int>("snatched"),
                    ImdbId      = row.Value <int?>("imdbId").GetValueOrDefault(),
                    TvdbId      = row.Value <int?>("tvdbId").GetValueOrDefault(),
                    TmdbId      = row.Value <int?>("tmdbId").GetValueOrDefault()
                };

                var poster = row.Value <string>("poster");
                if (!string.IsNullOrWhiteSpace(poster))
                {
                    release.PosterUrl = _settings.BaseUrl + poster.Substring(1);
                }

                var descriptions = new List <string>();
                var title        = row.Value <string>("title");
                var titleOrigin  = row.Value <string>("title_origin");
                var year         = row.Value <int?>("year");
                var pid          = row.Value <int?>("pid");
                var releaseType  = row.Value <string>("release_type");
                var tags         = row.Value <JArray>("tags");
                var genres       = row.Value <JArray>("genres");

                if (!string.IsNullOrWhiteSpace(title))
                {
                    descriptions.Add("Title: " + title);
                }

                if (!string.IsNullOrWhiteSpace(titleOrigin))
                {
                    descriptions.Add("Original Title: " + titleOrigin);
                }

                if (year > 0)
                {
                    descriptions.Add("Year: " + year);
                }

                if (pid > 0)
                {
                    descriptions.Add("Product-Link: " + _settings.BaseUrl + "product.php?pid=" + pid);
                }

                if (genres != null && genres.Any())
                {
                    descriptions.Add("Genres: " + string.Join(", ", genres));
                }

                if (tags != null && tags.Any())
                {
                    descriptions.Add("Tags: " + string.Join(", ", tags));
                }

                if (!string.IsNullOrWhiteSpace(releaseType))
                {
                    descriptions.Add("Release Type: " + releaseType);
                }

                if (descriptions.Any())
                {
                    release.Description = string.Join(Environment.NewLine, descriptions);
                }

                torrentInfos.Add(release);
            }

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

            var rowsSelector = "table#tor-tbl > tbody > tr";

            var searchResultParser   = new HtmlParser();
            var searchResultDocument = searchResultParser.ParseDocument(indexerResponse.Content);
            var rows = searchResultDocument.QuerySelectorAll(rowsSelector);

            foreach (var row in rows)
            {
                try
                {
                    var qDownloadLink = row.QuerySelector("a.tr-dl");

                    // Expects moderation
                    if (qDownloadLink == null)
                    {
                        continue;
                    }

                    var qForumLink   = row.QuerySelector("a.f");
                    var qDetailsLink = row.QuerySelector("a.tLink");
                    var qSize        = row.QuerySelector("td:nth-child(6) u");
                    var link         = new Uri(_settings.BaseUrl + "forum/" + qDetailsLink.GetAttribute("href"));
                    var seederString = row.QuerySelector("td:nth-child(7) b").TextContent;
                    var seeders      = string.IsNullOrWhiteSpace(seederString) ? 0 : ParseUtil.CoerceInt(seederString);

                    var timestr = row.QuerySelector("td:nth-child(11) u").TextContent;
                    var forum   = qForumLink;
                    var forumid = forum.GetAttribute("href").Split('=')[1];
                    var title   = _settings.StripRussianLetters
                        ? StripRussianRegex.Replace(qDetailsLink.TextContent, "")
                        : qDetailsLink.TextContent;
                    var size        = ParseUtil.GetBytes(qSize.TextContent);
                    var leechers    = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(8)").TextContent);
                    var grabs       = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(9)").TextContent);
                    var publishDate = DateTimeUtil.UnixTimestampToDateTime(long.Parse(timestr));
                    var release     = new TorrentInfo
                    {
                        MinimumRatio         = 1,
                        MinimumSeedTime      = 0,
                        Title                = title,
                        InfoUrl              = link.AbsoluteUri,
                        Description          = qForumLink.TextContent,
                        DownloadUrl          = link.AbsoluteUri,
                        Guid                 = link.AbsoluteUri,
                        Size                 = size,
                        Seeders              = seeders,
                        Peers                = leechers + seeders,
                        Grabs                = grabs,
                        PublishDate          = publishDate,
                        Categories           = _categories.MapTrackerCatToNewznab(forumid),
                        DownloadVolumeFactor = 1,
                        UploadVolumeFactor   = 1
                    };

                    torrentInfos.Add(release);
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Pornolab: Error while parsing row '{0}':\n\n{1}", row.OuterHtml, ex));
                }
            }

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

            var rowsSelector = ".torrent_table > tbody > tr";

            var searchResultParser   = new HtmlParser();
            var searchResultDocument = searchResultParser.ParseDocument(indexerResponse.Content);
            var rows = searchResultDocument.QuerySelectorAll(rowsSelector);

            var    stickyGroup = false;
            string categoryStr;
            ICollection <IndexerCategory> groupCategory = null;
            string groupTitle = null;

            foreach (var row in rows)
            {
                if (row.ClassList.Contains("torrent"))
                {
                    // garbage rows
                    continue;
                }
                else if (row.ClassList.Contains("group"))
                {
                    stickyGroup = row.ClassList.Contains("sticky");
                    var dispalyname = row.QuerySelector("#displayname");
                    var qCat        = row.QuerySelector("td.cats_col > div");
                    categoryStr = qCat.GetAttribute("title");
                    var qArtistLink = dispalyname.QuerySelector("#groupplatform > a");
                    if (qArtistLink != null)
                    {
                        categoryStr = ParseUtil.GetArgumentFromQueryString(qArtistLink.GetAttribute("href"), "artistname");
                    }

                    groupCategory = _categories.MapTrackerCatToNewznab(categoryStr);

                    var qDetailsLink = dispalyname.QuerySelector("#groupname > a");
                    groupTitle = qDetailsLink.TextContent;
                }
                else if (row.ClassList.Contains("group_torrent"))
                {
                    if (row.QuerySelector("td.edition_info") != null)
                    {
                        continue;
                    }

                    var sizeString = row.QuerySelector("td:nth-child(4)").TextContent;
                    if (string.IsNullOrEmpty(sizeString))
                    {
                        continue;
                    }

                    var qDetailsLink = row.QuerySelector("a[href^=\"torrents.php?id=\"]");
                    var title        = qDetailsLink.TextContent.Replace(", Freeleech!", "").Replace(", Neutral Leech!", "");

                    //if (stickyGroup && (query.ImdbID == null || !NewznabStandardCategory.MovieSearchImdbAvailable) && !query.MatchQueryStringAND(title)) // AND match for sticky releases
                    //{
                    //    continue;
                    //}
                    var qDescription  = qDetailsLink.QuerySelector("span.torrent_info_tags");
                    var qDLLink       = row.QuerySelector("a[href^=\"torrents.php?action=download\"]");
                    var qTime         = row.QuerySelector("span.time");
                    var qGrabs        = row.QuerySelector("td:nth-child(5)");
                    var qSeeders      = row.QuerySelector("td:nth-child(6)");
                    var qLeechers     = row.QuerySelector("td:nth-child(7)");
                    var qFreeLeech    = row.QuerySelector("strong.freeleech_label");
                    var qNeutralLeech = row.QuerySelector("strong.neutralleech_label");
                    var time          = qTime.GetAttribute("title");
                    var link          = _settings.BaseUrl + qDLLink.GetAttribute("href");
                    var seeders       = ParseUtil.CoerceInt(qSeeders.TextContent);
                    var publishDate   = DateTime.SpecifyKind(
                        DateTime.ParseExact(time, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture),
                        DateTimeKind.Unspecified).ToLocalTime();
                    var details  = _settings.BaseUrl + qDetailsLink.GetAttribute("href");
                    var grabs    = ParseUtil.CoerceInt(qGrabs.TextContent);
                    var leechers = ParseUtil.CoerceInt(qLeechers.TextContent);
                    var size     = ParseUtil.GetBytes(sizeString);

                    var release = new TorrentInfo
                    {
                        MinimumRatio         = 1,
                        MinimumSeedTime      = 288000, //80 hours
                        Categories           = groupCategory,
                        PublishDate          = publishDate,
                        Size                 = size,
                        InfoUrl              = details,
                        DownloadUrl          = link,
                        Guid                 = link,
                        Grabs                = grabs,
                        Seeders              = seeders,
                        Peers                = leechers + seeders,
                        Title                = title,
                        Description          = qDescription?.TextContent,
                        UploadVolumeFactor   = qNeutralLeech is null ? 1 : 0,
                        DownloadVolumeFactor = qFreeLeech != null || qNeutralLeech != null ? 0 : 1
                    };

                    torrentInfos.Add(release);
                }
            }

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

            var parser = new HtmlParser();
            var dom    = parser.ParseDocument(indexerResponse.Content);

            var rows = dom.QuerySelectorAll("tr");

            foreach (var row in rows.Skip(1))
            {
                var release    = new TorrentInfo();
                var qTitleLink = row.QuerySelector("td:nth-of-type(2) a:nth-of-type(1)");
                release.Title = qTitleLink.TextContent.Trim();

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

                release.Guid    = qTitleLink.GetAttribute("href");
                release.InfoUrl = release.Guid;

                var dateString = row.QuerySelector("td:nth-of-type(5)").TextContent;
                release.PublishDate = DateTime.ParseExact(dateString, "dd MMM yy", CultureInfo.InvariantCulture);

                // newbie users don't see DL links
                var qLink = row.QuerySelector("td:nth-of-type(3) a");
                if (qLink != null)
                {
                    release.DownloadUrl = qLink.GetAttribute("href");
                }
                else
                {
                    // use details link as placeholder
                    // null causes errors during export to torznab
                    // skipping the release prevents newbie users from adding the tracker (empty result)
                    release.DownloadUrl = release.InfoUrl;
                }

                var sizeStr = row.QuerySelector("td:nth-of-type(6)").TextContent;
                release.Size = ParseUtil.GetBytes(sizeStr);

                var connections = row.QuerySelector("td:nth-of-type(8)").TextContent.Trim().Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                release.Seeders = ParseUtil.CoerceInt(connections[0].Trim());
                release.Peers   = ParseUtil.CoerceInt(connections[1].Trim()) + release.Seeders;
                release.Grabs   = ParseUtil.CoerceInt(connections[2].Trim());

                var rCat    = row.QuerySelector("td:nth-of-type(1) a").GetAttribute("href");
                var rCatIdx = rCat.IndexOf("cat=");
                if (rCatIdx > -1)
                {
                    rCat = rCat.Substring(rCatIdx + 4);
                }

                release.Categories = _categories.MapTrackerCatToNewznab(rCat);

                if (row.QuerySelector("img[alt=\"Gold Torrent\"]") != null)
                {
                    release.DownloadVolumeFactor = 0;
                }
                else if (row.QuerySelector("img[alt=\"Silver Torrent\"]") != null)
                {
                    release.DownloadVolumeFactor = 0.5;
                }
                else
                {
                    release.DownloadVolumeFactor = 1;
                }

                var uLFactorImg = row.QuerySelector("img[alt*=\"x Multiplier Torrent\"]");
                if (uLFactorImg != null)
                {
                    release.UploadVolumeFactor = ParseUtil.CoerceDouble(uLFactorImg.GetAttribute("alt").Split('x')[0]);
                }
                else
                {
                    release.UploadVolumeFactor = 1;
                }

                qTitleLink.Remove();

                //release.Description = row.QuerySelector("td:nth-of-type(2)").TextContent;
                torrentInfos.Add(release);
            }

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

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

            try
            {
                //var json = JArray.Parse(results.Content);
                var json = JsonConvert.DeserializeObject <dynamic>(indexerResponse.Content);

                foreach (var row in json ?? Enumerable.Empty <dynamic>())
                {
                    var release      = new TorrentInfo();
                    var descriptions = new List <string>();
                    var tags         = new List <string>();

                    release.MinimumRatio    = 1.1;
                    release.MinimumSeedTime = 432000; // 120 hours
                    release.Title           = row.name;
                    release.Categories      = _categories.MapTrackerCatToNewznab(row.category.ToString());
                    release.Size            = row.size;
                    release.Seeders         = row.seeders;
                    release.Peers           = row.leechers + release.Seeders;
                    release.PublishDate     = DateTime.ParseExact(row.added.ToString() + " +01:00", "yyyy-MM-dd HH:mm:ss zzz", CultureInfo.InvariantCulture);
                    release.Files           = row.numfiles;
                    release.Grabs           = row.times_completed;

                    var infoUrl = _settings.BaseUrl + "torrent/" + row.id.ToString() + "/";

                    release.Guid        = infoUrl;
                    release.DownloadUrl = _settings.BaseUrl + "api/v1/torrents/download/" + row.id.ToString();
                    release.InfoUrl     = infoUrl;

                    if (row.frileech == 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    if (row.imdbid2 != null && row.imdbid2.ToString().StartsWith("tt"))
                    {
                        if (int.TryParse((string)row.imdbid2, out int imdbNumber))
                        {
                            release.ImdbId = imdbNumber;
                        }
                    }

                    torrentInfos.Add(release);
                }
            }
            catch (Exception ex)
            {
                throw new IndexerException(indexerResponse,
                                           "Unable to parse response from DigitalCore: {0}",
                                           ex.Message);
            }

            return(torrentInfos.ToArray());
        }
Esempio n. 13
0
        public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var torrentInfos  = new List <TorrentInfo>();
            var contentString = indexerResponse.Content;
            var xthorResponse = JsonConvert.DeserializeObject <XthorResponse>(contentString);

            if (xthorResponse != null)
            {
                CheckApiState(xthorResponse.Error);

                // If contains torrents
                if (xthorResponse.Torrents != null)
                {
                    // Adding each torrent row to releases
                    // Exclude hidden torrents (category 106, example => search 'yoda' in the API) #10407
                    torrentInfos.AddRange(xthorResponse.Torrents
                                          .Where(torrent => torrent.Category != 106).Select(torrent =>
                    {
                        if (_settings.NeedMultiReplacement)
                        {
                            var regex    = new Regex("(?i)([\\.\\- ])MULTI([\\.\\- ])");
                            torrent.Name = regex.Replace(torrent.Name,
                                                         "$1" + _settings.MultiReplacement + "$2");
                        }

                        // issue #8759 replace vostfr and subfrench with English
                        if (!string.IsNullOrEmpty(_settings.SubReplacement))
                        {
                            torrent.Name = torrent.Name.Replace("VOSTFR", _settings.SubReplacement)
                                           .Replace("SUBFRENCH", _settings.SubReplacement);
                        }

                        var publishDate = DateTimeUtil.UnixTimestampToDateTime(torrent.Added);

                        var guid    = new string(_torrentDetailsUrl.Replace("{id}", torrent.Id.ToString()));
                        var details = new string(_torrentDetailsUrl.Replace("{id}", torrent.Id.ToString()));
                        var link    = new string(torrent.Download_link);
                        var release = new TorrentInfo
                        {
                            // Mapping data
                            Categories           = _categories.MapTrackerCatToNewznab(torrent.Category.ToString()),
                            Title                = torrent.Name,
                            Seeders              = torrent.Seeders,
                            Peers                = torrent.Seeders + torrent.Leechers,
                            MinimumRatio         = 1,
                            MinimumSeedTime      = 345600,
                            PublishDate          = publishDate,
                            Size                 = torrent.Size,
                            Grabs                = torrent.Times_completed,
                            Files                = torrent.Numfiles,
                            UploadVolumeFactor   = 1,
                            DownloadVolumeFactor = torrent.Freeleech == 1 ? 0 : 1,
                            Guid                 = guid,
                            InfoUrl              = details,
                            DownloadUrl          = link,
                            TmdbId               = torrent.Tmdb_id
                        };

                        return(release);
                    }));
                }
            }

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

            var parser = new HtmlParser();
            var dom    = parser.ParseDocument(indexerResponse.Content);

            var userInfo     = dom.QuerySelector("table.navus tr");
            var userRank     = userInfo.Children[1].TextContent.Replace("Rank:", string.Empty).Trim();
            var hasFreeleech = _freeleechRanks.Contains(userRank);

            var rows = dom.QuerySelectorAll("table.mainblockcontenttt tr:has(td.mainblockcontent)");

            foreach (var row in rows.Skip(1))
            {
                var mainLink = row.Children[2].QuerySelector("a");
                var title    = mainLink.TextContent;
                var details  = new Uri(_settings.BaseUrl + mainLink.GetAttribute("href"));

                var posterMatch = _posterRegex.Match(mainLink.GetAttribute("onmouseover"));
                var poster      = posterMatch.Success ? _settings.BaseUrl + posterMatch.Groups[1].Value.Replace("\\", "/") : null;

                var link        = new Uri(_settings.BaseUrl + row.Children[4].FirstElementChild.GetAttribute("href"));
                var description = row.Children[2].QuerySelector("span").TextContent;
                var size        = ParseUtil.GetBytes(row.Children[7].TextContent);

                var dateTag     = row.Children[6].FirstElementChild;
                var dateString  = string.Join(" ", dateTag.Attributes.Select(attr => attr.Name));
                var publishDate = DateTime.ParseExact(dateString, "dd MMM yyyy HH:mm:ss zz00", CultureInfo.InvariantCulture).ToLocalTime();

                var catStr = row.FirstElementChild.FirstElementChild.GetAttribute("href").Split('=')[1];
                var cat    = _categories.MapTrackerCatToNewznab(catStr);

                // Sometimes the uploader column is missing, so seeders, leechers, and grabs may be at a different index.
                // There's room for improvement, but this works for now.
                var endIndex = row.Children.Length;

                if (row.Children[endIndex - 1].TextContent == "Edit")
                {
                    //Maybe use row.Children.Index(Node) after searching for an element instead?
                    endIndex -= 1;
                }
                else if (row.Children[endIndex - 4].TextContent == "Edit")
                {
                    // moderators get additional delete, recommend and like links
                    endIndex -= 4;
                }

                int?seeders = null;
                int?peers   = null;
                if (ParseUtil.TryCoerceInt(row.Children[endIndex - 3].TextContent, out var rSeeders))
                {
                    seeders = rSeeders;
                    if (ParseUtil.TryCoerceInt(row.Children[endIndex - 2].TextContent, out var rLeechers))
                    {
                        peers = rLeechers + rSeeders;
                    }
                }

                var grabs = ParseUtil.TryCoerceInt(row.Children[endIndex - 1].TextContent, out var rGrabs)
                    ? (int?)rGrabs
                    : null;

                var dlVolumeFactor = 1.0;
                var upVolumeFactor = 1.0;
                if (row.QuerySelector("img[src$=\"no_ratio.png\"]") != null)
                {
                    dlVolumeFactor = 0;
                    upVolumeFactor = 0;
                }
                else if (hasFreeleech || row.QuerySelector("img[src$=\"free.png\"]") != null)
                {
                    dlVolumeFactor = 0;
                }
                else if (row.QuerySelector("img[src$=\"50.png\"]") != null)
                {
                    dlVolumeFactor = 0.5;
                }
                else if (row.QuerySelector("img[src$=\"25.png\"]") != null)
                {
                    dlVolumeFactor = 0.75;
                }
                else if (row.QuerySelector("img[src$=\"75.png\"]") != null)
                {
                    dlVolumeFactor = 0.25;
                }

                var imdbLink = row.QuerySelector("a[href*=\"www.imdb.com/title/\"]")?.GetAttribute("href");
                var imdb     = !string.IsNullOrWhiteSpace(imdbLink) ? ParseUtil.GetImdbID(imdbLink) : null;

                var release = new TorrentInfo
                {
                    Title                = title,
                    Guid                 = details.AbsoluteUri,
                    DownloadUrl          = link.AbsoluteUri,
                    InfoUrl              = details.AbsoluteUri,
                    PosterUrl            = poster,
                    PublishDate          = publishDate,
                    Categories           = cat,
                    ImdbId               = imdb ?? 0,
                    Size                 = size,
                    Grabs                = grabs,
                    Seeders              = seeders,
                    Peers                = peers,
                    DownloadVolumeFactor = dlVolumeFactor,
                    UploadVolumeFactor   = upVolumeFactor,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 172800 // 48 hours
                };

                torrentInfos.Add(release);
            }

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

            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 <GazelleResponse>(indexerResponse.HttpResponse);

            if (jsonResponse.Resource.Status != "success" ||
                string.IsNullOrWhiteSpace(jsonResponse.Resource.Status) ||
                jsonResponse.Resource.Response == null)
            {
                return(torrentInfos);
            }

            foreach (var result in jsonResponse.Resource.Response.Results)
            {
                if (result.Torrents != null)
                {
                    foreach (var torrent in result.Torrents)
                    {
                        var id     = torrent.TorrentId;
                        var artist = WebUtility.HtmlDecode(result.Artist);
                        var album  = WebUtility.HtmlDecode(result.GroupName);

                        var title = $"{result.Artist} - {result.GroupName} ({result.GroupYear}) [{torrent.Format} {torrent.Encoding}] [{torrent.Media}]";
                        if (torrent.HasCue)
                        {
                            title += " [Cue]";
                        }

                        var infoUrl = GetInfoUrl(result.GroupId, id);

                        GazelleInfo release = new GazelleInfo()
                        {
                            Guid = infoUrl,

                            // Splice Title from info to avoid calling API again for every torrent.
                            Title = WebUtility.HtmlDecode(title),

                            Container            = torrent.Encoding,
                            Codec                = torrent.Format,
                            Size                 = long.Parse(torrent.Size),
                            DownloadUrl          = GetDownloadUrl(id, torrent.CanUseToken),
                            InfoUrl              = infoUrl,
                            Seeders              = int.Parse(torrent.Seeders),
                            Peers                = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders),
                            PublishDate          = torrent.Time.ToUniversalTime(),
                            Scene                = torrent.Scene,
                            Freeleech            = torrent.IsFreeLeech || torrent.IsPersonalFreeLeech,
                            Files                = torrent.FileCount,
                            Grabs                = torrent.Snatches,
                            DownloadVolumeFactor = torrent.IsFreeLeech || torrent.IsNeutralLeech || torrent.IsPersonalFreeLeech ? 0 : 1,
                            UploadVolumeFactor   = torrent.IsNeutralLeech ? 0 : 1
                        };

                        var category = torrent.Category;
                        if (category == null || category.Contains("Select Category"))
                        {
                            release.Categories = _categories.MapTrackerCatToNewznab("1");
                        }
                        else
                        {
                            release.Categories = _categories.MapTrackerCatDescToNewznab(category);
                        }

                        torrentInfos.Add(release);
                    }
                }

                // Non-Audio files are formatted a little differently (1:1 for group and torrents)
                else
                {
                    var id      = result.TorrentId;
                    var infoUrl = GetInfoUrl(result.GroupId, id);

                    GazelleInfo release = new GazelleInfo()
                    {
                        Guid                 = infoUrl,
                        Title                = WebUtility.HtmlDecode(result.GroupName),
                        Size                 = long.Parse(result.Size),
                        DownloadUrl          = GetDownloadUrl(id, result.CanUseToken),
                        InfoUrl              = infoUrl,
                        Seeders              = int.Parse(result.Seeders),
                        Peers                = int.Parse(result.Leechers) + int.Parse(result.Seeders),
                        PublishDate          = DateTimeOffset.FromUnixTimeSeconds(result.GroupTime).UtcDateTime,
                        Freeleech            = result.IsFreeLeech || result.IsPersonalFreeLeech,
                        Files                = result.FileCount,
                        Grabs                = result.Snatches,
                        DownloadVolumeFactor = result.IsFreeLeech || result.IsNeutralLeech || result.IsPersonalFreeLeech ? 0 : 1,
                        UploadVolumeFactor   = result.IsNeutralLeech ? 0 : 1
                    };

                    var category = result.Category;
                    if (category == null || category.Contains("Select Category"))
                    {
                        release.Categories = _categories.MapTrackerCatToNewznab("1");
                    }
                    else
                    {
                        release.Categories = _categories.MapTrackerCatDescToNewznab(category);
                    }

                    torrentInfos.Add(release);
                }
            }

            // order by date
            return
                (torrentInfos
                 .OrderByDescending(o => o.PublishDate)
                 .ToArray());
        }
Esempio n. 16
0
        public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var torrentInfos = new List <TorrentInfo>();

            var parser = new HtmlParser();
            var dom    = parser.ParseDocument(indexerResponse.Content);

            var rows = dom.QuerySelectorAll("#sortabletable tr:has(a[href*=\"details.php?id=\"])");

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

                var qDetails = row.QuerySelector("div > a[href*=\"details.php?id=\"]"); // details link, release name get's shortened if it's to long

                // use Title from tooltip or fallback to Details link if there's no tooltip
                var qTitle = row.QuerySelector(".tooltip-content > div:nth-of-type(1)") ?? qDetails;
                release.Title = qTitle.TextContent;

                var qDesciption = row.QuerySelectorAll(".tooltip-content > div");
                if (qDesciption.Any())
                {
                    release.Description = qDesciption[1].TextContent.Trim();
                }

                var qLink = row.QuerySelector("a[href*=\"download.php\"]");
                release.DownloadUrl = qLink.GetAttribute("href");
                release.Guid        = release.DownloadUrl;
                release.InfoUrl     = qDetails.GetAttribute("href");

                // 2021-03-17 03:39 AM
                var dateString = row.QuerySelectorAll("td:nth-of-type(2) div").Last().LastChild.TextContent.Trim();
                release.PublishDate = DateTime.ParseExact(dateString, "yyyy-MM-dd hh:mm tt", CultureInfo.InvariantCulture);

                var sizeStr = row.QuerySelector("td:nth-of-type(5)").TextContent.Trim();
                release.Size = ParseUtil.GetBytes(sizeStr);

                release.Seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(7)").TextContent.Trim());
                release.Peers   = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(8)").TextContent.Trim()) + release.Seeders;

                var catLink  = row.QuerySelector("td:nth-of-type(1) a").GetAttribute("href");
                var catSplit = catLink.IndexOf("category=");
                if (catSplit > -1)
                {
                    catLink = catLink.Substring(catSplit + 9);
                }

                release.Categories = _categories.MapTrackerCatToNewznab(catLink);

                var grabs = row.QuerySelector("td:nth-child(6)").TextContent;
                release.Grabs = ParseUtil.CoerceInt(grabs);

                if (row.QuerySelector("img[title^=\"Free Torrent\"]") != null)
                {
                    release.DownloadVolumeFactor = 0;
                }
                else if (row.QuerySelector("img[title^=\"Silver Torrent\"]") != null)
                {
                    release.DownloadVolumeFactor = 0.5;
                }
                else
                {
                    release.DownloadVolumeFactor = 1;
                }

                if (row.QuerySelector("img[title^=\"x2 Torrent\"]") != null)
                {
                    release.UploadVolumeFactor = 2;
                }
                else
                {
                    release.UploadVolumeFactor = 1;
                }

                torrentInfos.Add(release);
            }

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

            var parser = new HtmlParser();
            var doc    = parser.ParseDocument(indexerResponse.Content);

            var rows = doc.QuerySelectorAll("table[id='torrents'] > tbody > tr");

            foreach (var row in rows)
            {
                var qTitleLink = row.QuerySelector("a.hv");

                //no results
                if (qTitleLink == null)
                {
                    continue;
                }

                // drop invalid char that seems to have cropped up in some titles. #6582
                var title   = qTitleLink.TextContent.Trim().Replace("\u000f", "");
                var details = new Uri(_settings.BaseUrl + qTitleLink.GetAttribute("href").TrimStart('/'));

                var qLink = row.QuerySelector("a[href^=\"/download.php/\"]");
                var link  = new Uri(_settings.BaseUrl + qLink.GetAttribute("href").TrimStart('/'));

                var descrSplit  = row.QuerySelector("div.sub").TextContent.Split('|');
                var dateSplit   = descrSplit.Last().Split(new[] { " by " }, StringSplitOptions.None);
                var publishDate = DateTimeUtil.FromTimeAgo(dateSplit.First());
                var description = descrSplit.Length > 1 ? "Tags: " + descrSplit.First().Trim() : "";
                description += dateSplit.Length > 1 ? " Uploaded by: " + dateSplit.Last().Trim() : "";

                var catIcon = row.QuerySelector("td:nth-of-type(1) a");
                if (catIcon == null)
                {
                    // Torrents - Category column == Text or Code
                    // release.Category = MapTrackerCatDescToNewznab(row.Cq().Find("td:eq(0)").Text()); // Works for "Text" but only contains the parent category
                    throw new Exception("Please, change the 'Torrents - Category column' option to 'Icons' in the website Settings. Wait a minute (cache) and then try again.");
                }

                // Torrents - Category column == Icons
                var cat = _categories.MapTrackerCatToNewznab(catIcon.GetAttribute("href").Substring(1));

                var size = ParseUtil.GetBytes(row.Children[5].TextContent);

                var colIndex = 6;
                int?files    = null;

                if (row.Children.Length == 10)
                {
                    files = ParseUtil.CoerceInt(row.Children[colIndex].TextContent.Replace("Go to files", ""));
                    colIndex++;
                }

                var grabs          = ParseUtil.CoerceInt(row.Children[colIndex++].TextContent);
                var seeders        = ParseUtil.CoerceInt(row.Children[colIndex++].TextContent);
                var leechers       = ParseUtil.CoerceInt(row.Children[colIndex].TextContent);
                var dlVolumeFactor = row.QuerySelector("span.free") != null ? 0 : 1;

                var release = new TorrentInfo
                {
                    Title                = title,
                    Guid                 = details.AbsoluteUri,
                    DownloadUrl          = link.AbsoluteUri,
                    InfoUrl              = details.AbsoluteUri,
                    PublishDate          = publishDate,
                    Categories           = cat,
                    Size                 = size,
                    Files                = files,
                    Grabs                = grabs,
                    Seeders              = seeders,
                    Peers                = seeders + leechers,
                    DownloadVolumeFactor = dlVolumeFactor,
                    UploadVolumeFactor   = 1,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 1209600 // 336 hours
                };

                torrentInfos.Add(release);
            }

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

            var parser = new HtmlParser();
            var dom    = parser.ParseDocument(indexerResponse.Content);
            var rows   = dom.QuerySelectorAll("#torrents-table > tbody > tr");

            foreach (var row in rows.Skip(1))
            {
                var qDetails = row.QuerySelector(".br_right > a");
                var details  = _settings.BaseUrl + qDetails.GetAttribute("href");
                var title    = qDetails.QuerySelector("b").TextContent;

                // Remove auto-generated [REQ] tag from fulfilled requests
                if (title.StartsWith("[REQ] "))
                {
                    title = title.Substring(6);
                }

                var qLink = row.QuerySelector("td:nth-child(4) > a");
                if (qLink == null)
                {
                    continue; // support/donation banner
                }

                var link = _settings.BaseUrl + qLink.GetAttribute("href");

                // dateString format "yyyy-MMM-dd hh:mm:ss" => eg "2015-04-25 23:38:12"
                var dateString  = row.QuerySelector("td:nth-child(6) nobr").TextContent.Trim();
                var publishDate = DateTime.ParseExact(dateString, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture);

                var size     = ParseUtil.GetBytes(row.QuerySelector("td:nth-child(7)").InnerHtml.Split('<').First().Trim());
                var files    = ParseUtil.GetLongFromString(row.QuerySelector("td:nth-child(7) > a").TextContent);
                var grabs    = ParseUtil.GetLongFromString(row.QuerySelector("td:nth-child(8)").TextContent);
                var seeders  = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(9)").TextContent);
                var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(10)").TextContent);

                var category = row.QuerySelector(".br_type > a").GetAttribute("href").Replace("browse.php?cat=", string.Empty);

                var qImdb = row.QuerySelector("a[href*=\"www.imdb.com/\"]");
                var imdb  = qImdb != null?ParseUtil.GetImdbID(qImdb.GetAttribute("href").Split('/').Last()) : null;

                var release = new TorrentInfo
                {
                    InfoUrl              = details,
                    Guid                 = details,
                    Title                = title,
                    DownloadUrl          = link,
                    PublishDate          = publishDate,
                    Size                 = size,
                    Seeders              = seeders,
                    Peers                = seeders + leechers,
                    Grabs                = (int)grabs,
                    Files                = (int)files,
                    Categories           = _categories.MapTrackerCatToNewznab(category),
                    ImdbId               = imdb ?? 0,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 172800, // 48 hours
                    UploadVolumeFactor   = 1,
                    DownloadVolumeFactor = 1
                };

                torrentInfos.Add(release);
            }

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

            var json = JsonConvert.DeserializeObject <dynamic>(indexerResponse.Content);

            foreach (var row in json ?? Enumerable.Empty <dynamic>())
            {
                var release      = new TorrentInfo();
                var descriptions = new List <string>();
                var tags         = new List <string>();

                release.MinimumRatio    = 1.1;
                release.MinimumSeedTime = 172800; // 48 hours
                release.Title           = row.name;
                release.Categories      = _categories.MapTrackerCatToNewznab(row.category.ToString());
                release.Size            = row.size;
                release.Seeders         = row.seeders;
                release.Peers           = row.leechers + release.Seeders;
                release.PublishDate     = DateTime.ParseExact(row.added.ToString() + " +01:00", "yyyy-MM-dd HH:mm:ss zzz", CultureInfo.InvariantCulture);
                release.Files           = row.numfiles;
                release.Grabs           = row.times_completed;

                release.InfoUrl     = _settings.BaseUrl + "torrent/" + row.id.ToString() + "/";
                release.Guid        = release.InfoUrl;
                release.DownloadUrl = _settings.BaseUrl + "api/v1/torrents/download/" + row.id.ToString();

                if (row.frileech == 1)
                {
                    release.DownloadVolumeFactor = 0;
                }
                else
                {
                    release.DownloadVolumeFactor = 1;
                }

                release.UploadVolumeFactor = 1;

                if (!string.IsNullOrWhiteSpace(row.customcover.ToString()))
                {
                    release.PosterUrl = _settings.BaseUrl + row.customcover;
                }

                if (row.imdbid2 != null && row.imdbid2.ToString().StartsWith("tt"))
                {
                    release.ImdbId = ParseUtil.CoerceInt(row.imdbid2.ToString().Substring(2));
                    descriptions.Add("Title: " + row.title);
                    descriptions.Add("Year: " + row.year);
                    descriptions.Add("Genres: " + row.genres);
                    descriptions.Add("Tagline: " + row.tagline);
                    descriptions.Add("Cast: " + row.cast);
                    descriptions.Add("Rating: " + row.rating);
                    descriptions.Add("Plot: " + row.plot);

                    release.PosterUrl = _settings.BaseUrl + "img/imdb/" + row.imdbid2 + ".jpg";
                }

                if ((int)row.p2p == 1)
                {
                    tags.Add("P2P");
                }

                if ((int)row.pack == 1)
                {
                    tags.Add("Pack");
                }

                if ((int)row.reqid != 0)
                {
                    tags.Add("Request");
                }

                if ((int)row.sweaudio != 0)
                {
                    tags.Add("Swedish audio");
                }

                if ((int)row.swesub != 0)
                {
                    tags.Add("Swedish subtitles");
                }

                if (tags.Count > 0)
                {
                    descriptions.Add("Tags: " + string.Join(", ", tags));
                }

                var preDate = row.preDate.ToString();
                if (!string.IsNullOrWhiteSpace(preDate) && preDate != "1970-01-01 01:00:00")
                {
                    descriptions.Add("PRE: " + preDate);
                }

                descriptions.Add("Section: " + row.section);

                //release.Description = string.Join("<br>\n", descriptions);
                torrentInfos.Add(release);
            }

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

            var contentString = indexerResponse.Content;

            // returned content might start with an html error message, remove it first
            var jsonStart      = contentString.IndexOf('{');
            var jsonContentStr = contentString.Remove(0, jsonStart);

            var jsonContent = JObject.Parse(jsonContentStr);

            var result = jsonContent.Value <string>("status");

            // query was not successful
            if (result != "ok")
            {
                return(new List <ReleaseInfo>());
            }

            var dataItems  = jsonContent.Value <JToken>("data");
            var movieCount = dataItems.Value <int>("movie_count");

            // no results found in query
            if (movieCount < 1)
            {
                return(new List <ReleaseInfo>());
            }

            var movies = dataItems.Value <JToken>("movies");

            if (movies == null)
            {
                return(new List <ReleaseInfo>());
            }

            foreach (var movie in movies)
            {
                var torrents = movie.Value <JArray>("torrents");
                if (torrents == null)
                {
                    continue;
                }

                foreach (var torrent in torrents)
                {
                    var release = new TorrentInfo();

                    // append type: BRRip or WEBRip, resolves #3558 via #4577
                    var type = torrent.Value <string>("type");
                    switch (type)
                    {
                    case "web":
                        type = "WEBRip";
                        break;

                    default:
                        type = "BRRip";
                        break;
                    }

                    var quality = torrent.Value <string>("quality");
                    var title   = movie.Value <string>("title").Replace(":", "").Replace(' ', '.');
                    var year    = movie.Value <int>("year");
                    release.Title = $"{title}.{year}.{quality}.{type}-YTS";

                    var imdb = movie.Value <string>("imdb_code");
                    release.ImdbId = ParseUtil.GetImdbID(imdb).Value;

                    release.InfoHash = torrent.Value <string>("hash"); // magnet link is auto generated from infohash

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

                    release.DownloadUrl          = torrent.Value <string>("url");
                    release.Seeders              = torrent.Value <int>("seeds");
                    release.Peers                = torrent.Value <int>("peers") + release.Seeders;
                    release.Size                 = torrent.Value <long>("size_bytes");
                    release.DownloadVolumeFactor = 0;
                    release.UploadVolumeFactor   = 1;

                    release.InfoUrl = movie.Value <string>("url");

                    release.PosterUrl = new Uri(movie.Value <string>("large_cover_image")).AbsoluteUri;
                    release.Guid      = release.DownloadUrl;

                    // map the quality to a newznab category for torznab compatibility (for Radarr, etc)
                    switch (quality)
                    {
                    case "720p":
                        release.Categories = _categories.MapTrackerCatToNewznab("45");
                        break;

                    case "1080p":
                        release.Categories = _categories.MapTrackerCatToNewznab("44");
                        break;

                    case "2160p":
                        release.Categories = _categories.MapTrackerCatToNewznab("46");
                        break;

                    case "3D":
                        release.Categories = _categories.MapTrackerCatToNewznab("47");
                        break;

                    default:
                        release.Categories = _categories.MapTrackerCatToNewznab("45");
                        break;
                    }

                    if (release == null)
                    {
                        continue;
                    }

                    torrentInfos.Add(release);
                }
            }

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

            var parser = new HtmlParser();
            var dom    = parser.ParseDocument(indexerResponse.Content);

            foreach (var child in dom.QuerySelectorAll("#needseed"))
            {
                child.Remove();
            }

            var table = dom.QuerySelector("table[align=center] + br + table > tbody");

            // No results, so skip this search
            if (table == null)
            {
                return(torrentInfos);
            }

            foreach (var row in table.Children.Skip(1))
            {
                var release = new TorrentInfo();
                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 (torrentInfos.Any(r => r.Guid == detailsLink.AbsoluteUri))
                {
                    continue;
                }

                release.Files       = ParseUtil.CoerceInt(row.Children[3].TextContent);
                release.Grabs       = ParseUtil.CoerceInt(row.Children[7].TextContent);
                release.Guid        = detailsLink.AbsoluteUri;
                release.InfoUrl     = release.Guid;
                release.DownloadUrl = new Uri(_settings.BaseUrl + row.QuerySelector("a[href^=\"download.php\"]").GetAttribute("href")).AbsoluteUri;
                var catUrl   = new Uri(_settings.BaseUrl + row.Children[1].FirstElementChild.GetAttribute("href"));
                var catQuery = HttpUtility.ParseQueryString(catUrl.Query);
                var catNum   = catQuery["cat"];
                release.Categories = _categories.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    = ParseUtil.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;
                }

                torrentInfos.Add(release);
            }

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

            var parser = new HtmlParser();
            var dom    = parser.ParseDocument(indexerResponse.Content);

            var table = dom.QuerySelector("table.movehere");

            if (table == null)
            {
                return(torrentInfos); // no results
            }

            var headerColumns = table.QuerySelectorAll("tbody > tr > td.cat_Head")
                                .Select(x => x.TextContent).ToList();
            var categoryIndex = headerColumns.FindIndex(x => x.Equals("Type"));
            var nameIndex     = headerColumns.FindIndex(x => x.Equals("Name"));
            var sizeIndex     = headerColumns.FindIndex(x => x.Equals("Size"));
            var seedersIndex  = headerColumns.FindIndex(x => x.Equals("Seeders"));
            var leechersIndex = headerColumns.FindIndex(x => x.Equals("Leechers"));

            var rows = dom.QuerySelectorAll("tr.browse");

            foreach (var row in rows)
            {
                // TODO convert to initializer
                var qDescCol  = row.Children[nameIndex];
                var qLink     = qDescCol.QuerySelector("a");
                var details   = _settings.BaseUrl + "/" + qLink.GetAttribute("href");
                var torrentId = qLink.GetAttribute("href").Split('=')[1];
                var sizeStr   = row.Children[sizeIndex].TextContent;
                var seeders   = ParseUtil.CoerceInt(row.Children[seedersIndex].TextContent.Trim());

                var catId    = "82"; // default
                var qCatLink = row.Children[categoryIndex].QuerySelector("a");
                if (qCatLink != null)
                {
                    catId = new Regex(@"\?cat=(\d*)").Match(qCatLink.GetAttribute("href")).Groups[1].ToString().Trim();
                }

                var release = new TorrentInfo
                {
                    Title                = qLink.TextContent,
                    InfoUrl              = details,
                    Categories           = _categories.MapTrackerCatToNewznab(catId),
                    DownloadUrl          = string.Format("{0}/download.php/{1}/download.torrent", _settings.BaseUrl, torrentId),
                    Guid                 = details,
                    PublishDate          = DateTimeUtil.FromTimeAgo(qDescCol.ChildNodes.Last().TextContent),
                    Size                 = ParseUtil.GetBytes(sizeStr),
                    Seeders              = seeders,
                    Peers                = ParseUtil.CoerceInt(row.Children[leechersIndex].TextContent.Trim()) + seeders,
                    DownloadVolumeFactor = row.QuerySelector("font > b:contains(Freeleech)") != null ? 0 : 1,
                    UploadVolumeFactor   = 1,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 259200 // 72 hours
                };

                release.Categories = _categories.MapTrackerCatToNewznab(catId);

                //TODO Do something with this filtering
                //if (!query.MatchQueryStringAND(release.Title))
                //    continue;
                torrentInfos.Add(release);
            }

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

            var resultParser         = new HtmlParser();
            var searchResultDocument = resultParser.ParseDocument(indexerResponse.Content);
            var rows = searchResultDocument.QuerySelectorAll("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 || !string.Equals(prev.NodeName, "style", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var release = new TorrentInfo();
                release.MinimumRatio    = 1;
                release.MinimumSeedTime = 86400; // 24 hours

                var qLink = row.Children[1].FirstElementChild;
                release.Title   = qLink.TextContent.Trim();
                release.InfoUrl = _settings.BaseUrl + qLink.GetAttribute("href");
                release.Guid    = release.InfoUrl;

                var imdbLink = row.Children[1].QuerySelector("a[href*=imdb]");
                if (imdbLink != null)
                {
                    release.ImdbId = ParseUtil.GetImdbID(imdbLink.GetAttribute("href").Split('/').Last()).GetValueOrDefault();
                }

                var qDownload = row.Children[3].FirstElementChild;
                release.DownloadUrl = _settings.BaseUrl + qDownload.GetAttribute("href");

                var dateStr = row.Children[4].TextContent.Trim();

                //"July 11, 2015, 13:34:09", "Today|Yesterday at 20:04:23"
                release.PublishDate = DateTimeUtil.FromUnknown(dateStr);
                var sizeStr = row.Children[5].TextContent;
                release.Size    = ParseUtil.GetBytes(sizeStr);
                release.Seeders = ParseUtil.CoerceInt(row.Children[7].TextContent);
                release.Peers   = ParseUtil.CoerceInt(row.Children[8].TextContent) + release.Seeders;
                var grabs = row.QuerySelector("td:nth-child(10)").TextContent;
                grabs         = grabs.Replace("---", "0");
                release.Grabs = ParseUtil.CoerceInt(grabs);

                if (row.QuerySelector("img[title=\"FreeLeech\"]") != null)
                {
                    release.DownloadVolumeFactor = 0;
                }
                else if (row.QuerySelector("img[src=\"images/sf.png\"]") != null)
                {
                    release.DownloadVolumeFactor = 0;
                }
                else if (row.QuerySelector("img[title=\"Half FreeLeech\"]") != null)
                {
                    release.DownloadVolumeFactor = 0.5;
                }
                else
                {
                    release.DownloadVolumeFactor = 1;
                }

                release.UploadVolumeFactor = 1;
                var qCat = row.QuerySelector("a[href^=\"index.php?page=torrents&category=\"]");
                var cat  = qCat.GetAttribute("href").Split('=')[2];
                release.Categories = _categories.MapTrackerCatToNewznab(cat);
                torrentInfos.Add(release);
            }

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

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

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

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

                var catStr = row.Children[0].FirstElementChild.GetAttribute("href").Split(new[] { '[', ']' })[1];
                release.Categories = _categories.MapTrackerCatToNewznab(catStr);

                var qDetails = row.Children[1].QuerySelector("a[title='View Torrent']");
                release.InfoUrl = _settings.BaseUrl + qDetails.GetAttribute("href");
                release.Guid    = release.InfoUrl;

                var qDownload = row.Children[1].QuerySelector("a[title='Download']");
                release.DownloadUrl = _settings.BaseUrl + qDownload.GetAttribute("href");

                var dateStr = row.Children[3].TextContent.Trim().Replace(" and", "");
                release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);

                var sizeStr = row.Children[4].TextContent;
                release.Size = ParseUtil.GetBytes(sizeStr);

                release.Files   = ParseUtil.CoerceInt(row.Children[2].TextContent.Trim());
                release.Seeders = ParseUtil.CoerceInt(row.Children[7].TextContent.Trim());
                release.Peers   = ParseUtil.CoerceInt(row.Children[8].TextContent.Trim()) + release.Seeders;

                var grabs = row.QuerySelector("td:nth-child(6)").TextContent;
                release.Grabs = ParseUtil.CoerceInt(grabs);

                if (row.QuerySelector("strong:contains(\"Freeleech!\")") != null)
                {
                    release.DownloadVolumeFactor = 0;
                }
                else
                {
                    release.DownloadVolumeFactor = 1;
                }

                release.UploadVolumeFactor = 1;

                var title = row.QuerySelector("td:nth-child(2)");
                foreach (var element in title.QuerySelectorAll("span, strong, div, br"))
                {
                    element.Remove();
                }

                release.Title = ParseUtil.NormalizeMultiSpaces(title.TextContent.Replace(" - ]", "]"));

                //change "Season #" to "S##" for TV shows
                if (catStr == "10")
                {
                    release.Title = Regex.Replace(release.Title,
                                                  @"Season (\d+)",
                                                  m => string.Format("S{0:00}",
                                                                     int.Parse(m.Groups[1].Value)));
                }

                torrentInfos.Add(release);
            }

            return(torrentInfos.ToArray());
        }
Esempio n. 25
0
        public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            // Throw auth errors here before we try to parse
            if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.Forbidden)
            {
                throw new IndexerAuthException("[403 Forbidden] - mam_session_id expired or invalid");
            }

            // Throw common http errors here before we try to parse
            if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
            {
                // Remove cookie cache
                CookiesUpdater(null, null);

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

            if (!indexerResponse.HttpResponse.Headers.ContentType.Contains(HttpAccept.Json.Value))
            {
                // Remove cookie cache
                CookiesUpdater(null, null);

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

            var torrentInfos = new List <TorrentInfo>();

            var jsonResponse = JsonConvert.DeserializeObject <MyAnonamouseResponse>(indexerResponse.Content);

            var error = jsonResponse.Error;

            if (error != null && error == "Nothing returned, out of 0")
            {
                return(torrentInfos.ToArray());
            }

            foreach (var item in jsonResponse.Data)
            {
                //TODO shift to ReleaseInfo object initializer for consistency
                var release = new TorrentInfo();

                var id = item.Id;
                release.Title = item.Title;

                // release.Description = item.Value<string>("description");
                var author = string.Empty;

                if (item.AuthorInfo != null)
                {
                    var authorInfo = JsonConvert.DeserializeObject <Dictionary <string, string> >(item.AuthorInfo);
                    author = authorInfo?.First().Value;
                }

                if (author != null)
                {
                    release.Title += " by " + author;
                }

                var flags = new List <string>();

                var langCode = item.LangCode;
                if (!string.IsNullOrEmpty(langCode))
                {
                    flags.Add(langCode);
                }

                var filetype = item.Filetype;
                if (!string.IsNullOrEmpty(filetype))
                {
                    flags.Add(filetype);
                }

                if (flags.Count > 0)
                {
                    release.Title += " [" + string.Join(" / ", flags) + "]";
                }

                if (item.Vip)
                {
                    release.Title += " [VIP]";
                }

                var category = item.Category;
                release.Categories = _categories.MapTrackerCatToNewznab(category);

                release.DownloadUrl = _settings.BaseUrl + "/tor/download.php?tid=" + id;
                release.InfoUrl     = _settings.BaseUrl + "/t/" + id;
                release.Guid        = release.InfoUrl;

                var dateStr  = item.Added;
                var dateTime = DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                release.PublishDate = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc).ToLocalTime();

                release.Grabs   = item.Grabs;
                release.Files   = item.NumFiles;
                release.Seeders = item.Seeders;
                release.Peers   = item.Leechers + release.Seeders;
                var size = item.Size;
                release.Size = ParseUtil.GetBytes(size);

                release.DownloadVolumeFactor = item.Free ? 0 : 1;
                release.UploadVolumeFactor   = 1;

                torrentInfos.Add(release);
            }

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

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

            var jsonResponse = JsonConvert.DeserializeObject <HDBitsResponse>(indexerResponse.Content);

            if (jsonResponse.Status != StatusCode.Success)
            {
                throw new IndexerException(indexerResponse,
                                           "HDBits API request returned status code {0}: {1}",
                                           jsonResponse.Status,
                                           jsonResponse.Message ?? string.Empty);
            }

            var responseData = jsonResponse.Data as JArray;

            if (responseData == null)
            {
                throw new IndexerException(indexerResponse,
                                           "Indexer API call response missing result data");
            }

            var queryResults = responseData.ToObject <TorrentQueryResponse[]>();

            foreach (var result in queryResults)
            {
                var id = result.Id;
                var internalRelease = result.TypeOrigin == 1 ? true : false;

                var flags = new List <IndexerFlag>();

                if (internalRelease)
                {
                    flags.Add(IndexerFlag.Internal);
                }

                torrentInfos.Add(new HDBitsInfo()
                {
                    Guid                 = string.Format("HDBits-{0}", id),
                    Title                = result.Name,
                    Size                 = result.Size,
                    Categories           = _categories.MapTrackerCatToNewznab(result.TypeCategory.ToString()),
                    InfoHash             = result.Hash,
                    DownloadUrl          = GetDownloadUrl(id),
                    InfoUrl              = GetInfoUrl(id),
                    Seeders              = result.Seeders,
                    Grabs                = (int)result.TimesCompleted,
                    Files                = (int)result.NumFiles,
                    Peers                = result.Leechers + result.Seeders,
                    PublishDate          = result.Added.ToUniversalTime(),
                    Internal             = internalRelease,
                    ImdbId               = result.ImdbInfo?.Id ?? 0,
                    TvdbId               = result.TvdbInfo?.Id ?? 0,
                    DownloadVolumeFactor = result.FreeLeech == "yes" ? 0 : 1,
                    UploadVolumeFactor   = 1,
                    IndexerFlags         = flags
                });
            }

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

            var parser = new HtmlParser();
            var dom    = parser.ParseDocument(indexerResponse.Content);

            var firstPageRows = dom.QuerySelectorAll("#torrentTable > tbody > tr").Skip(1).ToCollection();

            // If pagination available
            int nbResults;

            // Check if we have a minimum of one result
            if (firstPageRows?.Length >= 1)
            {
                // Retrieve total count on our alone page
                nbResults = firstPageRows.Count();
            }
            else
            {
                // No result found for this query
                return(torrentInfos);
            }

            var torrentDetailsUrl  = _settings.BaseUrl + "details.php?id={id}";
            var torrentDownloadUrl = _settings.BaseUrl + "download.php?id={id}&passkey={passkey}";

            // Loop on results
            foreach (var row in firstPageRows)
            {
                var id           = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("href").Split('=').Last();        // ID
                var name         = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("title");                         // Release Name
                var categoryName = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("title");                   // Category
                var mainCat      = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("href").Split('?').Last();
                var qSubCat2     = row.QuerySelector("td:nth-of-type(1) > div > a[href^=\"/browse.php?sub2_cat[]=\"]");
                var cat          = mainCat;
                if (qSubCat2 != null)
                {
                    cat += '&' + qSubCat2.GetAttribute("href").Split('?').Last();
                }

                var seeders    = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)").TextContent);                                   // Seeders
                var leechers   = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)").TextContent);                                  // Leechers
                var regexObj   = new Regex(@"[^\d]");                                                                                       // Completed
                var completed2 = row.QuerySelector("td:nth-of-type(8)").TextContent;
                var completed  = ParseUtil.CoerceInt(regexObj.Replace(completed2, ""));
                var qFiles     = row.QuerySelector("td:nth-of-type(3) > a");                                                                // Files
                var files      = qFiles != null?ParseUtil.CoerceInt(Regex.Match(qFiles.TextContent, @"\d+").Value) : 1;

                var humanSize    = row.QuerySelector("td:nth-of-type(7)").TextContent.ToLowerInvariant();                                 // Size
                var size         = ParseUtil.GetBytes(humanSize);                                                                         // Date
                var dateTimeOrig = row.QuerySelector("td:nth-of-type(5)").TextContent;
                var dateTime     = Regex.Replace(dateTimeOrig, @"<[^>]+>|&nbsp;", "").Trim();
                var date         = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
                var details      = new Uri(torrentDetailsUrl.Replace("{id}", id.ToString()));                                               // Description Link
                var passkey      = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(2)").GetAttribute("href");                          // Download Link
                var key          = Regex.Match(passkey, "(?<=passkey\\=)([a-zA-z0-9]*)");
                var downloadLink = new Uri(torrentDownloadUrl.Replace("{id}", id.ToString()).Replace("{passkey}", key.ToString()));

                // Building release infos
                var release = new TorrentInfo
                {
                    Categories      = _categories.MapTrackerCatToNewznab(cat),
                    Title           = name,
                    Seeders         = seeders,
                    Peers           = seeders + leechers,
                    PublishDate     = date,
                    Size            = size,
                    Files           = files,
                    Grabs           = completed,
                    Guid            = details.AbsoluteUri,
                    InfoUrl         = details.AbsoluteUri,
                    DownloadUrl     = downloadLink.AbsoluteUri,
                    MinimumRatio    = 1,
                    MinimumSeedTime = 172800 // 48 hours
                };

                var genres = row.QuerySelector("span.genres")?.TextContent;
                if (!string.IsNullOrEmpty(genres))
                {
                    release.Description = genres;
                }

                // IMDB
                var imdbLink = row.QuerySelector("a[href*=\"imdb.com/title/tt\"]")?.GetAttribute("href");
                release.ImdbId = ParseUtil.GetImdbID(imdbLink) ?? 0;

                if (row.QuerySelector("img[title=\"100% freeleech\"]") != null)
                {
                    release.DownloadVolumeFactor = 0;
                }
                else if (row.QuerySelector("img[title=\"Halfleech\"]") != null)
                {
                    release.DownloadVolumeFactor = 0.5;
                }
                else if (row.QuerySelector("img[title=\"90% Freeleech\"]") != null)
                {
                    release.DownloadVolumeFactor = 0.1;
                }
                else
                {
                    release.DownloadVolumeFactor = 1;
                }

                release.UploadVolumeFactor = 1;

                torrentInfos.Add(release);
            }

            return(torrentInfos.ToArray());
        }
Esempio n. 28
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_list > tbody > tr");

            foreach (var row in rows.Skip(1))
            {
                var qTitleLink = row.QuerySelector("a[href*=\"?page=torrent-details\"]");

                // no results
                if (qTitleLink == null)
                {
                    continue;
                }

                var title = qTitleLink.TextContent.Trim();
                title += " SPANiSH"; // fix for Radarr
                title  = Regex.Replace(title, "4k", "2160p", RegexOptions.IgnoreCase);

                var detailsStr = qTitleLink.GetAttribute("href");
                var details    = new Uri(detailsStr);
                var link       = new Uri(detailsStr.Replace("/index.php?page=torrent-details&", "/download.php?"));
                var qPoster    = qTitleLink.GetAttribute("title");
                var poster     = qPoster != null ? new Uri(qPoster) : null;

                var publishDateStr = row.Children[4].InnerHtml.Split('>').Last();
                var publishDate    = DateTime.ParseExact(publishDateStr, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                var size           = ParseUtil.GetBytes(row.Children[5].TextContent.Replace(".", "").Replace(",", "."));
                var seeders        = ParseUtil.CoerceInt(row.Children[6].TextContent);
                var leechers       = ParseUtil.CoerceInt(row.Children[7].TextContent);
                var grabs          = ParseUtil.CoerceInt(row.Children[8].TextContent);

                var cat1 = row.Children[0].FirstElementChild.GetAttribute("href").Split('=').Last();
                var cat2 = row.Children[1].FirstElementChild.GetAttribute("href").Split('=').Last();
                var cat  = _categories.MapTrackerCatToNewznab($"cat[]={cat1}&subcat[]={cat2}");

                var dlVolumeFactor = row.QuerySelector("img[src*=\"/gold.png\"]") != null ? 0 :
                                     row.QuerySelector("img[src*=\"/silver.png\"]") != null ? 0.5 : 1;
                var ulVolumeFactor = row.QuerySelector("img[src*=\"/por3.gif\"]") != null ? 3 :
                                     row.QuerySelector("img[src*=\"/por2.gif\"]") != null ? 2 : 1;

                var release = new TorrentInfo
                {
                    Title                = title,
                    InfoUrl              = details.AbsoluteUri,
                    Guid                 = details.AbsoluteUri,
                    DownloadUrl          = link.AbsoluteUri,
                    PosterUrl            = poster.AbsoluteUri,
                    PublishDate          = publishDate,
                    Categories           = cat,
                    Size                 = size,
                    Grabs                = grabs,
                    Seeders              = seeders,
                    Peers                = seeders + leechers,
                    DownloadVolumeFactor = dlVolumeFactor,
                    UploadVolumeFactor   = ulVolumeFactor,
                    MinimumRatio         = 1,
                    MinimumSeedTime      = 259200 // 72 hours
                };

                torrentInfos.Add(release);
            }

            return(torrentInfos.ToArray());
        }