public override TagLib.Tag GetTag(TagTypes type, bool create) { TagLib.Tag tag = null; switch (type) { case TagTypes.Id3v2: if (id32_tag == null && create) { id32_tag = new Id3v2.Tag(); id32_tag.Version = 4; id32_tag.Flags |= Id3v2.HeaderFlags.FooterPresent; this.tag.CopyTo(id32_tag, true); } tag = id32_tag; break; case TagTypes.RiffInfo: if (info_tag == null && create) { info_tag = new InfoTag(); this.tag.CopyTo(info_tag, true); } tag = info_tag; break; case TagTypes.MovieId: if (mid_tag == null && create) { mid_tag = new MovieIdTag(); this.tag.CopyTo(mid_tag, true); } tag = mid_tag; break; case TagTypes.DivX: if (divx_tag == null && create) { divx_tag = new DivXTag(); this.tag.CopyTo(divx_tag, true); } tag = divx_tag; break; } this.tag.SetTags(id32_tag, info_tag, mid_tag, divx_tag); return(tag); }
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); } }
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); }
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); }
public override TagLib.Tag GetTag (TagTypes type, bool create) { TagLib.Tag tag = null; switch (type) { case TagTypes.Id3v2: if (id32_tag == null && create) { id32_tag = new Id3v2.Tag (); id32_tag.Version = 4; id32_tag.Flags |= Id3v2.HeaderFlags.FooterPresent; this.tag.CopyTo (id32_tag, true); } tag = id32_tag; break; case TagTypes.RiffInfo: if (info_tag == null && create) { info_tag = new InfoTag (); this.tag.CopyTo (info_tag, true); } tag = info_tag; break; case TagTypes.MovieId: if (mid_tag == null && create) { mid_tag = new MovieIdTag (); this.tag.CopyTo (mid_tag, true); } tag = mid_tag; break; case TagTypes.DivX: if (divx_tag == null && create) { divx_tag = new DivXTag (); this.tag.CopyTo (divx_tag, true); } tag = divx_tag; break; } this.tag.SetTags (id32_tag, info_tag, mid_tag, divx_tag); return tag; }