是否可以使用TagLibSharp从MP3文件中删除Lyrics3v2标签?

我想知道是否可以使用TagLibSharp库从MP3文件中删除Lyrics3v2标签类型。

文档说块条目以单词“ LYRICSBEGIN ”开头并以“ LYRICS200 ”结尾,同时它表示应该存在ID3标签以存在Lyrics3v2标签……但它没有指定是否引用ID3v1ID3v2标签,或其中任何一个,反正我不明白那部分,因为Lyrics3v2标签是单一标签类型,不是ID3v1 / ID3v2标签类型的一部分,它在mp3标头上有自己的条目所以……我不明白它对ID3v1 / ID3v2 “依赖”意味着什么。

无论如何假设信息是正确的,那么我应该能够使用TagLibSharp从包含Lyrics3v2标签的mp3文件中删除ID3v1ID3v2标签,然后该标签也将被删除?但是,标签仍然存在。

此外,暴露TagLibSharp类的Lyrics属性似乎不会影响Lyrics3v2标记,所有这些都非常令人困惑。

根据如何从id3中删除Lyrics3 v2标签? 答案是不”。 你会找到一个解决方法 关联 回答如下。

我用taglibsharp编写了这个解决方案:

 ' ************************************************************* ' THIS CLASS IS PARTIALLY DEFINED FOR THIS STACKOVERFLOW ANSWER ' ************************************************************* Imports System.IO Imports System.Text Imports TagLib '''  ''' Represents the Lyrics3 tag for a MP3 file. '''  Public Class Lyrics3Tag Protected ReadOnly mp3File As Mpeg.AudioFile '''  ''' The maximum length for the Lyrics3 block to prevent issues like removing a false-positive block of data. '''  ''' Note that this is a personal attempt to prevent catastrophes, not based on any official info. '''  Private ReadOnly maxLength As Integer = 512 ' bytes Private Sub New() End Sub Public Sub New(ByVal mp3File As Mpeg.AudioFile) Me.mp3File = mp3File End Sub '''  ''' Entirely removes the Lyrics3 tag. '''   Public Overridable Sub Remove() Dim initVector As New ByteVector(Encoding.UTF8.GetBytes("LYRICSBEGIN")) Dim initOffset As Long = Me.mp3File.Find(initVector, startPosition:=0) If (initOffset <> -1) Then ' The Lyrics3 block can end with one of these two markups, so we need to evaluate both. For Each str As String In {"LYRICS200", "LYRICSEND"} Dim endVector As New ByteVector(Encoding.UTF8.GetBytes(str)) Dim endOffset As Long = Me.mp3File.Find(endVector, startPosition:=initOffset) If (endOffset <> -1) Then Dim length As Integer = CInt(endOffset - initOffset) + (str.Length) If (length < Me.maxLength) Then Try Me.mp3File.Seek(initOffset, SeekOrigin.Begin) ' Dim raw As String = Me.mp3File.ReadBlock(length).ToString() Me.mp3File.RemoveBlock(initOffset, length) Exit Sub Catch ex As Exception Throw Finally Me.mp3File.Seek(0, SeekOrigin.Begin) End Try Else ' Length exceeds the max length. ' We can handle it or continue... Continue For End If End If Next str End If End Sub End Class 

用法示例:

 Dim mp3File As New Taglib.Mpeg.AudioFile("filepath") Using lyrics As New Lyrics3Tag(mp3File) lyrics.Remove() End Using