private int ScoreFlags(IndexerFlags flags) { var flagValues = Enum.GetValues(typeof(IndexerFlags)); var score = 0; foreach (IndexerFlags value in flagValues) { if ((flags & value) == value) { switch (value) { case IndexerFlags.G_DoubleUpload: case IndexerFlags.G_Freeleech: case IndexerFlags.PTP_Approved: case IndexerFlags.PTP_Golden: case IndexerFlags.HDB_Internal: score += 2; break; case IndexerFlags.G_Halfleech: score += 1; break; } } } return(score); }
protected IndexerFlags GetFlags(XElement item) { IndexerFlags flags = 0; var downloadFactor = TryGetFloatTorznabAttribute(item, "downloadvolumefactor", 1); var uploadFactor = TryGetFloatTorznabAttribute(item, "uploadvolumefactor", 1); if (uploadFactor == 2) { flags |= IndexerFlags.G_DoubleUpload; } if (downloadFactor == 0.5) { flags |= IndexerFlags.G_Halfleech; } if (downloadFactor == 0.0) { flags |= IndexerFlags.G_Freeleech; } return(flags); }
protected IndexerFlags GetFlags(XElement item) { IndexerFlags flags = 0; var description = item.TryGetValue("description"); if (description.ContainsIgnoreCase(IndexerFlags.G_Scene.ToString())) { flags |= IndexerFlags.G_Scene; } var downloadFactor = TryGetFloatTorznabAttribute(item, "downloadvolumefactor", 1); var uploadFactor = TryGetFloatTorznabAttribute(item, "uploadvolumefactor", 1); if (uploadFactor == 2) { flags |= IndexerFlags.G_DoubleUpload; } if (downloadFactor == 0.5) { flags |= IndexerFlags.G_Halfleech; } if (downloadFactor == 0.0) { flags |= IndexerFlags.G_Freeleech; } return(flags); }
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 queryResults = JsonConvert.DeserializeObject <List <FileListTorrent> >(indexerResponse.Content); foreach (var result in queryResults) { var id = result.Id; IndexerFlags flags = 0; if (result.FreeLeech) { flags |= IndexerFlags.G_Freeleech; } var imdbId = 0; if (result.ImdbId != null && result.ImdbId.Length > 2) { imdbId = int.Parse(result.ImdbId.Substring(2)); } torrentInfos.Add(new TorrentInfo() { Guid = string.Format("FileList-{0}", id), Title = result.Name, Size = result.Size, DownloadUrl = GetDownloadUrl(id), InfoUrl = GetInfoUrl(id), Seeders = result.Seeders, Peers = result.Leechers + result.Seeders, PublishDate = result.UploadDate, ImdbId = imdbId, IndexerFlags = flags }); } return(torrentInfos.ToArray()); }
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 xdoc = XDocument.Parse(indexerResponse.Content); var searchResults = xdoc.Descendants("searchresults").Select(x => new { AuthKey = x.Element("authkey").Value, }).FirstOrDefault(); var torrents = xdoc.Descendants("torrent") .Select(x => new { Id = x.Element("id").Value, Name = x.Element("name").Value, Year = x.Element("year").Value, GroupId = x.Element("groupid").Value, Time = DateTime.Parse(x.Element("time").Value), UserId = x.Element("userid").Value, Size = long.Parse(x.Element("size").Value), Snatched = x.Element("snatched").Value, Seeders = x.Element("seeders").Value, Leechers = x.Element("leechers").Value, ReleaseGroup = x.Element("releasegroup").Value, Resolution = x.Element("resolution").Value, Media = x.Element("media").Value, Format = x.Element("format").Value, Encoding = x.Element("encoding").Value, AudioFormat = x.Element("audioformat").Value, AudioBitrate = x.Element("audiobitrate").Value, AudioChannels = x.Element("audiochannels").Value, Subtitles = x.Element("subtitles").Value, EncodeStatus = x.Element("encodestatus").Value, Freeleech = x.Element("freeleech").Value, Internal = x.Element("internal").Value == "1", UserRelease = x.Element("userrelease").Value == "1", ImdbId = x.Element("imdb").Value }).ToList(); foreach (var torrent in torrents) { var id = torrent.Id; var title = $"{torrent.Name}.{torrent.Year}.{torrent.Resolution}.{torrent.Media}.{torrent.Encoding}.{torrent.AudioFormat}-{torrent.ReleaseGroup}"; IndexerFlags flags = 0; if (torrent.Freeleech == "0.00") { flags |= IndexerFlags.G_Freeleech; } if (torrent.Freeleech == "0.25") { flags |= IndexerFlags.G_Freeleech75; } if (torrent.Freeleech == "0.75") { flags |= IndexerFlags.G_Freeleech25; } if (torrent.Freeleech == "0.50") { flags |= IndexerFlags.G_Halfleech; } if (torrent.Internal) { flags |= IndexerFlags.AHD_Internal; } var imdbId = 0; if (torrent.ImdbId.Length > 2) { imdbId = int.Parse(torrent.ImdbId.Substring(2)); } torrentInfos.Add(new TorrentInfo() { Guid = string.Format("AwesomeHD-{0}", id), Title = title, Size = torrent.Size, DownloadUrl = GetDownloadUrl(id, searchResults.AuthKey, _settings.Passkey), InfoUrl = GetInfoUrl(torrent.GroupId, id), Seeders = int.Parse(torrent.Seeders), Peers = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders), PublishDate = torrent.Time.ToUniversalTime(), ImdbId = imdbId, IndexerFlags = flags, }); } } catch (XmlException) { throw new IndexerException(indexerResponse, "An error occurred while processing feed, feed invalid"); } return(torrentInfos.OrderByDescending(o => ((dynamic)o).Seeders).ToArray()); }
public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) { var torrentInfos = new List <ReleaseInfo>(); if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) { // Remove cookie cache AuthCookieCache.Remove(_settings.BaseUrl.Trim().TrimEnd('/')); throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request"); } if (indexerResponse.HttpResponse.Headers.ContentType != HttpAccept.Json.Value) { // Remove cookie cache AuthCookieCache.Remove(_settings.BaseUrl.Trim().TrimEnd('/')); throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}"); } var jsonResponse = JsonConvert.DeserializeObject <PassThePopcornResponse>(indexerResponse.Content); if (jsonResponse.TotalResults == "0" || jsonResponse.TotalResults.IsNullOrWhiteSpace() || jsonResponse.Movies == null) { return(torrentInfos); } foreach (var result in jsonResponse.Movies) { foreach (var torrent in result.Torrents) { var id = torrent.Id; var title = torrent.ReleaseName; IndexerFlags flags = 0; if (torrent.GoldenPopcorn) { flags |= IndexerFlags.PTP_Golden; //title = $"{title} 🍿"; } if (torrent.Checked) { flags |= IndexerFlags.PTP_Approved;//title = $"{title} ✔"; } if (torrent.FreeleechType == "Freeleech") { flags |= IndexerFlags.G_Freeleech; } // Only add approved torrents if (_settings.RequireApproved && torrent.Checked) { torrentInfos.Add(new PassThePopcornInfo() { Guid = string.Format("PassThePopcorn-{0}", id), Title = title, Size = long.Parse(torrent.Size), DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey), InfoUrl = GetInfoUrl(result.GroupId, id), Seeders = int.Parse(torrent.Seeders), Peers = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders), PublishDate = torrent.UploadTime.ToUniversalTime(), Golden = torrent.GoldenPopcorn, Scene = torrent.Scene, Approved = torrent.Checked, ImdbId = (result.ImdbId.IsNotNullOrWhiteSpace() ? int.Parse(result.ImdbId) : 0), IndexerFlags = flags }); } // Add all torrents else if (!_settings.RequireApproved) { torrentInfos.Add(new PassThePopcornInfo() { Guid = string.Format("PassThePopcorn-{0}", id), Title = title, Size = long.Parse(torrent.Size), DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey), InfoUrl = GetInfoUrl(result.GroupId, id), Seeders = int.Parse(torrent.Seeders), Peers = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders), PublishDate = torrent.UploadTime.ToUniversalTime(), Golden = torrent.GoldenPopcorn, Scene = torrent.Scene, Approved = torrent.Checked, ImdbId = (result.ImdbId.IsNotNullOrWhiteSpace() ? int.Parse(result.ImdbId) : 0), IndexerFlags = flags }); } // Don't add any torrents else if (_settings.RequireApproved && !torrent.Checked) { continue; } } } // prefer golden if (_settings.Golden) { if (_settings.Scene) { return (torrentInfos.OrderByDescending(o => o.PublishDate) .ThenBy(o => ((dynamic)o).Golden ? 0 : 1) .ThenBy(o => ((dynamic)o).Scene ? 0 : 1) .ToArray()); } return (torrentInfos.OrderByDescending(o => o.PublishDate) .ThenBy(o => ((dynamic)o).Golden ? 0 : 1) .ToArray()); } // prefer scene if (_settings.Scene) { return (torrentInfos.OrderByDescending(o => o.PublishDate) .ThenBy(o => ((dynamic)o).Scene ? 0 : 1) .ToArray()); } // order by date return (torrentInfos .OrderByDescending(o => o.PublishDate) .ToArray()); }
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; IndexerFlags flags = 0; if (result.FreeLeech == "yes") { flags |= IndexerFlags.G_Freeleech; } if (internalRelease) { flags |= IndexerFlags.HDB_Internal; } torrentInfos.Add(new HDBitsInfo() { Guid = string.Format("HDBits-{0}", id), Title = result.Name, Size = result.Size, InfoHash = result.Hash, DownloadUrl = GetDownloadUrl(id), InfoUrl = GetInfoUrl(id), Seeders = result.Seeders, Peers = result.Leechers + result.Seeders, PublishDate = result.Added.ToUniversalTime(), Internal = internalRelease, ImdbId = result.ImdbInfo?.Id ?? 0, IndexerFlags = flags }); } return(torrentInfos.ToArray()); }
public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) { var torrentInfos = new List <ReleaseInfo>(); if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) { // Remove cookie cache if (indexerResponse.HttpResponse.HasHttpRedirect && indexerResponse.HttpResponse.Headers["Location"] .ContainsIgnoreCase("login.php")) { CookiesUpdater(null, null); throw new IndexerException(indexerResponse, "We are being redirected to the PTP login page. Most likely your session expired or was killed. Try testing the indexer in the settings."); } throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request"); } if (indexerResponse.HttpResponse.Headers.ContentType != HttpAccept.Json.Value) { if (indexerResponse.HttpResponse.Request.Url.Path.ContainsIgnoreCase("login.php")) { CookiesUpdater(null, null); throw new IndexerException(indexerResponse, "We are currently on the login page. Most likely your session expired or was killed. Try testing the indexer in the settings."); } // Remove cookie cache throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}"); } var jsonResponse = JsonConvert.DeserializeObject <PassThePopcornResponse>(indexerResponse.Content); if (jsonResponse.TotalResults == "0" || jsonResponse.TotalResults.IsNullOrWhiteSpace() || jsonResponse.Movies == null) { return(torrentInfos); } foreach (var result in jsonResponse.Movies) { foreach (var torrent in result.Torrents) { var id = torrent.Id; var title = torrent.ReleaseName; IndexerFlags flags = 0; if (torrent.GoldenPopcorn) { flags |= IndexerFlags.PTP_Golden; //title = $"{title} 🍿"; } if (torrent.Checked) { flags |= IndexerFlags.PTP_Approved;//title = $"{title} ✔"; } if (torrent.FreeleechType == "Freeleech") { flags |= IndexerFlags.G_Freeleech; } if (torrent.Scene) { flags |= IndexerFlags.G_Scene; } // Only add approved torrents try { torrentInfos.Add(new PassThePopcornInfo() { Guid = string.Format("PassThePopcorn-{0}", id), Title = title, Size = long.Parse(torrent.Size), DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey), InfoUrl = GetInfoUrl(result.GroupId, id), Seeders = int.Parse(torrent.Seeders), Peers = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders), PublishDate = torrent.UploadTime.ToUniversalTime(), Golden = torrent.GoldenPopcorn, Scene = torrent.Scene, Approved = torrent.Checked, ImdbId = (result.ImdbId.IsNotNullOrWhiteSpace() ? int.Parse(result.ImdbId) : 0), IndexerFlags = flags }); } catch (Exception e) { _logger.Error(e, "Encountered exception parsing PTP torrent: {" + $"Size: {torrent.Size}" + $"UploadTime: {torrent.UploadTime}" + $"Seeders: {torrent.Seeders}" + $"Leechers: {torrent.Leechers}" + $"ReleaseName: {torrent.ReleaseName}" + $"ID: {torrent.Id}" + "}. Please immediately report this info on https://github.com/Radarr/Radarr/issues/1584."); throw; } } } return (torrentInfos); }