簡體   English   中英

是否可以使用TagLibSharp從MP3文件中刪除Lyrics3v2標簽?

[英]Is it possible, using TagLibSharp, to remove a Lyrics3v2 tag from a MP3 file?

我想知道是否可以使用TagLibSharp庫從MP3文件中刪除Lyrics3v2標簽類型。

文件說,該塊條目以詞“LYRICSBEGIN”開始,以“LYRICS200”結尾,它也說,ID3標簽應該存在讓存在Lyrics3v2標簽...但它沒有指定是否reffers到的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

''' <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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM