public SongInformation(string path) { try { using (var file = new TagLib.Mpeg4.File(path)) { var tags = file.GetTag(TagLib.TagTypes.Apple) as TagLib.Mpeg4.AppleTag; this.path = path; this.title = tags.Title; this.album = tags.Album; this.artist = tags.AlbumArtists.FirstOrDefault() ?? tags.Performers.FirstOrDefault(); this.track = tags.Track > 0 ? (int?)tags.Track : (int?)null; this.isCompilation = tags.IsCompilation; } } catch { using (var file = TagLib.File.Create(path)) { var tags = file.GetTag(TagLib.TagTypes.Id3v2); this.path = path; this.title = tags.Title; this.album = tags.Album; this.artist = tags.AlbumArtists.FirstOrDefault() ?? tags.Performers.FirstOrDefault(); this.track = tags.Track > 0 ? (int?)tags.Track : (int?)null; //this.isCompilation = tags.IsCompilation; } } }
void TagTestWithSave(ref TagLib.Mpeg4.File file, MemoryFileAbstraction abst, TagTestFunc testFunc) { testFunc(file.GetTag(TagTypes.Apple), "Before Save"); file.Save(); // Console.WriteLine (); // Extras.DumpHex ((abst.ReadStream as System.IO.MemoryStream).ToArray ()); file = new TagLib.Mpeg4.File(abst, ReadStyle.None); testFunc(file.GetTag(TagTypes.Apple), "After Save"); }
public Video(string filePath) : base(filePath) { if (this.Extension.ToLower() == ".wmv") { TagLib.Asf.File a = new TagLib.Asf.File(filePath); _lengthInSeconds = (int)Math.Round(a.Properties.Duration.TotalSeconds); _resolution = a.Properties.VideoWidth.ToString() + " x " + a.Properties.VideoHeight.ToString(); foreach (TagLib.ICodec codec in a.Properties.Codecs) { if (codec.MediaTypes == TagLib.MediaTypes.Video) { _videoCompression = codec.Description; } else if (codec.MediaTypes == TagLib.MediaTypes.Audio) { _audioCompression = codec.Description; } } _frameRate = 0; } else if (this.Extension.ToLower() == ".mp4") { TagLib.Mpeg4.File newMpg = new TagLib.Mpeg4.File(filePath); _lengthInSeconds = (int)Math.Round(newMpg.Properties.Duration.TotalSeconds); _resolution = newMpg.Properties.VideoWidth.ToString() + " x " + newMpg.Properties.VideoHeight.ToString(); foreach (ICodec codec in newMpg.Properties.Codecs) { if (codec.MediaTypes == TagLib.MediaTypes.Video) { _videoCompression = codec.Description; } else if (codec.MediaTypes == TagLib.MediaTypes.Audio) { _audioCompression = codec.Description; } if (codec is TagLib.Mpeg.VideoHeader) { TagLib.Mpeg.VideoHeader G = (TagLib.Mpeg.VideoHeader)codec; _frameRate = G.VideoFrameRate; } } //TODO: Figure out frame rate. } else if (this.Extension.ToLower() == ".webm") { TagLib.Matroska.File a = new TagLib.Matroska.File(filePath); _lengthInSeconds = (int)Math.Round(a.Properties.Duration.TotalSeconds); _resolution = a.Properties.VideoWidth.ToString() + " x " + a.Properties.VideoHeight.ToString(); } }
/// <summary> /// Processes an MP4 file. /// </summary> /// <param name="file"></param> /// <param name="fullPath"></param> /// <returns></returns> private PhotoFile ProcessTagFile(TagLib.Mpeg4.File file, string fullPath) { DateTime createdDate = File.GetCreationTime(fullPath); return(new PhotoFile(fullPath, createdDate, createdDate)); }