internal Track(string FilePath, string Title, string Artist, IList <string> AlbumArtists, string Album, uint Year, uint TrackNumber, string MusicBrainzTrackId, bool HasFrontCover, int FrontCoverHeight, int FrontCoverWidth, int Bitrate, int SampleRate, string Source, uint DiscNumber, TimeSpan Duration, TrackFileType FileType ) { this.FilePath = FilePath; this.Title = Title; this.Artist = Artist; this.AlbumArtists = AlbumArtists; this.Album = Album; this.Year = Year; this.TrackNumber = TrackNumber; this.MusicBrainzTrackId = MusicBrainzTrackId; this.HasFrontCover = HasFrontCover; this.FrontCoverHeight = FrontCoverHeight; this.FrontCoverWidth = FrontCoverWidth; this.Bitrate = Bitrate; this.SampleRate = SampleRate; this.Source = Source; this.Duration = Duration; this.FileType = FileType; this.DiscNumber = DiscNumber; }
public Track(string filename) { using (var file = TagLib.File.Create(filename)) { this.FileType = Track.GetTrackFileType(file.Properties.Description, file.Properties.BitsPerSample); this.Duration = file.Properties.Duration.Ticks; this.SampleRate = file.Properties.AudioSampleRate; this.Bitrate = file.Properties.AudioBitrate; this.Album = file.Tag.Album; this.AlbumArtists = file.Tag.AlbumArtists.Select(s => s.Trim()).ToList(); this.Artist = file.Tag.FirstPerformer; this.TrackNumber = file.Tag.Track; this.Year = file.Tag.Year; this.MusicBrainzTrackId = file.Tag.MusicBrainzTrackId; this.Title = file.Tag.Title; this.DiscNumber = file.Tag.Disc == 0 ? 1 : file.Tag.Disc; var frontAlbum = from picture in file.Tag.Pictures where picture.Type == TagLib.PictureType.FrontCover select picture; this.HasFrontCover = frontAlbum.Any(); if (this.HasFrontCover) { using (Image <Rgba32> image = Image.Load(new MemoryStream(frontAlbum.First().Data.Data))) { this.FrontCoverHeight = image.Height; this.FrontCoverWidth = image.Width; } } } }
public Track(string filename, string source = "None") { this.FilePath = Path.GetFullPath(filename); this.Source = source; IFileAbstraction f = new TagLib.File.LocalFileAbstraction(filename); using (var file = TagLib.File.Create(f)) { switch (file.Properties.Description) { case "Flac Audio": this.FileType = Track.GetFlacType(file.Properties.BitsPerSample); break; case "MPEG Version 1 Audio, Layer 3": case "MPEG Version 2 Audio, Layer 3": case "MPEG Version 2.5 Audio, Layer 3": this.FileType = TrackFileType.MP3_CBR; break; case "MPEG Version 1 Audio, Layer 3 VBR": case "MPEG Version 2 Audio, Layer 3 VBR": case "MPEG Version 2.5 Audio, Layer 3 VBR": this.FileType = TrackFileType.MP3_VBR; break; case "MPEG-4 Audio (alac)": this.FileType = TrackFileType.ALAC; break; case "MPEG-4 Audio (mp4a)": this.FileType = TrackFileType.AAC; break; default: this.FileType = TrackFileType.UNKNOWN; break; } this.Duration = file.Properties.Duration; this.SampleRate = file.Properties.AudioSampleRate; this.Bitrate = file.Properties.AudioBitrate; this.Album = file.Tag.Album; this.AlbumArtists = file.Tag.AlbumArtists.ToList(); this.Artist = file.Tag.FirstPerformer; this.TrackNumber = file.Tag.Track; this.Year = file.Tag.Year; this.MusicBrainzTrackId = file.Tag.MusicBrainzTrackId; this.Title = file.Tag.Title; this.DiscNumber = file.Tag.Disc; var frontAlbum = from picture in file.Tag.Pictures where picture.Type == TagLib.PictureType.FrontCover select picture; this.HasFrontCover = frontAlbum.Any(); if (this.HasFrontCover) { using (var image = Image.FromStream(new MemoryStream(frontAlbum.First().Data.Data), false, false)) { this.FrontCoverHeight = image.Height; this.FrontCoverWidth = image.Width; } } } }