Ejemplo n.º 1
0
        public TrackTags Read(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(new TrackTags());
            }

            var id3V2Tags = ID3v2.FromFile(filePath);

            var tags = new TrackTags();

            tags.Album       = Get(id3V2Tags, ID3v2Mapping.Album);
            tags.AlbumArtist = Get(id3V2Tags, ID3v2Mapping.AlbumArtist);
            tags.Artist      = Get(id3V2Tags, ID3v2Mapping.Artist);
            tags.Comment     = Get(id3V2Tags, ID3v2Mapping.Comment);
            tags.Composer    = Get(id3V2Tags, ID3v2Mapping.Composer);
            tags.DiscNumber  = Get(id3V2Tags, ID3v2Mapping.DiscNumber);
            tags.FileName    = Path.GetFileNameWithoutExtension(filePath);
            tags.Genre       = Get(id3V2Tags, ID3v2Mapping.Genre);
            tags.Title       = Get(id3V2Tags, ID3v2Mapping.Title);
            tags.TrackNumber = Get(id3V2Tags, ID3v2Mapping.TrackNumber);
            tags.Year        = Get(id3V2Tags, ID3v2Mapping.Year);

            var codec = CodecFactory.Instance.GetCodec(filePath);

            if (codec != null)
            {
                tags.Length = codec.GetLength();
            }

            return(tags);
        }
Ejemplo n.º 2
0
        public void LoadTags(string filename)
        {
            ID3v2 t2 = ID3v2.FromFile(filename);
            ID3v1 t1 = ID3v1.FromFile(filename);

            if (t2 != null)
            {
                Title          = t2.QuickInfo.Title;
                Artist         = t2.QuickInfo.Artist;
                Album          = t2.QuickInfo.Album;
                Year           = t2.QuickInfo.Year.ToString();
                LeadPerformers = t2.QuickInfo.LeadPerformers;
                Genre          = t2.QuickInfo.Genre.ToString();
                TrackNumber    = t2.QuickInfo.TrackNumber.ToString();
                Comments       = t2.QuickInfo.Comments;

                if (t2.QuickInfo.Image != null)
                {
                    if (Image != null)
                    {
                        (Image as BitmapImage).StreamSource.Dispose();
                        Image = null;
                    }

                    MemoryStream imgstream = new MemoryStream();
                    t2.QuickInfo.Image.Save(imgstream, System.Drawing.Imaging.ImageFormat.Png);
                    var img = new BitmapImage();
                    img.BeginInit();
                    imgstream.Seek(0, SeekOrigin.Begin);
                    img.StreamSource = imgstream;
                    img.EndInit();
                    Image = img;
                }
            }
            if (t1 != null)
            {
                if (String.IsNullOrWhiteSpace(Title))
                {
                    Title = t1.Title;
                }
                if (String.IsNullOrWhiteSpace(Artist))
                {
                    Artist = t1.Artist;
                }
                if (String.IsNullOrWhiteSpace(Album))
                {
                    Album = t1.Album;
                }
                if (String.IsNullOrWhiteSpace(Year))
                {
                    Year = t1.Year.ToString();
                }
                if (string.IsNullOrWhiteSpace(Comments))
                {
                    Comments = t1.Comment;
                }
                Genre = t1.Genre.ToString();
            }
        }
Ejemplo n.º 3
0
        public LectorMetadatos(string s)
        {
            switch (Path.GetExtension(s))
            {
            case ".mp3":
                ID3v2 mp3tag = ID3v2.FromFile(s);
                _mp3iD3 = new ID3v2QuickInfo(mp3tag);
                Artista = _mp3iD3.LeadPerformers;
                Titulo  = _mp3iD3.Title;
                break;

            case ".flac":
                _FLACfile = new FLACFile(s, true);
                Artista   = _FLACfile.ARTIST;
                Titulo    = _FLACfile.TITLE;
                break;

            case ".ogg":
                _vorbisReader = new VorbisReader(s);
                foreach (String meta in _vorbisReader.Comments)
                {
                    if (meta.Contains("TITLE="))
                    {
                        Titulo = meta.Replace("TITLE=", "");
                    }
                    else if (meta.Contains("TITLE=".ToLower()))
                    {
                        Titulo = meta.Replace("title=", "");
                    }
                }
                foreach (String meta in _vorbisReader.Comments)
                {
                    if (meta.Contains("ARTIST="))
                    {
                        Artista = meta.Replace("ARTIST=", "");
                    }
                    else if (meta.Contains("ARTIST=".ToLower()))
                    {
                        Artista = meta.Replace("artist=", "");
                    }
                }
                Cerrar();
                break;

            default:
                break;
            }
        }