public Seek ( long offset ) : void | ||
offset | long |
/// A |
return | void |
private static void RemoveLyrics(TagLib.File mp3File) { var maxLength = 512; ByteVector initVector = new ByteVector(Encoding.UTF8.GetBytes("LYRICSBEGIN")); long initOffset = mp3File.Find(initVector, startPosition: 0); if ((initOffset != -1)) { // The Lyrics3 block can end with one of these two markups, so we need to evaluate both. foreach (string str in new[] { "LYRICS200", "LYRICSEND" }) { ByteVector endVector = new ByteVector(Encoding.UTF8.GetBytes(str)); long endOffset = mp3File.Find(endVector, startPosition: initOffset); if ((endOffset != -1)) { int length = System.Convert.ToInt32(endOffset - initOffset) + (str.Length); if ((length < maxLength)) { try { mp3File.Seek(initOffset, SeekOrigin.Begin); // Dim raw As String = Me.mp3File.ReadBlock(length).ToString() mp3File.RemoveBlock(initOffset, length); Console.WriteLine($"Removed lyrics in {mp3File.Name}"); return; } catch (Exception ex) { throw ex; } finally { mp3File.Seek(0, SeekOrigin.Begin); } } else { // We can handle it or continue... continue; } } } } }
public Tag(File file, long position) { if (file == null) { throw new ArgumentNullException("file"); } file.Mode = File.AccessMode.Read; if ((position < 0L) || (position > (file.Length - 0x80L))) { throw new ArgumentOutOfRangeException("position"); } file.Seek(position); ByteVector data = file.ReadBlock(0x80); if (!data.StartsWith(FileIdentifier)) { throw new CorruptFileException("ID3v1 data does not start with identifier."); } this.Parse(data); }
//Additional info here http://gabriel.mp3-tech.org/mp3infotag.html //https://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header /// <summary>See if the mp3 file is encoded using VBR. Not sure what to do with ABR... /// </summary> private bool IsVBR() { bool bVBR = false; if (currentFile.MimeType != "taglib/mp3") { return(false); } foreach (ICodec codec in currentFile.Properties.Codecs) { TagLib.Mpeg.AudioHeader header = (TagLib.Mpeg.AudioHeader)codec; // if (header == null) // return; if (header.XingHeader.Present) { currentFile.Mode = TagLib.File.AccessMode.Read; long XingHeader = currentFile.Find(TagLib.Mpeg.XingHeader.FileIdentifier); long Offset = TagLib.Mpeg.XingHeader.XingHeaderOffset(header.Version, header.ChannelMode); TagLib.Mpeg.XingHeader xing_header = TagLib.Mpeg.XingHeader.Unknown; currentFile.Seek(XingHeader);// + Offset); ByteVector xing_data = currentFile.ReadBlock(16); if (xing_data.Count == 16 && xing_data.StartsWith( TagLib.Mpeg.XingHeader.FileIdentifier)) { xing_header = new TagLib.Mpeg.XingHeader(xing_data); } int Flags = BitConverter.ToInt32(xing_data.Take(8).ToArray().Reverse().ToArray(), 0); bool FramesPresent = (Flags & 0x0001) > 0; bool BytesPresent = (Flags & 0x0002) > 0; bool TOCPresent = (Flags & 0x0004) > 0; bool QualityPresent = (Flags & 0x0008) > 0; long LameHeader = currentFile.Find(LAME_Identifier); if (QualityPresent) { //Header offset + 8 (XING + flags) + Frames, Bytes and TOC if available currentFile.Seek(XingHeader + 8 + 4 * (FramesPresent ? 1 : 0) + 4 * (BytesPresent ? 1 : 0) + 100 * (TOCPresent ? 1 : 0)); ByteVector Quality_data = currentFile.ReadBlock(4); int VBRQuality = BitConverter.ToInt32(Quality_data.ToArray().Reverse().ToArray(), 0); bVBR = true; } currentFile.Mode = TagLib.File.AccessMode.Closed; // if (xing_header.Present) // return false; // var vector = new TagLib.ByteVector(); // TagLib.ByteVector xing = header.; /* CODE HERE */ /* TagLib.File ref(fileName); * TagLib.Mpeg.File *file = dynamic_cast<TagLib.Mpeg.File *>(ref file()); * * if(!file) * return; * * TagLib.Mpeg.Properties *properties = file->audioProperties(); * const TagLib::MPEG::XingHeader *xingHeader = properties->xingHeader(); * * if(!xingHeader) * return; */ } if (header.VBRIHeader.Present) { /* CODE HERE */ } } return(bVBR); }