3

TagLibSharpライブラリを使用して、MP3 ファイルからLyrics3v2タグ タイプを削除することは可能でしょうか。

このドキュメントには、ブロック エントリが「 LYRICSBEGIN 」という単語で始まり「 LYRICS200」で終わると書かれています。また、 Lyrics3v2タグを存在させるには ID3 タグが存在する必要があると書かれています ...しかし、 ID3v1またはを参照するかどうかは指定していません。 ID3v2タグ、またはそれらのいずれか、とにかくその部分がわかりません.Lyrics3v2タグは単一のタグタイプであり、 ID3v1 / ID3v2タグタイプの一部ではないため、mp3ヘッダーに独自のエントリがあるため... ID3v1/ID3v2の「依存の意味がわかりません

とにかく、情報が正しいと仮定すると、TagLibSharpを使用して、 Lyrics3v2タグを含む mp3 ファイルからID3v1およびID3v2タグを削除できるはずですが、そのタグも削除されますか? ただし、タグはまだ存在します。

また、TagLibSharpLyricsのクラスを公開するプロパティは、 Lyrics3v2タグには影響しないようです。これはすべて非常に混乱しています。

4

2 に答える 2

3

id3 から Lyrics3 v2 タグを削除する方法によると? 答えはノーだ"。回避策はリンクされた以下に答えます。

于 2016-05-01T10:42:31.523 に答える
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
于 2016-05-06T08:51:41.457 に答える