C# 是否可以使用TagLibSharp从MP3文件中删除Lyrics3v2标记?
我想知道是否可以使用库从MP3文件中删除Lyrics3v2标记类型 文档说明块条目以单词“LYRICSBEGIN”开头,以“LYRICS200”结尾,还说明应该存在ID3标记以允许存在Lyrics3v2标记……但它没有指定引用是指ID3v1还是ID3v2标记,或者他们中的任何一个,无论如何,我不理解这一部分,因为Lyrics3v2标签是一种单一的标签类型,不是ID3v1/ID3v2标签类型的一部分,它在mp3头上有自己的条目,所以。。。我不明白ID3v1/ID3v2“依赖性”是什么意思 无论如何,假设信息是正确的,那么我应该能够使用TagLibSharp从包含Lyrics3v2标记的mp3文件中删除ID3v1和ID3v2标记,然后该标记也将被删除?但是,该标记仍然存在C# 是否可以使用TagLibSharp从MP3文件中删除Lyrics3v2标记?,c#,.net,vb.net,mp3,taglib-sharp,C#,.net,Vb.net,Mp3,Taglib Sharp,我想知道是否可以使用库从MP3文件中删除Lyrics3v2标记类型 文档说明块条目以单词“LYRICSBEGIN”开头,以“LYRICS200”结尾,还说明应该存在ID3标记以允许存在Lyrics3v2标记……但它没有指定引用是指ID3v1还是ID3v2标记,或者他们中的任何一个,无论如何,我不理解这一部分,因为Lyrics3v2标签是一种单一的标签类型,不是ID3v1/ID3v2标签类型的一部分,它在mp3头上有自己的条目,所以。。。我不明白ID3v1/ID3v2“依赖性”是什么意思 无论如何
另外,暴露TagLibSharp类的
歌词
属性似乎对Lyrics3v2标记没有影响,所有这些都非常令人困惑。根据答案是“否”。您将在下面的链接答案中找到解决方法。我使用taglibsharp
编写了此解决方案:
' *************************************************************
' THIS CLASS IS PARTIALLY DEFINED FOR THIS STACKOVERFLOW ANSWER
' *************************************************************
Imports System.IO
Imports System.Text
Imports TagLib
''' <summary>
''' Represents the <c>Lyrics3</c> tag for a MP3 file.
''' </summary>
Public Class Lyrics3Tag
Protected ReadOnly mp3File As Mpeg.AudioFile
''' <summary>
''' The maximum length for the <c>Lyrics3</c> block to prevent issues like removing a false-positive block of data.
''' <para></para>
''' Note that this is a personal attempt to prevent catastrophes, not based on any official info.
''' </summary>
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
''' <summary>
''' Entirely removes the <c>Lyrics3</c> tag.
''' </summary>
<DebuggerStepThrough>
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
这个问题应该重新打开,首先,我的问题是针对特定的库,而不是mp3结构本身,其次,我使用taglibsharp编写了一个工作解决方案,但我无法共享答案,因为我的问题被阻止。我真的很想发布解决方案,之后版主可以阻止它。如果他们不重新打开你的问题,请将你的工作解决方案添加到另一个链接问题中作为第二个答案。我真的很想看看你的解决方案!谢谢。@PeterCo我出版了它:我希望它能对你或其他人有用。@ElektroStudios:我重新开始了这个问题。您现在可以从中删除答案,并将其重新发布在此处。
Dim mp3File As New Taglib.Mpeg.AudioFile("filepath")
Using lyrics As New Lyrics3Tag(mp3File)
lyrics.Remove()
End Using