【问题标题】:Is it possible, using TagLibSharp, to remove a Lyrics3v2 tag from a MP3 file?是否可以使用 TagLibSharp 从 MP3 文件中删除 Lyrics3v2 标签?
【发布时间】:2016-08-26 01:55:39
【问题描述】:

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

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

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

另外,暴露TagLibSharp类的Lyrics属性似乎对Lyrics3v2标签没有影响,这一切都非常令人困惑。

【问题讨论】:

  • 这个问题应该重新打开,首先我的问题是针对特定库的,而不是针对 mp3 结构本身的,其次,我使用 taglibsharp 编写了一个可行的解决方案,但我无法分享答案因为我的问题被阻止了。我真的很想发布解决方案,版主可以在此之后阻止它。
  • 如果他们没有重新打开您的问题,请将您的工作解决方案添加到另一个链接的问题作为第二个答案。我真的很想看看你的解决方案!谢谢。
  • @PeterCo 我发布了它:stackoverflow.com/questions/26671210/… 我希望它对您或其他人有用。
  • @ElektroStudios:我重新提出了这个问题。您现在可以从stackoverflow.com/q/26671210/444991 中删除您的答案,然后在此处重新发布。

标签: c# .net vb.net mp3 taglib-sharp


【解决方案1】:

根据How to remove Lyrics3 v2 tag from id3?,答案是“否”。您将在下面的 linked 答案中找到解决方法。

【讨论】:

    【解决方案2】:

    我使用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
    

    示例用法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 2017-06-04
      相关资源
      最近更新 更多