Beispiel #1
0
        public void ApplyMetadata(FileInfo mediaFile, SongProperties properties)
        {
            var formatter = new TitleFormatters.TitleFormatter(properties);

            var trackData = formatter.GetProperties();

            TagLib.Id3v2.Tag.DefaultVersion = 3;
            TagLib.Id3v2.Tag.ForceDefaultVersion = true;

            using (TagLib.File file = new AudioFile(mediaFile.FullName))
            {
                var albumCover = new AttachedPictureFrame(trackData.Picture)
                    {
                        Type = PictureType.FrontCover,
                    };

                file.Tag.Pictures = new IPicture[1]{albumCover};
                file.Tag.Album = trackData.AlbumTitle;
                file.Tag.Title = trackData.Title;
                file.Tag.Year = trackData.Year;
                file.Tag.AlbumArtists = trackData.Artists;
                file.Tag.Comment = trackData.Comment;
                file.Tag.Genres = new[] {"Pop, Gospel, Motown"};
                file.Save();
            }
        }
 private static void RenameOneFile(FileInfo file, string caption) {
     try {
         AudioFile audioFile = new AudioFile(file.FullName) {
             Tag = {Album = caption, Artists = new[] {caption}, AlbumArtists = new[] {caption}}
         };
         audioFile.Save();
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine("Change tag name to [" +caption+"] for [" + file.Name + "] success.");
         Console.ResetColor();
     }
     catch (Exception ex) {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Error change tag name for [" + file.Name + "]");
         Console.ResetColor();
     }
 }
        public override void Rebuild(bool deepLoad)
        {
            _tag = null;

            if (IsServerURI == false)
            {
                try
                {
                    TagLib.File.IFileAbstraction abs = null;

                    if (IsURI)
                    {
                        abs = new UriFileAbstraction(base.Path);
                    }
                    else
                    {
                        abs = new TagLib.File.LocalFileAbstraction(base.Path);
                    }

                    af = new TagLib.Mpeg.AudioFile(abs, ReadStyle.Average);

                    if (deepLoad)
                    {
                        // This will actually toggle reading the audio header
                        TimeSpan duration = af.Properties.Duration;
                        _deepLoad = true;
                    }

                    _tag  = af.Tag;
                    _prop = af.Properties;
                }
                catch (Exception ex)
                {
                    string s = null;
                }

                _tagModified = false;
            }
        }
 /// <summary>
 /// Calculates the File Quality Coefficient extracting information from the MPEG file Header.
 /// For implementation details read the Wiki Page for this coefficient (http://code.google.com/p/p2p-player/wiki/ImplicitQoS#Coefficiente_di_Qualità_del_File)
 /// </summary>
 /// <param name="filepath">Path of the file</param>
 /// <returns>File quality coeffient of the given file</returns>
 private static FileQualityCoefficient calculateFQ(String filepath)
 {
     AudioFile mpegFile= new AudioFile(filepath);
     AudioHeader header;
     if (AudioHeader.Find(out header,mpegFile,0)) {
         double brComp=Math.Truncate((Math.Log10(header.AudioBitrate/192.0)+0.78)*100.0)/100.0;
         double srComp=0.0;
         switch (header.AudioSampleRate) {
             case 32000:
             srComp=0.2;
             break;
         case 44100:
             srComp=0.8;
             break;
         case 48000:
             srComp=1.0;
             break;
         default:
             srComp=0.0;
             break;
         }
         double cmComp=0.0;
         switch (header.ChannelMode) {
             case ChannelMode.SingleChannel:
                 cmComp=0.2;
                 break;
             case ChannelMode.DualChannel:
                 cmComp=0.5;
                 break;
             case ChannelMode.JointStereo:
                 cmComp=0.8;
                 break;
             case ChannelMode.Stereo:
                 cmComp=1.0;
                 break;
             default:
                 cmComp=0.0;
                 break;
         }
         return new FileQualityCoefficient(brComp,cmComp,srComp);
     } else {
         return new FileQualityCoefficient();
     }
 }
        private void ButtonSelectFile_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new Microsoft.Win32.OpenFileDialog
            {
                FilterIndex = 3,
                Filter = "MP3 Files (*.mp3)|*.mp3|MPEG 4 Audio (*.m4a)|*.m4a|Audio Files|*.mp3;*.m4a"
            };

            var result = dlg.ShowDialog();

            if (result == true)
            {
                _filePath = dlg.FileName;

                ButtonSelectFile.Content = Path.GetFileName(_filePath);
                try // load data from tags
                {
                    var file = new AudioFile(_filePath);

                    // Song title
                    TextBoxSongTitle.Text = file.Tag.Title;

                    // Song artist
                    if (string.IsNullOrEmpty(file.Tag.FirstPerformer))
                    {
                        ComboBoxArtist.SelectedIndex = -1;
                    }
                    else
                    {
                        int index = GetArtistIndex(file.Tag.FirstPerformer);
                        if (index == -1)
                        {
                            EnableEditing(ComboBoxArtist);
                            ComboBoxArtist.Text = file.Tag.FirstPerformer;
                        }
                        else
                        {
                            ComboBoxArtist.SelectedIndex = index;
                        }
                    }

                    // Song album
                    if (string.IsNullOrEmpty(file.Tag.Album))
                    {
                        ComboBoxAlbum.SelectedIndex = -1;
                    }
                    else
                    {
                        int index = GetAlbumIndex(file.Tag.Album);
                        if (index == -1)
                        {
                            EnableEditing(ComboBoxAlbum);
                            ComboBoxAlbum.Text = file.Tag.Album;
                        }
                        else
                        {
                            ComboBoxAlbum.SelectedIndex = index;
                        }
                    }

                    // Song genre
                    if (string.IsNullOrEmpty(file.Tag.Genres[0]))
                    {
                        ComboBoxGenre.SelectedIndex = -1;
                    }
                    else
                    {
                        int index = GetGenreIndex(file.Tag.Genres[0]);
                        if (index == -1)
                        {
                            EnableEditing(ComboBoxGenre);
                            ComboBoxGenre.Text = file.Tag.Genres[0];
                        }
                        else
                        {
                            ComboBoxGenre.SelectedIndex = index;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Unable to read tags from file. " + ex.Message);
                }
                if (string.IsNullOrEmpty(TextBoxSongTitle.Text))
                {
                    TextBoxSongTitle.Text = Path.GetFileNameWithoutExtension(_filePath);
                }
            }
        }
Beispiel #6
0
        public ID3FileInfo(string path, bool deepLoad)
            : base(path, false)
        {
            if (IsValid)
            {
                try
                {
                    af = new TagLib.Mpeg.AudioFile(path, ReadStyle.Average);

                    if (deepLoad)
                    {
                        // This will actually toggle reading the audio header
                        TimeSpan duration = af.Properties.Duration;
                        _deepLoad = true;
                    }

                    _tag = af.Tag;
                    _prop = af.Properties;
                }
                catch
                {
                }

                _tagModified = false;
            }
        }
Beispiel #7
0
 public MP3Audio(string FilePath) : base(FilePath)
 {
     _mp3File = new AudioFile(FilePath);
 }