예제 #1
0
 private void InitializeITunes()
 {
     if (theLibrary.IsInitialized == false)
     {
         bool success = theLibrary.InitializeITunesApp();
         if (success)
         {
             this.DisplayMessage(new OutputMessage("Successfully initialized iTunes App!", MessageSeverity.Always));
             this.DisplayMessage(new OutputMessage(ExportArtwork.GetLibrarySizeMessage(theLibrary), MessageSeverity.Always, true));
         }
         else
         {
             this.DisplayMessage(new OutputMessage("Error initializing iTunes App!", MessageSeverity.Always));
         }
     }
 }
예제 #2
0
 void bgw_DoWork(object sender, DoWorkEventArgs e)
 {
     ExportArtwork.DoExport(theLibrary, (BackgroundWorker)sender, e, this.DisplayMessage);
 }
        private static OutputMessage ExportDirectoryArtwork(iTunesLibrary library, List <Track> trackList, string directory)
        {
            List <Track> directoryTrackList = trackList.Where(t => t.Directory == directory).ToList();

            int trackCount = directoryTrackList.Count();

            if (trackCount == 0)
            {
                return(new OutputMessage("No tracks found in the library for the directory: \"" + directory + "\".", MessageSeverity.Error));
            }

            // Minimum # of tracks in a directory (regardless of whether they have artwork attached)
            int minTracks = iTunes_Artwork_Export.Properties.Settings.Default.MinTracks;

            if (trackCount < minTracks)
            {
                return(new OutputMessage("Not enough tracks in the following directory: \"" + directory + "\" (track count is " + trackCount.ToString() + "; minimum is " + minTracks.ToString() + ").", MessageSeverity.Warning));
            }

            // Check that at least 1 track has artwork attached
            if (directoryTrackList.Where(t => t.ArtworkCount > 0).Count() == 0)
            {
                return(new OutputMessage("No artwork found for the tracks in directory: \"" + directory + "\".", MessageSeverity.Warning));
            }

            Track artworkTrack = null;

            try
            {
                artworkTrack = GetArtworkTrack(directoryTrackList);
            }
            catch (ArgumentException argEx)
            {
                return(new OutputMessage(argEx.Message, MessageSeverity.Error));
            }
            catch (ApplicationException appEx)
            {
                return(new OutputMessage(appEx.Message, MessageSeverity.Warning));
            }
            catch (Exception ex)
            {
                return(new OutputMessage(ex.Message, MessageSeverity.Error));
            }

            if (artworkTrack == null)
            {
                return(new OutputMessage("Error: No artwork track returned for directory \"" + directory + "\".", MessageSeverity.Error));
            }

            PersistentID artworkTrackPersistentID = artworkTrack.PersistentID;
            IITTrack     itArtworkTrack           = null;

            try
            {
                itArtworkTrack = ExportArtwork.GetTrackByPersistentID(library, artworkTrackPersistentID);
            }
            catch (Exception ex)
            {
                return(new OutputMessage("Error when retrieving track by Persistent ID: " + ex.Message + ".  Track: " + artworkTrack.ToString(true, true), MessageSeverity.Error));
            }

            if (itArtworkTrack != null)
            {
                // Found the iTunes Track in the library with the Artwork Track's persistent ID.

                IITArtwork iaArt = GetTrackArtwork(itArtworkTrack);
                if (iaArt != null)
                {
                    // Found the artwork on that track.

                    DirectoryInfo trackDirectoryInfo = new DirectoryInfo(directory);
                    if (trackDirectoryInfo.Exists)
                    {
                        string outputFileName = directory + "\\" + iTunes_Artwork_Export.Properties.Settings.Default.FileName;
                        try
                        {
                            FileInfo fiOutputFile = new FileInfo(outputFileName);
                            if (fiOutputFile.Exists)
                            {
                                return(new OutputMessage("File \"" + outputFileName + "\" already exists!", MessageSeverity.Debug));
                            }
                            else
                            {
                                try
                                {
                                    iaArt.SaveArtworkToFile(outputFileName);
                                    return(new OutputMessage("Saved artwork to: \"" + outputFileName + "\".  Track: " + artworkTrack.ToString(true, false), MessageSeverity.Success));
                                }
                                catch (Exception ex)
                                {
                                    return(new OutputMessage("Error when attempting to save artwork to: \"" + outputFileName + "\": " + ex.Message, MessageSeverity.Error));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            return(new OutputMessage("Could not output artwork to \"" + outputFileName + "\": " + ex.Message + ".  Track: " + artworkTrack.ToString(true, false), MessageSeverity.Error));
                        }
                    }
                    else
                    {
                        return(new OutputMessage("Could not output artwork to directory \"" + directory + "\": directory does not exist.  Track: " + artworkTrack.ToString(true, false), MessageSeverity.Error));
                    }
                }
                else
                {
                    return(new OutputMessage("Could not retrieve artwork for Track: " + artworkTrack.ToString(true, false), MessageSeverity.Error));
                }
            }
            else
            {
                return(new OutputMessage("Could not retrieve Track by Persistent ID: " + artworkTrack.ToString(true, true), MessageSeverity.Error));
            }
        }