예제 #1
0
        /// <summary>
        /// Execute our search query
        /// </summary>
        /// <param name="query">Query</param>
        /// <returns>Releases</returns>
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases   = new List <ReleaseInfo>();
            var searchTerm = query.GetEpisodeSearchString() + " " + query.SanitizedSearchTerm; // use episode search string first, see issue #1202

            searchTerm = searchTerm.Trim();
            searchTerm = searchTerm.ToLower();

            if (EnhancedAnime && query.HasSpecifiedCategories && (query.Categories.Contains(TorznabCatType.TVAnime.ID) || query.Categories.Contains(100032) || query.Categories.Contains(100101) || query.Categories.Contains(100110)))
            {
                var regex = new Regex(" ([0-9]+)");
                searchTerm = regex.Replace(searchTerm, " E$1");
            }

            // Check cache first so we don't query the server (if search term used or not in dev mode)
            if (!DevMode && !string.IsNullOrEmpty(searchTerm))
            {
                lock (cache)
                {
                    // Remove old cache items
                    CleanCache();

                    // Search in cache
                    var cachedResult = cache.FirstOrDefault(i => i.Query == searchTerm);
                    if (cachedResult != null)
                    {
                        return(cachedResult.Results.Select(s => (ReleaseInfo)s.Clone()).ToArray());
                    }
                }
            }

            // Build our query
            var request = BuildQuery(searchTerm, query, ApiEndpoint);

            // Getting results & Store content
            var results = await QueryExec(request);

            try
            {
                // Deserialize our Json Response
                var xthorResponse = JsonConvert.DeserializeObject <XthorResponse>(results);

                // Check Tracker's State
                CheckApiState(xthorResponse.error);

                // If contains torrents
                if (xthorResponse.torrents != null)
                {
                    // Adding each torrent row to releases
                    releases.AddRange(xthorResponse.torrents.Select(torrent =>
                    {
                        //issue #3847 replace multi keyword
                        if (!string.IsNullOrEmpty(ReplaceMulti))
                        {
                            var regex    = new Regex("(?i)([\\.\\- ])MULTI([\\.\\- ])");
                            torrent.name = regex.Replace(torrent.name, "$1" + ReplaceMulti + "$2");
                        }

                        var publishDate = DateTimeUtil.UnixTimestampToDateTime(torrent.added);
                        //TODO replace with download link?
                        var guid     = new Uri(TorrentDescriptionUrl.Replace("{id}", torrent.id.ToString()));
                        var comments = new Uri(TorrentCommentUrl.Replace("{id}", torrent.id.ToString()));
                        var link     = new Uri(torrent.download_link);
                        var release  = new ReleaseInfo
                        {
                            // Mapping data
                            Category             = 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,
                            Comments             = comments,
                            Link                 = link,
                            TMDb                 = torrent.tmdb_id
                        };

                        //TODO make consistent with other trackers
                        if (DevMode)
                        {
                            Output(release.ToString());
                        }

                        return(release);
                    }));
                }
            }
            catch (Exception ex)
            {
                OnParseError("Unable to parse result \n" + ex.StackTrace, ex);
            }

            // Return found releases
            return(releases);
        }
예제 #2
0
파일: Xthor.cs 프로젝트: ilkerhalil/Jackett
        /// <summary>
        /// Execute our search query
        /// </summary>
        /// <param name="query">Query</param>
        /// <returns>Releases</returns>
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases   = new List <ReleaseInfo>();
            var searchTerm = query.GetQueryString();

            // Check cache first so we don't query the server (if search term used or not in dev mode)
            if (!DevMode && !string.IsNullOrEmpty(searchTerm))
            {
                lock (cache)
                {
                    // Remove old cache items
                    CleanCache();

                    // Search in cache
                    var cachedResult = cache.FirstOrDefault(i => i.Query == searchTerm);
                    if (cachedResult != null)
                    {
                        return(cachedResult.Results.Select(s => (ReleaseInfo)s.Clone()).ToArray());
                    }
                }
            }

            // Build our query
            var request = BuildQuery(searchTerm, query, ApiEndpoint);

            // Getting results & Store content
            var results = await QueryExec(request);

            try
            {
                // Deserialize our Json Response
                var xthorResponse = JsonConvert.DeserializeObject <XthorResponse>(results.Content);

                // Check Tracker's State
                CheckApiState(xthorResponse.error);

                // If contains torrents
                if (xthorResponse.torrents != null)
                {
                    // Adding each torrent row to releases
                    releases.AddRange(xthorResponse.torrents.Select(torrent => new ReleaseInfo
                    {
                        // Mapping data
                        Category             = MapTrackerCatToNewznab(torrent.category.ToString()),
                        Title                = torrent.name, Seeders = torrent.seeders,
                        Peers                = torrent.seeders + torrent.leechers,
                        MinimumRatio         = 1,
                        MinimumSeedTime      = 345600,
                        PublishDate          = DateTimeUtil.UnixTimestampToDateTime(torrent.added),
                        Size                 = torrent.size,
                        Grabs                = torrent.times_completed,
                        Files                = torrent.numfiles,
                        UploadVolumeFactor   = 1,
                        DownloadVolumeFactor = (torrent.freeleech == 1 ? 0 : 1),
                        Guid                 = new Uri(TorrentDescriptionUrl.Replace("{id}", torrent.id.ToString())),
                        Comments             = new Uri(TorrentCommentUrl.Replace("{id}", torrent.id.ToString())),
                        Link                 = new Uri(torrent.download_link)
                    }));
                }
            }
            catch (Exception ex)
            {
                OnParseError("Error, unable to parse result \n" + ex.StackTrace, ex);
            }

            // Return found releases
            return(releases);
        }