Beispiel #1
0
        /// <summary>Determines whether [is album art].</summary>
        /// <param name="imageType">Type of the image.</param>
        /// <returns><c>true</c> if [is album art] [the specified image type]; otherwise, <c>false</c>.</returns>
        public static bool IsAlbumArt(this MDBImageType imageType)
        {
            switch (imageType)
            {
            case MDBImageType.UserCover:
            case MDBImageType.AlbumCover:
            case MDBImageType.AlbumCDArt:
            case MDBImageType.AlbumCoverFront:
                return(true);

            default: return(false);
            }
        }
Beispiel #2
0
        /// <summary>Determines whether [is artist art].</summary>
        /// <param name="imageType">Type of the image.</param>
        /// <returns><c>true</c> if [is artist art] [the specified image type]; otherwise, <c>false</c>.</returns>
        public static bool IsArtistArt(this MDBImageType imageType)
        {
            switch (imageType)
            {
            case MDBImageType.ArtistBackground:
            case MDBImageType.ArtistMusicBanner:
            case MDBImageType.ArtistMusicLogo:
            case MDBImageType.ArtistMusicLogoHD:
            case MDBImageType.ArtistThumb:
                return(true);

            default: return(false);
            }
        }
Beispiel #3
0
        /// <summary>Saves the album image.</summary>
        /// <param name="folder">The folder.</param>
        /// <param name="name">The name.</param>
        /// <param name="imageType">Type of the image.</param>
        /// <param name="album">The album.</param>
        /// <param name="data">The data.</param>
        /// <exception cref="Exception">Invalid image type!</exception>
        public void SaveAlbumImage(MDBFolder folder, string name, MDBImageType imageType, MDBAlbum album, byte[] data)
        {
            var image = new MDBImage()
            {
                MusicBrainzGuid = album.MusicBrainzReleaseGroupGuid,
                Type            = imageType,
            };

            if (!image.IsAlbumArt)
            {
                throw new Exception("Invalid image type!");
            }

            SaveImage(data, folder, name, ref image, album);
        }
Beispiel #4
0
        /// <summary>Saves the artist image.</summary>
        /// <param name="folder">The folder.</param>
        /// <param name="name">The name.</param>
        /// <param name="imageType">Type of the image.</param>
        /// <param name="artist">The artist.</param>
        /// <param name="data">The data.</param>
        /// <exception cref="Exception">Invalid image type!</exception>
        public void SaveArtistImage(MDBFolder folder, string name, MDBImageType imageType, MDBArtist artist, byte[] data)
        {
            var image = new MDBImage()
            {
                MusicBrainzGuid = artist.MusicBrainzArtistGuid,
                Type            = imageType,
            };

            if (!image.IsArtistArt)
            {
                throw new Exception("Invalid image type!");
            }

            SaveImage(data, folder, name, ref image, artist);
            WriteArtistIni(folder, artist);
        }
Beispiel #5
0
        void FanArtTV_CheckArtistImage(MDBImageType imageType, MDBArtist artist, JsonNode node)
        {
            foreach (JsonNode v in node.Values)
            {
                try
                {
                    string source = v["url"].Value.ToString();

                    MDBFolder folder = mdb.GetArtistArtFolder(artist);
                    string    fileNameWithoutExtension = imageType.ToString() + " " + v["id"].Value.ToString();

                    byte[] imageData = null;
                    //download only if not exists
                    string fullPath = mdb.GetImageFileNameWithExtension(folder, fileNameWithoutExtension);
                    if (fullPath != null)
                    {
                        //file exists
                        MDBFile mdbFile;
                        mdb.RegisterFile(folder, fullPath, out mdbFile);
                        if (mdb.Images.Exist(nameof(MDBImage.FileID), mdbFile.ID))
                        {
                            continue;
                        }
                        //register image (image dataset missing)
                        imageData = mdb.TryLoadImageData(fullPath);
                    }
                    //download
                    if (imageData == null)
                    {
                        this.LogInfo("Download FanArtTV Image <cyan>{0}", source);
                        imageData = mdb.TryDownloadImageData(source);
                        if (imageData == null)
                        {
                            this.LogInfo("<yellow>Invalid FanArtTV Artist image <default>for artist <red>{0}", artist.Name);
                            continue;
                        }
                    }
                    mdb.SaveArtistImage(folder, fileNameWithoutExtension, imageType, artist, imageData);
                }
                catch (Exception ex)
                {
                    this.LogWarning(ex, "Error saving artist image {0}.", artist);
                }
            }
        }
        public void GetArtistsWithoutImage(WebData webData, MDBImageType imageType = 0)
        {
            var artists = mdb.Artists.GetStructs();
            var missing = new List <RPCArtist>();

            foreach (var artist in artists)
            {
                var search = Search.FieldEquals(nameof(MDBImage.MusicBrainzGuid), artist.MusicBrainzArtistGuid);
                if (imageType != 0)
                {
                    search &= Search.FieldEquals(nameof(MDBImage.Type), imageType);
                }
                if (!mdb.Images.Exist(search))
                {
                    missing.Add(RPCArtist.Load(mdb, artist));
                }
            }
            webData.Result.AddMessage(webData.Method, "Retrieved artist datasets with missing imagetype {0}...", imageType);
            webData.Result.AddStructs(missing);
        }
Beispiel #7
0
        void FanArtTV_ParseNode(MDBArtist artist, IEnumerable <MDBAlbum> albums, JsonNode node)
        {
            MDBImageType imageType = MDBImageType.Undefined;

            switch (node.Name)
            {
            case "mbid_id":
            case "name":
                return;

            case "hdmusiclogo": imageType = MDBImageType.ArtistMusicLogoHD; break;

            case "musiclogo": imageType = MDBImageType.ArtistMusicLogo; break;

            case "albums": FanArtTV_ParseGuidRoot(artist, node); break;

            case "cdart": imageType = MDBImageType.AlbumCDArt; break;

            case "albumcover": imageType = MDBImageType.AlbumCover; break;

            case "artistthumb": imageType = MDBImageType.ArtistThumb; break;

            case "artistbackground": imageType = MDBImageType.ArtistBackground; break;

            case "musicbanner": imageType = MDBImageType.ArtistMusicBanner; break;

            default: throw new NotImplementedException(string.Format("Unknown FanArtTV node {0}", node.Name));
            }
            if (imageType == MDBImageType.Undefined)
            {
                return;
            }
            if (imageType.IsAlbumArt())
            {
                FanArtTV_CheckAlbumImage(imageType, artist, albums, node);
                return;
            }
            FanArtTV_CheckArtistImage(imageType, artist, node);
        }
Beispiel #8
0
 void FanArtTV_CheckAlbumImage(MDBImageType imageType, MDBArtist artist, IEnumerable <MDBAlbum> albums, JsonNode node)
 {
     if (!albums.Any())
     {
         return;
     }
     foreach (JsonNode v in node.Values)
     {
         try
         {
             string source = v["url"].Value.ToString();
             string fileNameWithoutExtension = imageType.ToString() + " " + v["id"].Value.ToString();
             //check if each album has this image, autoload if we already have it at any album
             byte[] imageData = null;
             var    albumsWithMissingImages = new List <MDBAlbum>();
             FindAlbumImage(albums, fileNameWithoutExtension, out imageData, out albumsWithMissingImages);
             if (albumsWithMissingImages.Count == 0)
             {
                 continue;
             }
             //try load from files table
             if (imageData == null)
             {
                 foreach (var file in mdb.Files.GetStructs(nameof(MDBFile.Name), fileNameWithoutExtension))
                 {
                     string fullPath = file.GetFullPath(mdb);
                     imageData = mdb.TryLoadImageData(fullPath);
                     if (imageData == null)
                     {
                         File.Delete(fullPath);
                         mdb.Files.Delete(file.ID);
                     }
                 }
             }
             //if not found, load from web
             if (imageData == null)
             {
                 this.LogInfo("Download FanArtTV Image <blue>{0}", source);
                 imageData = mdb.TryDownloadImageData(source);
                 if (imageData == null)
                 {
                     throw new Exception("Could not load image data!");
                 }
             }
             //save to all albums
             foreach (MDBAlbum album in albumsWithMissingImages)
             {
                 var albumFolder = GetAlbumFolder(album);
                 if (albumFolder.ID == 0)
                 {
                     continue;
                 }
                 mdb.SaveAlbumImage(albumFolder, fileNameWithoutExtension, imageType, album, imageData);
             }
         }
         catch (Exception ex)
         {
             this.LogWarning(ex, "Error saving {0} image {1} for artist {2}.", imageType, v, artist);
         }
     }
 }
Beispiel #9
0
        IList <MDBImage> FindArtistImages(out MDBImageType[] types, long audioFileID = 0, long artistID = 0, bool thumb = false, bool background = false)
        {
            if (background)
            {
                types = new MDBImageType[] { MDBImageType.ArtistBackground };
            }
            else
            {
                types = new MDBImageType[] { MDBImageType.ArtistThumb, MDBImageType.ArtistMusicLogoHD, MDBImageType.ArtistMusicLogo, MDBImageType.ArtistBackground };
            }

            MDBAudioFile audioFile = mdb.AudioFiles.TryGetStruct(audioFileID);
            var          albums    = new Set <long>();

            if (audioFileID > 0)
            {
                //lookup SongArtistID
                var images = FindArtistImagesByArtistID(types, audioFile.SongArtistID);
                if (images.Count > 0)
                {
                    return(images);
                }
                //lookup AlbumArtistID
                images = FindArtistImagesByArtistID(types, audioFile.AlbumArtistID);
                if (images.Count > 0)
                {
                    return(images);
                }
                //will use these for album lookup later
                if (audioFile.SongArtistID > 0)
                {
                    albums.IncludeRange(mdb.Albums.FindRows(nameof(MDBAlbum.ArtistID), audioFile.SongArtistID));
                }
                if (audioFile.AlbumArtistID > 0)
                {
                    albums.IncludeRange(mdb.Albums.FindRows(nameof(MDBAlbum.ArtistID), audioFile.AlbumArtistID));
                }
            }
            if (artistID > 0)
            {
                //lookup artistID
                var images = FindArtistImagesByArtistID(types, artistID);
                if (images.Count > 0)
                {
                    return(images);
                }
                //will use these for album lookup later
                albums.IncludeRange(mdb.Albums.FindRows(nameof(MDBAlbum.ArtistID), artistID));
            }

            //no lookup album of artist
            types = new MDBImageType[] { MDBImageType.AlbumCoverFront, MDBImageType.AlbumCover, MDBImageType.UserCover, MDBImageType.AlbumCDArt };
            if (audioFile.AlbumID > 0)
            {
                var album  = mdb.Albums.TryGetStruct(audioFile.AlbumID);
                var images = mdb.Images.GetStructs(Search.FieldEquals(nameof(MDBImage.MusicBrainzGuid), album.MusicBrainzReleaseGroupGuid) & Search.FieldIn(nameof(MDBImage.Type), types));
                if (images.Count > 0)
                {
                    return(images);
                }
            }
            //no lookup any album of artist
            foreach (var album in mdb.Albums.GetStructs(albums))
            {
                if (album.MusicBrainzReleaseGroupGuid != null)
                {
                    var images = mdb.Images.GetStructs(Search.FieldEquals(nameof(MDBImage.MusicBrainzGuid), album.MusicBrainzReleaseGroupGuid) & Search.FieldIn(nameof(MDBImage.Type), types));
                    if (images.Count > 0)
                    {
                        return(images);
                    }
                }
            }

            return(new MDBImage[0]);
        }