Example #1
0
        /// <summary>
        /// Returns the artist that produced the album
        /// </summary>
        /// <param name="foreignArtistId"></param>
        /// <returns></returns>
        public async Task <ArtistResult> GetAlbumArtist(string foreignArtistId)
        {
            var settings = await GetSettings();

            return(await _lidarrApi.GetArtistByForeignId(foreignArtistId, settings.ApiKey, settings.FullUri));
        }
Example #2
0
        private async Task <SenderResult> SendToLidarr(AlbumRequest model, LidarrSettings settings)
        {
            var qualityToUse = int.Parse(settings.DefaultQualityProfile);
            //if (model.QualityOverride > 0)
            //{
            //    qualityToUse = model.QualityOverride;
            //}

            var rootFolderPath = /*model.RootPathOverride <= 0 ?*/ settings.DefaultRootPath /*: await RadarrRootPath(model.RootPathOverride, settings)*/;

            // Need to get the artist
            var artist = await _lidarrApi.GetArtistByForeignId(model.ForeignArtistId, settings.ApiKey, settings.FullUri);

            if (artist == null || artist.id <= 0)
            {
                // Create artist
                var newArtist = new ArtistAdd
                {
                    foreignArtistId = model.ForeignArtistId,
                    addOptions      = new Addoptions
                    {
                        monitored = true,
                        searchForMissingAlbums = false,
                        selectedOption         = 6, // None
                        AlbumsToMonitor        = new[] { model.ForeignAlbumId }
                    },
                    added             = DateTime.Now,
                    monitored         = true,
                    albumFolder       = settings.AlbumFolder,
                    artistName        = model.ArtistName,
                    cleanName         = model.ArtistName.ToLowerInvariant().RemoveSpaces(),
                    images            = new Image[] { },
                    languageProfileId = settings.LanguageProfileId,
                    links             = new Link[] {},
                    metadataProfileId = settings.MetadataProfileId,
                    qualityProfileId  = qualityToUse,
                    rootFolderPath    = rootFolderPath,
                };

                var result = await _lidarrApi.AddArtist(newArtist, settings.ApiKey, settings.FullUri);

                if (result != null && result.id > 0)
                {
                    // Search for it
                    if (!settings.AddOnly)
                    {
                        // get the album
                        var album = await _lidarrApi.GetAllAlbumsByArtistId(result.id, settings.ApiKey, settings.FullUri);

                        var albumToSearch = album.FirstOrDefault(x =>
                                                                 x.foreignAlbumId.Equals(model.ForeignAlbumId, StringComparison.InvariantCultureIgnoreCase));
                        var maxRetryCount = 10; // 5 seconds
                        var currentRetry  = 0;
                        while (albumToSearch != null)
                        {
                            if (currentRetry >= maxRetryCount)
                            {
                                break;
                            }
                            currentRetry++;
                            await Task.Delay(500);

                            album = await _lidarrApi.GetAllAlbumsByArtistId(result.id, settings.ApiKey, settings.FullUri);

                            albumToSearch = album.FirstOrDefault(x =>
                                                                 x.foreignAlbumId.Equals(model.ForeignAlbumId, StringComparison.InvariantCultureIgnoreCase));
                        }


                        if (albumToSearch != null)
                        {
                            await _lidarrApi.AlbumSearch(new[] { albumToSearch.id }, settings.ApiKey, settings.FullUri);
                        }
                    }
                    return(new SenderResult {
                        Message = "Album has been requested!", Sent = true, Success = true
                    });
                }
            }
            else
            {
                SenderResult result = await SetupAlbum(model, artist, settings);

                return(result);
            }

            return(new SenderResult {
                Success = false, Sent = false, Message = "Album is already monitored"
            });
        }
Example #3
0
        public async Task <ArtistInformation> GetArtistInformation(string artistId)
        {
            var artist = await _musicBrainzApi.GetArtistInformation(artistId);

            var lidarrSettings = await GetLidarrSettings();

            Task <ArtistResult> lidarrArtistTask = null;

            if (lidarrSettings.Enabled)
            {
                lidarrArtistTask = _lidarrApi.GetArtistByForeignId(artistId, lidarrSettings.ApiKey, lidarrSettings.FullUri);
            }

            var info = new ArtistInformation
            {
                Id             = artistId,
                Name           = artist.Name,
                Country        = artist.Country,
                Region         = artist.Area?.Name,
                Type           = artist.Type,
                StartYear      = artist.LifeSpan?.Begin ?? "",
                EndYear        = artist.LifeSpan?.End ?? "",
                Disambiguation = artist.Disambiguation,
                ReleaseGroups  = new List <ReleaseGroup>(),
                Members        = new List <BandMember>()
            };

            foreach (var g in artist.ReleaseGroups)
            {
                var release = new ReleaseGroup
                {
                    ReleaseType = g.PrimaryType,
                    Id          = g.Id,
                    Title       = g.Title,
                    ReleaseDate = g.FirstReleaseDate,
                };

                await RunSearchRules(release);

                info.ReleaseGroups.Add(release);
            }

            info.Links   = GetLinksForArtist(artist);
            info.Members = GetBandMembers(artist);

            if (lidarrArtistTask != null)
            {
                try
                {
                    var artistResult = await lidarrArtistTask;
                    info.Banner   = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("banner", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl();
                    info.Logo     = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("logo", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl();
                    info.Poster   = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("poster", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl();
                    info.FanArt   = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("fanart", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl();
                    info.Overview = artistResult.overview;
                }
                catch (JsonSerializationException)
                {
                    // swallow, Lidarr probably doesn't have this artist
                }
            }

            return(info);
        }