示例#1
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());
        }
示例#2
0
            public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
            {
                var torrentInfos = new List <ReleaseInfo>();

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

                if (jsonResponse.Resource.Status != "success" ||
                    jsonResponse.Resource.Status.IsNullOrWhiteSpace() ||
                    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;

                            // in SC movies, artist=director and GroupName=title
                            var artist = WebUtility.HtmlDecode(result.Artist);
                            var album  = WebUtility.HtmlDecode(result.GroupName);
                            var title  = WebUtility.HtmlDecode(result.GroupName);

                            var release = new GazelleInfo()
                            {
                                Guid        = string.Format("SecretCinema-{0}", id),
                                Title       = WebUtility.HtmlDecode(title),
                                Container   = torrent.Encoding,
                                Files       = torrent.FileCount,
                                Grabs       = torrent.Snatches,
                                Codec       = torrent.Format,
                                Size        = long.Parse(torrent.Size),
                                DownloadUrl = GetDownloadUrl(id),
                                InfoUrl     = GetInfoUrl(result.GroupId, id),
                                Seeders     = int.Parse(torrent.Seeders),
                                Peers       = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders),
                                PublishDate = torrent.Time.ToUniversalTime(),
                                Scene       = torrent.Scene,
                            };

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

                            if (IsAnyMovieCategory(release.Categories))
                            {
                                // Remove director from title
                                // SC API returns no more useful information than this
                                release.Title = $"{result.GroupName} ({result.GroupYear}) {torrent.Media}";

                                // Replace media formats with standards
                                release.Title = Regex.Replace(release.Title, "BDMV", "COMPLETE BLURAY", RegexOptions.IgnoreCase);
                                release.Title = Regex.Replace(release.Title, "SD", "DVDRip", RegexOptions.IgnoreCase);
                            }
                            else
                            {
                                // SC API currently doesn't return anything but title.
                                release.Title = $"{result.Artist} - {result.GroupName} ({result.GroupYear}) [{torrent.Format} {torrent.Encoding}] [{torrent.Media}]";
                            }

                            if (torrent.HasCue)
                            {
                                release.Title += " [Cue]";
                            }

                            torrentInfos.Add(release);
                        }
                    }
                    else
                    {
                        var id        = result.TorrentId;
                        var groupName = WebUtility.HtmlDecode(result.GroupName);

                        var release = new GazelleInfo()
                        {
                            Guid        = string.Format("SecretCinema-{0}", id),
                            Title       = groupName,
                            Size        = long.Parse(result.Size),
                            DownloadUrl = GetDownloadUrl(id),
                            InfoUrl     = GetInfoUrl(result.GroupId, id),
                            Seeders     = int.Parse(result.Seeders),
                            Peers       = int.Parse(result.Leechers) + int.Parse(result.Seeders),
                            Files       = result.FileCount,
                            Grabs       = result.Snatches,
                            PublishDate = DateTimeOffset.FromUnixTimeSeconds(result.GroupTime).UtcDateTime,
                        };

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

                        torrentInfos.Add(release);
                    }
                }

                // order by date
                return
                    (torrentInfos
                     .OrderByDescending(o => o.PublishDate)
                     .ToArray());
            }