예제 #1
0
        public static TorznabQuery ToTorznabQuery(ApiSearch request)
        {
            var stringQuery = new TorznabQuery();

            stringQuery.QueryType = "search";

            var queryStr = request.Query;

            if (queryStr != null)
            {
                var seasonMatch = Regex.Match(queryStr, @"S(\d{2,4})");
                if (seasonMatch.Success)
                {
                    stringQuery.Season = int.Parse(seasonMatch.Groups[1].Value);
                    queryStr           = queryStr.Remove(seasonMatch.Index, seasonMatch.Length);
                }

                var episodeMatch = Regex.Match(queryStr, @"E(\d{2,4}[A-Za-z]?)");
                if (episodeMatch.Success)
                {
                    stringQuery.Episode = episodeMatch.Groups[1].Value.TrimStart(new char[] { '0' });
                    queryStr            = queryStr.Remove(episodeMatch.Index, episodeMatch.Length);
                }
                queryStr = queryStr.Trim();
            }
            else
            {
                queryStr = ""; // empty string search is interpreted as null
            }

            stringQuery.SearchTerm = queryStr;
            stringQuery.Categories = request.Category;
            if (stringQuery.Categories == null)
            {
                stringQuery.Categories = new int[0];
            }
            stringQuery.ExpandCatsToSubCats();

            // try to build an IMDB Query (tt plus 6 to 8 digits)
            if (stringQuery.SanitizedSearchTerm.StartsWith("tt") && stringQuery.SanitizedSearchTerm.Length <= 10)
            {
                var          imdbID    = ParseUtil.GetFullImdbID(stringQuery.SanitizedSearchTerm);
                TorznabQuery imdbQuery = null;
                if (imdbID != null)
                {
                    imdbQuery = new TorznabQuery()
                    {
                        ImdbID     = imdbID,
                        Categories = stringQuery.Categories,
                        Season     = stringQuery.Season,
                        Episode    = stringQuery.Episode,
                    };
                    imdbQuery.ExpandCatsToSubCats();

                    return(imdbQuery);
                }
            }

            return(stringQuery);
        }
예제 #2
0
        public static TorznabQuery ToTorznabQuery(TorznabRequest request)
        {
            var query = new TorznabQuery()
            {
                QueryType  = "search",
                SearchTerm = request.q,
                ImdbID     = request.imdbid,
                Episode    = request.ep,
            };

            if (request.t != null)
            {
                query.QueryType = request.t;
            }
            if (!request.extended.IsNullOrEmptyOrWhitespace())
            {
                query.Extended = ParseUtil.CoerceInt(request.extended);
            }
            if (!request.limit.IsNullOrEmptyOrWhitespace())
            {
                query.Limit = ParseUtil.CoerceInt(request.limit);
            }
            if (!request.offset.IsNullOrEmptyOrWhitespace())
            {
                query.Offset = ParseUtil.CoerceInt(request.offset);
            }

            if (request.cat != null)
            {
                query.Categories = request.cat.Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => int.Parse(s)).ToArray();
            }
            else
            {
                if (query.QueryType == "movie" && !string.IsNullOrWhiteSpace(request.imdbid))
                {
                    query.Categories = new int[] { TorznabCatType.Movies.ID }
                }
                ;
                else
                {
                    query.Categories = new int[0];
                }
            }

            if (!request.rid.IsNullOrEmptyOrWhitespace())
            {
                query.RageID = int.Parse(request.rid);
            }

            if (!request.season.IsNullOrEmptyOrWhitespace())
            {
                query.Season = int.Parse(request.season);
            }

            query.ExpandCatsToSubCats();

            return(query);
        }
예제 #3
0
        public static TorznabQuery ToTorznabQuery(ApiSearch request)
        {
            var stringQuery = new TorznabQuery();

            var queryStr = request.Query;

            if (queryStr != null)
            {
                var seasonMatch = Regex.Match(queryStr, @"S(\d{2,4})");
                if (seasonMatch.Success)
                {
                    stringQuery.Season = int.Parse(seasonMatch.Groups[1].Value);
                    queryStr           = queryStr.Remove(seasonMatch.Index, seasonMatch.Length);
                }

                var episodeMatch = Regex.Match(queryStr, @"E(\d{2,4}[A-Za-z]?)");
                if (episodeMatch.Success)
                {
                    stringQuery.Episode = episodeMatch.Groups[1].Value;
                    queryStr            = queryStr.Remove(episodeMatch.Index, episodeMatch.Length);
                }
                queryStr = queryStr.Trim();
            }


            stringQuery.SearchTerm = queryStr;
            stringQuery.Categories = request.Category == 0 ? new int[0] : new int[1] {
                request.Category
            };
            stringQuery.ExpandCatsToSubCats();

            // try to build an IMDB Query
            var          imdbID    = ParseUtil.GetFullImdbID(stringQuery.SanitizedSearchTerm);
            TorznabQuery imdbQuery = null;

            if (imdbID != null)
            {
                imdbQuery = new TorznabQuery()
                {
                    ImdbID     = imdbID,
                    Categories = stringQuery.Categories,
                    Season     = stringQuery.Season,
                    Episode    = stringQuery.Episode,
                };
                imdbQuery.ExpandCatsToSubCats();

                return(imdbQuery);
            }

            return(stringQuery);
        }
예제 #4
0
        public static TorznabQuery ToTorznabQuery(TorrentPotatoRequest request)
        {
            var torznabQuery = new TorznabQuery()
            {
                Categories = new int[1] {
                    TorznabCatType.Movies.ID
                },
                SearchTerm = request.Search,
                ImdbID     = request.Imdbid,
                QueryType  = "TorrentPotato"
            };

            torznabQuery.ExpandCatsToSubCats();

            return(torznabQuery);
        }
예제 #5
0
        public static TorznabQuery ToTorznabQuery(TorznabRequest request)
        {
            var query = new TorznabQuery()
            {
                QueryType  = "search",
                SearchTerm = request.q,
                ImdbID     = request.imdbid,
                Episode    = request.ep,
            };

            if (request.t != null)
            {
                query.QueryType = request.t;
            }
            if (!string.IsNullOrWhiteSpace(request.extended))
            {
                query.Extended = ParseUtil.CoerceInt(request.extended);
            }
            if (!string.IsNullOrWhiteSpace(request.limit))
            {
                query.Limit = ParseUtil.CoerceInt(request.limit);
            }
            if (!string.IsNullOrWhiteSpace(request.offset))
            {
                query.Offset = ParseUtil.CoerceInt(request.offset);
            }

            if (request.cat != null)
            {
                query.Categories = request.cat.Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => int.Parse(s)).ToArray();
            }
            else
            {
                if (query.QueryType == "movie" && !string.IsNullOrWhiteSpace(request.imdbid))
                {
                    query.Categories = new int[] { TorznabCatType.Movies.ID }
                }
                ;
                else
                {
                    query.Categories = new int[0];
                }
            }

            if (!string.IsNullOrWhiteSpace(request.rid))
            {
                query.RageID = int.Parse(request.rid);
            }

            if (!string.IsNullOrWhiteSpace(request.season))
            {
                query.Season = int.Parse(request.season);
            }

            if (!string.IsNullOrWhiteSpace(request.album))
            {
                query.Album = request.album;
            }
            if (!string.IsNullOrWhiteSpace(request.artist))
            {
                query.Artist = request.artist;
            }
            if (!string.IsNullOrWhiteSpace(request.label))
            {
                query.Label = request.label;
            }
            if (!string.IsNullOrWhiteSpace(request.track))
            {
                query.Track = request.track;
            }
            if (!string.IsNullOrWhiteSpace(request.year))
            {
                query.Year = int.Parse(request.year);
            }
            if (!string.IsNullOrWhiteSpace(request.genre))
            {
                query.Genre = request.genre.Split(',');
            }

            query.ExpandCatsToSubCats();

            return(query);
        }
예제 #6
0
        public ManualSearchResult Search([FromBody] AdminSearch value)
        {
            var results = new List <TrackerCacheResult>();
            var query   = new TorznabQuery()
            {
                SearchTerm = value.Query,
                Categories = value.Category == 0 ? new int[0] : new int[1] {
                    value.Category
                }
            };

            query.ExpandCatsToSubCats();

            var trackers = indexerService.GetAllIndexers().Where(t => t.IsConfigured).ToList();

            if (!string.IsNullOrWhiteSpace(value.Tracker))
            {
                trackers = trackers.Where(t => t.ID == value.Tracker).ToList();
            }

            if (value.Category != 0)
            {
                trackers = trackers.Where(t => t.TorznabCaps.Categories.Select(c => c.ID).Contains(value.Category)).ToList();
            }

            Parallel.ForEach(trackers.ToList(), indexer =>
            {
                try
                {
                    var searchResults = indexer.PerformQuery(query).Result;
                    searchResults     = indexer.CleanLinks(searchResults);
                    cacheService.CacheRssResults(indexer, searchResults);
                    searchResults = indexer.FilterResults(query, searchResults);

                    lock (results)
                    {
                        foreach (var result in searchResults)
                        {
                            var item       = Mapper.Map <TrackerCacheResult>(result);
                            item.Tracker   = indexer.DisplayName;
                            item.TrackerId = indexer.ID;
                            item.Peers     = item.Peers - item.Seeders; // Use peers as leechers
                            results.Add(item);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e, "An error occured during manual search on " + indexer.DisplayName + ":  " + e.Message);
                }
            });

            ConfigureCacheResults(results);

            if (trackers.Count > 1)
            {
                results = results.OrderByDescending(d => d.PublishDate).ToList();
            }

            var manualResult = new ManualSearchResult()
            {
                Results  = results,
                Indexers = trackers.Select(t => t.DisplayName).ToList()
            };


            if (manualResult.Indexers.Count == 0)
            {
                manualResult.Indexers = new List <string>()
                {
                    "None"
                }
            }
            ;

            logger.Info(string.Format("Manual search for \"{0}\" on {1} with {2} results.", query.GetQueryString(), string.Join(", ", manualResult.Indexers), manualResult.Results.Count));
            return(manualResult);
        }
    }
예제 #7
0
        public ManualSearchResult Search([FromBody] AdminSearch value)
        {
            var results     = new List <TrackerCacheResult>();
            var stringQuery = new TorznabQuery();

            var queryStr = value.Query;

            if (queryStr != null)
            {
                var seasonMatch = Regex.Match(queryStr, @"S(\d{2,4})");
                if (seasonMatch.Success)
                {
                    stringQuery.Season = int.Parse(seasonMatch.Groups[1].Value);
                    queryStr           = queryStr.Remove(seasonMatch.Index, seasonMatch.Length);
                }

                var episodeMatch = Regex.Match(queryStr, @"E(\d{2,4})");
                if (episodeMatch.Success)
                {
                    stringQuery.Episode = episodeMatch.Groups[1].Value;
                    queryStr            = queryStr.Remove(episodeMatch.Index, episodeMatch.Length);
                }
                queryStr = queryStr.Trim();
            }


            stringQuery.SearchTerm = queryStr;
            stringQuery.Categories = value.Category == 0 ? new int[0] : new int[1] {
                value.Category
            };
            stringQuery.ExpandCatsToSubCats();

            // try to build an IMDB Query
            var          imdbID    = ParseUtil.GetFullImdbID(stringQuery.SanitizedSearchTerm);
            TorznabQuery imdbQuery = null;

            if (imdbID != null)
            {
                imdbQuery = new TorznabQuery()
                {
                    ImdbID     = imdbID,
                    Categories = stringQuery.Categories,
                    Season     = stringQuery.Season,
                    Episode    = stringQuery.Episode,
                };
                imdbQuery.ExpandCatsToSubCats();
            }

            var trackers = indexerService.GetAllIndexers().Where(t => t.IsConfigured).ToList();

            if (!string.IsNullOrWhiteSpace(value.Tracker))
            {
                trackers = trackers.Where(t => t.ID == value.Tracker).ToList();
            }

            if (value.Category != 0)
            {
                trackers = trackers.Where(t => t.TorznabCaps.Categories.Select(c => c.ID).Contains(value.Category)).ToList();
            }

            Parallel.ForEach(trackers.ToList(), indexer =>
            {
                try
                {
                    var query = stringQuery;
                    // use imdb Query for trackers which support it
                    if (imdbQuery != null && indexer.TorznabCaps.SupportsImdbSearch)
                    {
                        query = imdbQuery;
                    }

                    var searchResults = indexer.PerformQuery(query).Result;
                    searchResults     = indexer.CleanLinks(searchResults);
                    cacheService.CacheRssResults(indexer, searchResults);
                    searchResults = indexer.FilterResults(query, searchResults);

                    lock (results)
                    {
                        foreach (var result in searchResults)
                        {
                            var item       = Mapper.Map <TrackerCacheResult>(result);
                            item.Tracker   = indexer.DisplayName;
                            item.TrackerId = indexer.ID;
                            item.Peers     = item.Peers - item.Seeders; // Use peers as leechers
                            results.Add(item);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e, "An error occured during manual search on " + indexer.DisplayName + ":  " + e.Message);
                }
            });

            ConfigureCacheResults(results);

            if (trackers.Count > 1)
            {
                results = results.OrderByDescending(d => d.PublishDate).ToList();
            }

            var manualResult = new ManualSearchResult()
            {
                Results  = results,
                Indexers = trackers.Select(t => t.DisplayName).ToList()
            };


            if (manualResult.Indexers.Count == 0)
            {
                manualResult.Indexers = new List <string>()
                {
                    "None"
                }
            }
            ;

            logger.Info(string.Format("Manual search for \"{0}\" on {1} with {2} results.", stringQuery.GetQueryString(), string.Join(", ", manualResult.Indexers), manualResult.Results.Count));
            return(manualResult);
        }
    }