/// <summary> /// Gets a tag of a specified type from the current instance, /// optionally creating a new tag if possible. /// </summary> /// <param name="type"> /// A <see cref="TagTypes" /> value indicating the /// type of tag to read. /// </param> /// <param name="create"> /// A <see cref="bool" /> value specifying whether or not to /// try and create the tag if one is not found. /// </param> /// <returns> /// A <see cref="Tag" /> object containing the tag that was /// found in or added to the current instance. If no /// matching tag was found and none was created, <see /// langword="null" /> is returned. /// </returns> /// <remarks> /// At the time of this writing, only <see cref="AppleTag" /> /// is supported. All other tag types will be ignored. /// </remarks> public override Tag GetTag(TagTypes type, bool create) { if (type == TagTypes.Apple) { if (apple_tag == null && create) { apple_tag = new AppleTag(udta_box); tag.SetTags(apple_tag); } return(apple_tag); } return(null); }
/// <summary> /// Gets a tag of a specified type from the current instance, /// optionally creating a new tag if possible. /// </summary> /// <param name="type"> /// A <see cref="TagLib.TagTypes" /> value indicating the /// type of tag to read. /// </param> /// <param name="create"> /// A <see cref="bool" /> value specifying whether or not to /// try and create the tag if one is not found. /// </param> /// <returns> /// A <see cref="Tag" /> object containing the tag that was /// found in or added to the current instance. If no /// matching tag was found and none was created, <see /// langword="null" /> is returned. /// </returns> /// <remarks> /// At the time of this writing, only <see cref="AppleTag" /> /// is supported. All other tag types will be ignored. /// </remarks> public override Tag GetTag (TagTypes type, bool create) { if (type == TagTypes.Apple) { if (apple_tag == null && create) { IsoUserDataBox udtaBox = FindAppleTagUdta (); if (null == udtaBox) { udtaBox = new IsoUserDataBox (); } apple_tag = new AppleTag (udtaBox); tag.SetTags (apple_tag); } return apple_tag; } return null; }
/// <summary> /// Reads the file with a specified read style. /// </summary> /// <param name="propertiesStyle"> /// A <see cref="ReadStyle" /> value specifying at what level /// of accuracy to read the media properties, or <see /// cref="ReadStyle.None" /> to ignore the properties. /// </param> void Read (ReadStyle propertiesStyle) { // TODO: Support Id3v2 boxes!!! tag = new CombinedTag (); Mode = AccessMode.Read; try { var parser = new FileParser (this); if ((propertiesStyle & ReadStyle.Average) == 0) parser.ParseTag (); else parser.ParseTagAndProperties (); InvariantStartPosition = parser.MdatStartPosition; InvariantEndPosition = parser.MdatEndPosition; UdtaBoxes.AddRange (parser.UserDataBoxes); // Ensure our collection contains at least a single empty box if (UdtaBoxes.Count == 0) { var dummy = new IsoUserDataBox (); UdtaBoxes.Add (dummy); } // Check if a udta with ILST actually exists if (IsAppleTagUdtaPresent ()) TagTypesOnDisk |= TagTypes.Apple; //There is an udta present with ILST info // Find the udta box with the Apple Tag ILST IsoUserDataBox udtaBox = FindAppleTagUdta (); if (null == udtaBox) { udtaBox = new IsoUserDataBox (); } apple_tag = new AppleTag (udtaBox); tag.SetTags (apple_tag); // If we're not reading properties, we're done. if ((propertiesStyle & ReadStyle.Average) == 0) { Mode = AccessMode.Closed; return; } // Get the movie header box. var mvhd_box = parser.MovieHeaderBox; if (mvhd_box == null) { Mode = AccessMode.Closed; throw new CorruptFileException ("mvhd box not found."); } var audio_sample_entry = parser.AudioSampleEntry; var visual_sample_entry = parser.VisualSampleEntry; // Read the properties. properties = new Properties (mvhd_box.Duration, audio_sample_entry, visual_sample_entry); } finally { Mode = AccessMode.Closed; } }
private void Read(ReadStyle propertiesStyle) { tag = new CombinedTag(); Mode = AccessMode.Read; try { FileParser parser = new FileParser(this); if (propertiesStyle == ReadStyle.None) { parser.ParseTag(); } else { parser.ParseTagAndProperties(); } InvariantStartPosition = parser.MdatStartPosition; InvariantEndPosition = parser.MdatEndPosition; udta_boxes.AddRange(parser.UserDataBoxes); if (udta_boxes.Count == 0) { IsoUserDataBox dummy = new IsoUserDataBox(); udta_boxes.Add(dummy); } if (IsAppleTagUdtaPresent()) { TagTypesOnDisk |= TagTypes.Apple; } IsoUserDataBox udtaBox = FindAppleTagUdta(); if (null == udtaBox) { udtaBox = new IsoUserDataBox(); } apple_tag = new AppleTag(udtaBox); tag.SetTags(apple_tag); if (propertiesStyle == ReadStyle.None) { Mode = AccessMode.Closed; return; } IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox; if (mvhd_box == null) { Mode = AccessMode.Closed; throw new CorruptFileException("mvhd box not found."); } IsoAudioSampleEntry audio_sample_entry = parser.AudioSampleEntry; IsoVisualSampleEntry visual_sample_entry = parser.VisualSampleEntry; properties = new Properties(mvhd_box.Duration, audio_sample_entry, visual_sample_entry); } finally { Mode = AccessMode.Closed; } }
public override void RemoveTags(TagTypes types) { if ((types & TagLib.TagTypes.Id3v2) != TagLib.TagTypes.None) { id32_tag = null; } if ((types & TagLib.TagTypes.RiffInfo) != TagLib.TagTypes.None) { info_tag = null; } if ((types & TagLib.TagTypes.MovieId) != TagLib.TagTypes.None) { mid_tag = null; } if ((types & TagLib.TagTypes.DivX) != TagLib.TagTypes.None) { divx_tag = null; } tag.SetTags(id32_tag, info_tag, mid_tag, divx_tag); }
private void Read(bool read_tags, ReadStyle style, out uint riff_size, out long tag_start, out long tag_end) { Seek(0); if (ReadBlock(4) != FileIdentifier) { throw new CorruptFileException("File does not begin with RIFF identifier"); } riff_size = ReadBlock(4).ToUInt(false); ByteVector stream_format = ReadBlock(4); tag_start = -1; tag_end = -1; long position = 12; long length = Length; TimeSpan duration = TimeSpan.Zero; ICodec[] codecs = new ICodec [0]; do { bool tag_found = false; Seek(position); string fourcc = ReadBlock(4).ToString(StringType.UTF8); uint size = ReadBlock(4).ToUInt(false); switch (fourcc) { case "fmt ": if (stream_format == "WAVE" && style != ReadStyle.None) { Seek(position + 8); codecs = new ICodec [] { new WaveFormatEx(ReadBlock(18), 0) }; } break; case "data": if (stream_format == "WAVE") { if (style != ReadStyle.None && codecs.Length == 1 && codecs [0] is WaveFormatEx) { duration += TimeSpan.FromSeconds((double)size / (double)((WaveFormatEx)codecs [0]).AverageBytesPerSecond); } InvariantStartPosition = position; InvariantEndPosition = position + size; } break; case "LIST": { switch (ReadBlock(4).ToString(StringType.UTF8)) { case "hdrl": if (stream_format == "AVI " && style != ReadStyle.None) { AviHeaderList header_list = new AviHeaderList(this, position + 12, (int)(size - 4)); duration = header_list.Header.Duration; codecs = header_list.Codecs; } break; case "INFO": { if (read_tags && info_tag == null) { info_tag = new InfoTag(this, position + 12, (int)(size - 4)); } tag_found = true; break; } case "MID ": if (read_tags && mid_tag == null) { mid_tag = new MovieIdTag(this, position + 12, (int)(size - 4)); } tag_found = true; break; case "movi": if (stream_format == "AVI ") { InvariantStartPosition = position; InvariantEndPosition = position + size; } break; } break; } case "ID32": if (read_tags && id32_tag == null) { id32_tag = new Id3v2.Tag(this, position + 8); } tag_found = true; break; case "IDVX": if (read_tags && divx_tag == null) { divx_tag = new DivXTag(this, position + 8); } tag_found = true; break; case "JUNK": if (tag_end == position) { tag_end = position + 8 + size; } break; } if (tag_found) { if (tag_start == -1) { tag_start = position; tag_end = position + 8 + size; } else if (tag_end == position) { tag_end = position + 8 + size; } } position += 8 + size; }while (position + 8 < length); if (style != ReadStyle.None) { if (codecs.Length == 0) { throw new UnsupportedFormatException("Unsupported RIFF type."); } properties = new Properties(duration, codecs); } if (read_tags) { tag.SetTags(id32_tag, info_tag, mid_tag, divx_tag); } }
/// <summary> /// Reads the file with a specified read style. /// </summary> /// <param name="propertiesStyle"> /// A <see cref="ReadStyle" /> value specifying at what level /// of accuracy to read the media properties, or <see /// cref="ReadStyle.None" /> to ignore the properties. /// </param> private void Read (ReadStyle propertiesStyle) { // TODO: Support Id3v2 boxes!!! tag = new CombinedTag (); Mode = AccessMode.Read; try { FileParser parser = new FileParser (this); if (propertiesStyle == ReadStyle.None) parser.ParseTag (); else parser.ParseTagAndProperties (); InvariantStartPosition = parser.MdatStartPosition; InvariantEndPosition = parser.MdatEndPosition; udta_box = parser.UserDataBox; if (udta_box != null && udta_box.GetChild (BoxType.Meta) != null && udta_box.GetChild (BoxType.Meta ).GetChild (BoxType.Ilst) != null) TagTypesOnDisk |= TagTypes.Apple; if (udta_box == null) udta_box = new IsoUserDataBox (); apple_tag = new AppleTag (udta_box); tag.SetTags (apple_tag); // If we're not reading properties, we're done. if (propertiesStyle == ReadStyle.None) { Mode = AccessMode.Closed; return; } // Get the movie header box. IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox; if(mvhd_box == null) { Mode = AccessMode.Closed; throw new CorruptFileException ( "mvhd box not found."); } IsoAudioSampleEntry audio_sample_entry = parser.AudioSampleEntry; IsoVisualSampleEntry visual_sample_entry = parser.VisualSampleEntry; // Read the properties. properties = new Properties (mvhd_box.Duration, audio_sample_entry, visual_sample_entry); } finally { Mode = AccessMode.Closed; } }
/// <summary> /// Reads the file with a specified read style. /// </summary> /// <param name="propertiesStyle"> /// A <see cref="ReadStyle" /> value specifying at what level /// of accuracy to read the media properties, or <see /// cref="ReadStyle.None" /> to ignore the properties. /// </param> private void Read(ReadStyle propertiesStyle) { // TODO: Support Id3v2 boxes!!! tag = new CombinedTag(); Mode = AccessMode.Read; try { FileParser parser = new FileParser(this); if (propertiesStyle == ReadStyle.None) { parser.ParseTag(); } else { parser.ParseTagAndProperties(); } InvariantStartPosition = parser.MdatStartPosition; InvariantEndPosition = parser.MdatEndPosition; udta_box = parser.UserDataBox; if (udta_box != null && udta_box.GetChild(BoxType.Meta) != null && udta_box.GetChild(BoxType.Meta ).GetChild(BoxType.Ilst) != null) { TagTypesOnDisk |= TagTypes.Apple; } if (udta_box == null) { udta_box = new IsoUserDataBox(); } apple_tag = new AppleTag(udta_box); tag.SetTags(apple_tag); // If we're not reading properties, we're done. if (propertiesStyle == ReadStyle.None) { Mode = AccessMode.Closed; return; } // Get the movie header box. IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox; if (mvhd_box == null) { Mode = AccessMode.Closed; throw new CorruptFileException( "mvhd box not found."); } IsoAudioSampleEntry audio_sample_entry = parser.AudioSampleEntry; IsoVisualSampleEntry visual_sample_entry = parser.VisualSampleEntry; // Read the properties. properties = new Properties(mvhd_box.Duration, audio_sample_entry, visual_sample_entry); } finally { Mode = AccessMode.Closed; } }
/// <summary> /// Reads the file with a specified read style. /// </summary> /// <param name="propertiesStyle"> /// A <see cref="ReadStyle" /> value specifying at what level /// of accuracy to read the media properties, or <see /// cref="ReadStyle.None" /> to ignore the properties. /// </param> private void Read(ReadStyle propertiesStyle) { // TODO: Support Id3v2 boxes!!! tag = new CombinedTag (); Mode = AccessMode.Read; try { FileParser parser = new FileParser (this); if (propertiesStyle == ReadStyle.None) parser.ParseTag (); else parser.ParseTagAndProperties (); InvariantStartPosition = parser.MdatStartPosition; InvariantEndPosition = parser.MdatEndPosition; udta_boxes.AddRange(parser.UserDataBoxes); // Ensure our collection contains at least a single empty box if (udta_boxes.Count == 0) { IsoUserDataBox dummy = new IsoUserDataBox (); udta_boxes.Add(dummy); } // Check if a udta with ILST actually exists if (IsAppleTagUdtaPresent ()) TagTypesOnDisk |= TagTypes.Apple; //There is an udta present with ILST info // Find the udta box with the Apple Tag ILST IsoUserDataBox udtaBox = FindAppleTagUdta(); if (null == udtaBox) { udtaBox = new IsoUserDataBox(); } apple_tag = new AppleTag (udtaBox); tag.SetTags (apple_tag); // If we're not reading properties, we're done. if (propertiesStyle == ReadStyle.None) { Mode = AccessMode.Closed; return; } // Get the movie header box. IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox; if(mvhd_box == null) { Mode = AccessMode.Closed; throw new CorruptFileException ( "mvhd box not found."); } IsoAudioSampleEntry audio_sample_entry = parser.AudioSampleEntry; IsoVisualSampleEntry visual_sample_entry = parser.VisualSampleEntry; // Read the properties. properties = new Properties (mvhd_box.Duration, audio_sample_entry, visual_sample_entry); } finally { Mode = AccessMode.Closed; } }