示例#1
0
        public Author GetAuthorInfo(string foreignAuthorId)
        {
            _logger.Debug("Getting Author details ReadarrAPI.MetadataID of {0}", foreignAuthorId);

            var httpRequest = _requestBuilder.GetRequestBuilder().Create()
                              .SetSegment("route", $"author/{foreignAuthorId}")
                              .Build();

            httpRequest.AllowAutoRedirect = true;
            httpRequest.SuppressHttpError = true;

            var httpResponse = _httpClient.Get <AuthorResource>(httpRequest);

            if (httpResponse.HasHttpError)
            {
                if (httpResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new AuthorNotFoundException(foreignAuthorId);
                }
                else if (httpResponse.StatusCode == HttpStatusCode.BadRequest)
                {
                    throw new BadRequestException(foreignAuthorId);
                }
                else
                {
                    throw new HttpException(httpRequest, httpResponse);
                }
            }

            return(MapAuthor(httpResponse.Resource));
        }
        private IEnumerable <ImportListRequest> GetPagedRequests()
        {
            var request = _requestBulder.GetRequestBuilder()
                          .Create()
                          .SetSegment("route", "chart/" + Settings.ListId)
                          .Build();

            yield return(new ImportListRequest(request));
        }
示例#3
0
        public HashSet <string> GetChangedAuthors(DateTime startTime)
        {
            var httpRequest = _requestBuilder.GetRequestBuilder().Create()
                              .SetSegment("route", "author/changed")
                              .AddQueryParam("since", startTime.ToString("o"))
                              .Build();

            httpRequest.SuppressHttpError = true;

            var httpResponse = _httpClient.Get <RecentUpdatesResource>(httpRequest);

            if (httpResponse.Resource.Limited)
            {
                return(null);
            }

            return(new HashSet <string>(httpResponse.Resource.Ids.Select(x => x.ToString())));
        }
示例#4
0
        public Artist GetArtistInfo(string foreignArtistId, int metadataProfileId)
        {
            _logger.Debug("Getting Artist with GamearrAPI.MetadataID of {0}", foreignArtistId);

            var httpRequest = _requestBuilder.GetRequestBuilder().Create()
                              .SetSegment("route", "artist/" + foreignArtistId)
                              .Build();

            httpRequest.AllowAutoRedirect = true;
            httpRequest.SuppressHttpError = true;

            var httpResponse = _httpClient.Get <ArtistResource>(httpRequest);


            if (httpResponse.HasHttpError)
            {
                if (httpResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new ArtistNotFoundException(foreignArtistId);
                }
                else if (httpResponse.StatusCode == HttpStatusCode.BadRequest)
                {
                    throw new BadRequestException(foreignArtistId);
                }
                else
                {
                    throw new HttpException(httpRequest, httpResponse);
                }
            }

            var artist = new Artist();

            artist.Metadata  = MapArtistMetadata(httpResponse.Resource);
            artist.CleanName = Parser.Parser.CleanArtistName(artist.Metadata.Value.Name);
            artist.SortName  = Parser.Parser.NormalizeTitle(artist.Metadata.Value.Name);

            artist.Albums = FilterAlbums(httpResponse.Resource.Albums, metadataProfileId)
                            .Select(x => MapAlbum(x, null)).ToList();

            return(artist);
        }
示例#5
0
        public HashSet <string> GetChangedArtists(DateTime startTime)
        {
            var startTimeUtc = (DateTimeOffset)DateTime.SpecifyKind(startTime, DateTimeKind.Utc);
            var httpRequest  = _requestBuilder.GetRequestBuilder().Create()
                               .SetSegment("route", "recent/artist")
                               .AddQueryParam("since", startTimeUtc.ToUnixTimeSeconds())
                               .Build();

            httpRequest.SuppressHttpError = true;

            var httpResponse = _httpClient.Get <RecentUpdatesResource>(httpRequest);

            if (httpResponse.Resource.Limited)
            {
                return(null);
            }

            return(new HashSet <string>(httpResponse.Resource.Items));
        }
        public IList <SpotifyImportListItemInfo> MapSpotifyReleases(IList <SpotifyImportListItemInfo> items)
        {
            // first pass bulk lookup, server won't do search
            var spotifyIds = items.Select(x => x.ArtistSpotifyId)
                             .Concat(items.Select(x => x.AlbumSpotifyId))
                             .Where(x => x.IsNotNullOrWhiteSpace())
                             .Distinct();
            var httpRequest = _requestBuilder.GetRequestBuilder().Create()
                              .SetSegment("route", "spotify/lookup")
                              .Build();

            httpRequest.SetContent(spotifyIds.ToJson());
            httpRequest.Headers.ContentType = "application/json";

            _logger.Trace($"Requesting maps for:\n{spotifyIds.ToJson()}");

            Dictionary <string, string> map;

            try
            {
                var httpResponse = _httpClient.Post <List <SpotifyMap> >(httpRequest);
                var mapList      = httpResponse.Resource;

                // Generate a mapping dictionary.
                // The API will return 0 to mean it has previously searched and can't find the item.
                // null means that it has never been searched before.
                map = mapList.Where(x => x.MusicbrainzId.IsNotNullOrWhiteSpace())
                      .ToDictionary(x => x.SpotifyId, x => x.MusicbrainzId);
            }
            catch (Exception e)
            {
                _logger.Error(e);
                map = new Dictionary <string, string>();
            }

            _logger.Trace("Got mapping:\n{0}", map.ToJson());

            foreach (var item in items)
            {
                if (item.AlbumSpotifyId.IsNotNullOrWhiteSpace())
                {
                    if (map.ContainsKey(item.AlbumSpotifyId))
                    {
                        item.AlbumMusicBrainzId = map[item.AlbumSpotifyId];
                    }
                    else
                    {
                        MapAlbumItem(item);
                    }
                }
                else if (item.ArtistSpotifyId.IsNotNullOrWhiteSpace())
                {
                    if (map.ContainsKey(item.ArtistSpotifyId))
                    {
                        item.ArtistMusicBrainzId = map[item.ArtistSpotifyId];
                    }
                    else
                    {
                        MapArtistItem(item);
                    }
                }
            }

            // Strip out items where mapped to not found
            return(items.Where(x => x.AlbumMusicBrainzId != "0" && x.ArtistMusicBrainzId != "0").ToList());
        }