Example #1
0
        public static void SetFileTags(Mp3File file, Mp3Tag data)
        {
            if (data != null)
            {
                using (var mp3 = new Mp3(file.FilePath, Mp3Permissions.ReadWrite))
                {
                    Id3Tag tag = mp3.GetTag(Id3TagFamily.Version2X);

                    if (tag == null)
                    {
                        tag = new Id3Tag();
                        var propinfo = typeof(Id3Tag).GetProperty("Version", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                        propinfo.SetValue(tag, Id3Version.V23);
                    }

                    tag.Artists.Value.Add(data.Artist);
                    tag.Title = new TitleFrame(data.Title);
                    tag.Album = new AlbumFrame(data.Album);
                    tag.Year  = new YearFrame(data.Year);

                    if (tag.Genre.Value != null)
                    {
                        string filteredGenre = string.Join(';', tag.Genre.Value.Split(';').Where(x => FilterGenre(x)));
                        tag.Genre = new GenreFrame(filteredGenre);
                    }

                    mp3.WriteTag(tag, WriteConflictAction.Replace);

                    file.Filled = true;

                    Console.WriteLine($"{data.Artist}\t{data.Title}\t{data.Album}\t{data.Year}\t{data.Genres}");
                }
            }
        }
Example #2
0
        public static Mp3File[] GetMp3Files(string mp3Folder)
        {
            string[]  filePathes = GetMp3FilesPathes(mp3Folder);
            Mp3File[] files      = new Mp3File[filePathes.Length];

            Mp3Tag[] tags = GetFileTags(filePathes);

            for (int i = 0; i < filePathes.Length; i++)
            {
                files[i]          = new Mp3File();
                files[i].FileName = filePathes[i].Split('\\').Last();
                files[i].FilePath = filePathes[i];
                files[i].Tags     = tags[i];
            }

            return(files);
        }