Пример #1
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);
                }
            }
        }
Пример #2
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);
         }
     }
 }