Example #1
0
        public async Task <Models.DTO.TorrentPotatoResponse> Potato([FromUri] Models.DTO.TorrentPotatoRequest request)
        {
            var result = await CurrentIndexer.ResultsForQuery(CurrentQuery);

            // Cache non query results
            if (string.IsNullOrEmpty(CurrentQuery.SanitizedSearchTerm))
            {
                cacheService.CacheRssResults(CurrentIndexer, result.Releases);
            }

            // Log info
            if (string.IsNullOrWhiteSpace(CurrentQuery.SanitizedSearchTerm))
            {
                logger.Info($"Found {result.Releases.Count()} torrentpotato releases from {CurrentIndexer.DisplayName}");
            }
            else
            {
                logger.Info($"Found {result.Releases.Count()} torrentpotato releases from {CurrentIndexer.DisplayName} for: {CurrentQuery.GetQueryString()}");
            }

            var serverUrl      = serverService.GetServerUrl(Request);
            var potatoReleases = result.Releases.Where(r => r.Link != null || r.MagnetUri != null).Select(r =>
            {
                var release  = AutoMapper.Mapper.Map <ReleaseInfo>(r);
                release.Link = serverService.ConvertToProxyLink(release.Link, serverUrl, CurrentIndexer.ID, "dl", release.Title + ".torrent");
                var item     = new Models.DTO.TorrentPotatoResponseItem()
                {
                    release_name = release.Title + "[" + CurrentIndexer.DisplayName + "]", // Suffix the indexer so we can see which tracker we are using in CPS as it just says torrentpotato >.>
                    torrent_id   = release.Guid.ToString(),
                    details_url  = release.Comments.ToString(),
                    download_url = (release.Link != null ? release.Link.ToString() : release.MagnetUri.ToString()),
                    imdb_id      = release.Imdb.HasValue ? "tt" + release.Imdb : null,
                    freeleech    = (release.DownloadVolumeFactor == 0 ? true : false),
                    type         = "movie",
                    size         = (long)release.Size / (1024 * 1024), // This is in MB
                    leechers     = (int)release.Peers - (int)release.Seeders,
                    seeders      = (int)release.Seeders,
                    publish_date = r.PublishDate == DateTime.MinValue ? null : release.PublishDate.ToUniversalTime().ToString("s")
                };
                return(item);
            });

            var potatoResponse = new Models.DTO.TorrentPotatoResponse()
            {
                results = potatoReleases.ToList()
            };

            return(potatoResponse);
        }
Example #2
0
        public async Task <IHttpActionResult> Torznab([FromUri] Models.DTO.TorznabRequest request)
        {
            if (string.Equals(CurrentQuery.QueryType, "caps", StringComparison.InvariantCultureIgnoreCase))
            {
                return(ResponseMessage(new HttpResponseMessage()
                {
                    Content = new StringContent(CurrentIndexer.TorznabCaps.ToXml(), Encoding.UTF8, "application/xml")
                }));
            }

            if (CurrentQuery.ImdbID != null)
            {
                if (CurrentQuery.QueryType != "movie")
                {
                    logger.Warn($"A non movie request with an imdbid was made from {Request.GetOwinContext().Request.RemoteIpAddress}.");
                    return(GetErrorXML(201, "Incorrect parameter: only movie-search supports the imdbid parameter"));
                }

                if (!string.IsNullOrEmpty(CurrentQuery.SearchTerm))
                {
                    logger.Warn($"A movie-search request from {Request.GetOwinContext().Request.RemoteIpAddress} was made contining q and imdbid.");
                    return(GetErrorXML(201, "Incorrect parameter: please specify either imdbid or q"));
                }

                CurrentQuery.ImdbID = ParseUtil.GetFullImdbID(CurrentQuery.ImdbID); // normalize ImdbID
                if (CurrentQuery.ImdbID == null)
                {
                    logger.Warn($"A movie-search request from {Request.GetOwinContext().Request.RemoteIpAddress} was made with an invalid imdbid.");
                    return(GetErrorXML(201, "Incorrect parameter: invalid imdbid format"));
                }

                if (!CurrentIndexer.TorznabCaps.SupportsImdbSearch)
                {
                    logger.Warn($"A movie-search request with imdbid from {Request.GetOwinContext().Request.RemoteIpAddress} was made but the indexer {CurrentIndexer.DisplayName} doesn't support it.");
                    return(GetErrorXML(203, "Function Not Available: imdbid is not supported by this indexer"));
                }
            }

            var result = await CurrentIndexer.ResultsForQuery(CurrentQuery);

            // Some trackers do not support multiple category filtering so filter the releases that match manually.
            int?newItemCount = null;

            // Cache non query results
            if (string.IsNullOrEmpty(CurrentQuery.SanitizedSearchTerm))
            {
                newItemCount = cacheService.GetNewItemCount(CurrentIndexer, result.Releases);
                cacheService.CacheRssResults(CurrentIndexer, result.Releases);
            }

            // Log info
            var logBuilder = new StringBuilder();

            if (newItemCount != null)
            {
                logBuilder.AppendFormat("Found {0} ({1} new) releases from {2}", result.Releases.Count(), newItemCount, CurrentIndexer.DisplayName);
            }
            else
            {
                logBuilder.AppendFormat("Found {0} releases from {1}", result.Releases.Count(), CurrentIndexer.DisplayName);
            }

            if (!string.IsNullOrWhiteSpace(CurrentQuery.SanitizedSearchTerm))
            {
                logBuilder.AppendFormat(" for: {0}", CurrentQuery.GetQueryString());
            }

            logger.Info(logBuilder.ToString());

            var serverUrl  = serverService.GetServerUrl(Request);
            var resultPage = new ResultPage(new ChannelInfo
            {
                Title            = CurrentIndexer.DisplayName,
                Description      = CurrentIndexer.DisplayDescription,
                Link             = new Uri(CurrentIndexer.SiteLink),
                ImageUrl         = new Uri(serverUrl + "logos/" + CurrentIndexer.ID + ".png"),
                ImageTitle       = CurrentIndexer.DisplayName,
                ImageLink        = new Uri(CurrentIndexer.SiteLink),
                ImageDescription = CurrentIndexer.DisplayName
            });

            var proxiedReleases = result.Releases.Select(r => AutoMapper.Mapper.Map <ReleaseInfo>(r)).Select(r =>
            {
                r.Link = serverService.ConvertToProxyLink(r.Link, serverUrl, r.Origin.ID, "dl", r.Title + ".torrent");
                return(r);
            });

            resultPage.Releases = proxiedReleases.ToList();

            var xml = resultPage.ToXml(new Uri(serverUrl));

            // Force the return as XML
            return(ResponseMessage(new HttpResponseMessage()
            {
                Content = new StringContent(xml, Encoding.UTF8, "application/rss+xml")
            }));
        }
Example #3
0
        public async Task <IActionResult> Torznab([FromQuery] TorznabRequest request)
        {
            if (string.Equals(CurrentQuery.QueryType, "caps", StringComparison.InvariantCultureIgnoreCase))
            {
                return(Content(CurrentIndexer.TorznabCaps.ToXml(), "application/rss+xml", Encoding.UTF8));
            }

            // indexers - returns a list of all included indexers (meta indexers only)
            if (string.Equals(CurrentQuery.QueryType, "indexers", StringComparison.InvariantCultureIgnoreCase))
            {
                if (!(CurrentIndexer is BaseMetaIndexer)) // shouldn't be needed because CanHandleQuery should return false
                {
                    logger.Warn($"A search request with t=indexers from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.DisplayName} isn't a meta indexer.");
                    return(GetErrorXML(203, "Function Not Available: this isn't a meta indexer"));
                }
                var CurrentBaseMetaIndexer = (BaseMetaIndexer)CurrentIndexer;
                var indexers = CurrentBaseMetaIndexer.Indexers;
                if (string.Equals(request.configured, "true", StringComparison.InvariantCultureIgnoreCase))
                {
                    indexers = indexers.Where(i => i.IsConfigured);
                }
                else if (string.Equals(request.configured, "false", StringComparison.InvariantCultureIgnoreCase))
                {
                    indexers = indexers.Where(i => !i.IsConfigured);
                }

                var xdoc = new XDocument(
                    new XDeclaration("1.0", "UTF-8", null),
                    new XElement("indexers",
                                 from i in indexers
                                 select new XElement("indexer",
                                                     new XAttribute("id", i.ID),
                                                     new XAttribute("configured", i.IsConfigured),
                                                     new XElement("title", i.DisplayName),
                                                     new XElement("description", i.DisplayDescription),
                                                     new XElement("link", i.SiteLink),
                                                     new XElement("language", i.Language),
                                                     new XElement("type", i.Type),
                                                     i.TorznabCaps.GetXDocument().FirstNode
                                                     )
                                 )
                    );

                return(Content(xdoc.Declaration.ToString() + Environment.NewLine + xdoc.ToString(), "application/xml", Encoding.UTF8));
            }

            if (CurrentQuery.ImdbID != null)
            {
                if (!string.IsNullOrEmpty(CurrentQuery.SearchTerm))
                {
                    logger.Warn($"A search request from {Request.HttpContext.Connection.RemoteIpAddress} was made containing q and imdbid.");
                    return(GetErrorXML(201, "Incorrect parameter: please specify either imdbid or q"));
                }

                CurrentQuery.ImdbID = ParseUtil.GetFullImdbID(CurrentQuery.ImdbID); // normalize ImdbID
                if (CurrentQuery.ImdbID == null)
                {
                    logger.Warn($"A search request from {Request.HttpContext.Connection.RemoteIpAddress} was made with an invalid imdbid.");
                    return(GetErrorXML(201, "Incorrect parameter: invalid imdbid format"));
                }

                if (!CurrentIndexer.TorznabCaps.SupportsImdbSearch)
                {
                    logger.Warn($"A search request with imdbid from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.DisplayName} doesn't support it.");
                    return(GetErrorXML(203, "Function Not Available: imdbid is not supported by this indexer"));
                }
            }

            try
            {
                var result = await CurrentIndexer.ResultsForQuery(CurrentQuery);

                // Some trackers do not support multiple category filtering so filter the releases that match manually.
                int?newItemCount = null;

                // Cache non query results
                if (string.IsNullOrEmpty(CurrentQuery.SanitizedSearchTerm))
                {
                    newItemCount = cacheService.GetNewItemCount(CurrentIndexer, result.Releases);
                    cacheService.CacheRssResults(CurrentIndexer, result.Releases);
                }

                // Log info
                var logBuilder = new StringBuilder();
                if (newItemCount != null)
                {
                    logBuilder.AppendFormat("Found {0} ({1} new) releases from {2}", result.Releases.Count(), newItemCount, CurrentIndexer.DisplayName);
                }
                else
                {
                    logBuilder.AppendFormat("Found {0} releases from {1}", result.Releases.Count(), CurrentIndexer.DisplayName);
                }

                if (!string.IsNullOrWhiteSpace(CurrentQuery.SanitizedSearchTerm))
                {
                    logBuilder.AppendFormat(" for: {0}", CurrentQuery.GetQueryString());
                }

                logger.Info(logBuilder.ToString());

                var serverUrl  = serverService.GetServerUrl(Request);
                var resultPage = new ResultPage(new ChannelInfo
                {
                    Title            = CurrentIndexer.DisplayName,
                    Description      = CurrentIndexer.DisplayDescription,
                    Link             = new Uri(CurrentIndexer.SiteLink),
                    ImageUrl         = new Uri(serverUrl + "logos/" + CurrentIndexer.ID + ".png"),
                    ImageTitle       = CurrentIndexer.DisplayName,
                    ImageLink        = new Uri(CurrentIndexer.SiteLink),
                    ImageDescription = CurrentIndexer.DisplayName
                });

                var proxiedReleases = result.Releases.Select(r => AutoMapper.Mapper.Map <ReleaseInfo>(r)).Select(r =>
                {
                    r.Link = serverService.ConvertToProxyLink(r.Link, serverUrl, r.Origin.ID, "dl", r.Title);
                    return(r);
                });

                resultPage.Releases = proxiedReleases.ToList();

                var xml = resultPage.ToXml(new Uri(serverUrl));
                // Force the return as XML

                return(Content(xml, "application/rss+xml", Encoding.UTF8));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(GetErrorXML(900, ex.ToString()));
            }
        }