Esempio n. 1
0
 private void writeTagInfo(string title, string path, string genre, string artist)
 {
     try
     {
         bool changed = false;
         TagLib.Mpeg.AudioFile file = new TagLib.Mpeg.AudioFile(path);
         if (String.IsNullOrWhiteSpace(file.Tag.Title) || file.Tag.Title.ToLower() != title.ToLower())
         {
             file.Tag.Title = Capitalise(title); changed = true;
         }
         ;
         if (file.Tag.Genres.Length == 0 || file.Tag.Genres[0].ToLower() != genre.ToLower())
         {
             file.Tag.Genres = new string[1] {
                 Capitalise(genre)
             }; changed = true;
         }
         ;
         if (file.Tag.Performers.Length == 0 || file.Tag.Performers[0] != artist.ToLower())
         {
             file.Tag.Performers = new string[1] {
                 Capitalise(artist)
             }; changed = true;
         }
         ;
         if (file.Tag.Lyrics == null)
         {
             file.Tag.Lyrics = Tracklist; changed = true;
         }
         ;
         if (file.Tag.Album == null || file.Tag.Album.ToLower() != album.ToLower())
         {
             file.Tag.Album = Capitalise(album); changed = true;
         }
         if (changed)
         {
             Console.WriteLine("CHG");
             file.Save();
         }
     }
     catch (Exception ex)
     {
         logger.addEvent(new cEvent(Severity.Error, "An error occured while writing tags for the current file:\r\n" + "Title: " + title + "\r\n" +
                                    "Path: " + path + "\r\nGenre: " + genre + "\r\n" + artist, ex));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Saves the metadata associated with this audio file from its properties.
        /// </summary>
        public void SaveMetadata()
        {
            // Check what is the type of the audio file
            if (fileType == AudioFileFormat.MP3)
            {          
                // Declare variables
                TagLib.Mpeg.AudioFile file = null;

                try
                {
                    // Read tags
                    file = new TagLib.Mpeg.AudioFile(filePath);                    

                    // Copy tags
                    file = (TagLib.Mpeg.AudioFile)FillTags(file);

                    // Save metadata
                    file.Save();
                }
                catch (Exception ex)
                {
                    // Throw exception
                    throw new Exception("An error occured while reading/writing the tags and properties of the file (" + filePath + ").", ex);
                }
                finally
                {
                    // Dispose file (if needed)
                    if (file != null)
                        file.Dispose();
                }
            }
            else if (fileType == AudioFileFormat.FLAC)
            {
                // Declare variables
                TagLib.Flac.File file = null;

                try
                {
                    // Read tags
                    file = new TagLib.Flac.File(filePath);

                    // Copy tags
                    file = (TagLib.Flac.File)FillTags(file);

                    // Save metadata
                    file.Save();
                }
                catch (Exception ex)
                {
                    // Throw exception
                    throw new Exception("An error occured while reading/writing the tags and properties of the file (" + filePath + ").", ex);
                }
                finally
                {
                    // Dispose file (if needed)
                    if (file != null)
                        file.Dispose();
                }
            }
            else if (fileType == AudioFileFormat.OGG)
            {
                // Declare variables
                TagLib.Ogg.File file = null;

                try
                {
                    // Read tags
                    file = new TagLib.Ogg.File(filePath);

                    // Copy tags
                    file = (TagLib.Ogg.File)FillTags(file);

                    // Save metadata
                    file.Save();
                }
                catch (Exception ex)
                {
                    // Throw exception
                    throw new Exception("An error occured while reading/writing the tags and properties of the file (" + filePath + ").", ex);
                }
                finally
                {
                    // Dispose file (if needed)
                    if (file != null)
                        file.Dispose();
                }
            }
            else if (fileType == AudioFileFormat.APE)
            {
                // Declare variables
                TagLib.Ape.File file = null;

                try
                {
                    // Read tags
                    file = new TagLib.Ape.File(filePath);

                    // Copy tags
                    file = (TagLib.Ape.File)FillTags(file);

                    // Save metadata
                    file.Save();
                }
                catch (Exception ex)
                {
                    // Throw exception
                    throw new Exception("An error occured while reading/writing the tags and properties of the file (" + filePath + ").", ex);
                }
                finally
                {
                    // Dispose file (if needed)
                    if (file != null)
                        file.Dispose();
                }
            }
            else if (fileType == AudioFileFormat.WV)
            {
                // Declare variables
                TagLib.WavPack.File file = null;

                try
                {
                    // Read tags
                    file = new TagLib.WavPack.File(filePath);

                    // Copy tags
                    file = (TagLib.WavPack.File)FillTags(file);

                    // Save metadata
                    file.Save();
                }
                catch (Exception ex)
                {
                    // Throw exception
                    throw new Exception("An error occured while reading/writing the tags and properties of the file (" + filePath + ").", ex);
                }
                finally
                {
                    // Dispose file (if needed)
                    if (file != null)
                        file.Dispose();
                }
            }
            else if (fileType == AudioFileFormat.WMA)
            {
                // Declare variables
                TagLib.Asf.File file = null;

                try
                {
                    // Read tags
                    file = new TagLib.Asf.File(filePath);

                    // Copy tags
                    file = (TagLib.Asf.File)FillTags(file);

                    // Save metadata
                    file.Save();
                }
                catch (Exception ex)
                {
                    // Throw exception
                    throw new Exception("An error occured while reading/writing the tags and properties of the file (" + filePath + ").", ex);
                }
                finally
                {
                    // Dispose file (if needed)
                    if (file != null)
                        file.Dispose();
                }
            }
        }
Esempio n. 3
0
 public void SetTitle(string value)
 {
     file.Tag.Title = value;
     file.Save();
 }