private async Task <List <ReleaseResource> > GetSearchReleases([FromQuery] SearchResource payload)
        {
            try
            {
                var request = new NewznabRequest
                {
                    q      = payload.Query,
                    t      = payload.Type,
                    source = "Prowlarr",
                    cat    = string.Join(",", payload.Categories),
                    server = Request.GetServerUrl(),
                    host   = Request.GetHostName(),
                    limit  = payload.Limit,
                    offset = payload.Offset
                };

                request.QueryToParams();

                var result = await _nzbSearhService.Search(request, payload.IndexerIds, true);

                var decisions = result.Releases;

                return(MapDecisions(decisions, Request.GetServerUrl()));
            }
            catch (SearchFailedException ex)
            {
                throw new NzbDroneClientException(HttpStatusCode.BadRequest, ex.Message);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Search failed: " + ex.Message);
            }

            return(new List <ReleaseResource>());
        }
Beispiel #2
0
        public static ReleaseInfo ToModel(this SearchResource resource)
        {
            ReleaseInfo model;

            if (resource.Protocol == DownloadProtocol.Torrent)
            {
                model = new TorrentInfo
                {
                    MagnetUrl = resource.MagnetUrl,
                    InfoHash  = resource.InfoHash,
                    Seeders   = resource.Seeders,
                    Peers     = (resource.Seeders.HasValue && resource.Leechers.HasValue) ? (resource.Seeders + resource.Leechers) : null
                };
            }
            else
            {
                model = new ReleaseInfo();
            }

            model.Guid             = resource.Guid;
            model.Title            = resource.Title;
            model.Size             = resource.Size;
            model.DownloadUrl      = resource.DownloadUrl;
            model.InfoUrl          = resource.InfoUrl;
            model.PosterUrl        = resource.PosterUrl;
            model.CommentUrl       = resource.CommentUrl;
            model.IndexerId        = resource.IndexerId;
            model.Indexer          = resource.Indexer;
            model.DownloadProtocol = resource.Protocol;
            model.ImdbId           = resource.ImdbId;
            model.PublishDate      = resource.PublishDate.ToUniversalTime();

            return(model);
        }
 public Task <List <ReleaseResource> > GetAll([FromQuery] SearchResource payload)
 {
     return(GetSearchReleases(payload));
 }