Sub Write_Tags(Folder As String, PG As udtPrimaryGroup, PieceNo As Int)
' Set the music file source folder (same for mp3 and flac)
' DoV1, DoV2 and DoFlac are boolean properties set up when the class is initialized
setSourceFolder(Folder)
' PrimaryGroup info is here
mPG = PG
' Piece info is here:
mPiece = PG.Pieces(PieceNo)
Try
If DoV1 Or DoV2 Then
' Set the (MP3) filename
mFileName = $"${mPiece.FileStub}$2.0{mPiece.SourceTrack}.${mPiece.TrackFileExt}"$
' Check that the file (Folder, Name) exists:
If File.Exists(mSourceFolder, mFileName) Then
Dim Fi As JavaObject
Fi.InitializeNewInstance("java.io.File",Array(File.Combine(mSourceFolder, mFileName)))
audioFile = audioTaggerFileIO.RunMethod("read", Array(Fi))
If DoV1 Then
' TagType = "ID3v1"
' Not used: Method0 = "hasID3v1Tag"
' Method1 = "getID3v1Tag"
' Method2 = "createNewID3v1Tag"
Set_TagsToTagRecordPGValues ("ID3v1", "getID3v1Tag", "createNewID3v1Tag")
End If
If DoV2 Then
' TagType = "ID3v2"
' Not used: Method0 = "hasID3v2Tag"
' Method1 = "getID3v2Tag"
' Method2 = "createNewID3v2Tag"
Set_TagsToTagRecordPGValues ("ID3v2", "getID3v2TagAsv24", "createNewID3v2Tag")
End If
' Commit the result to the music file
audioFile.RunMethod("commit", Null)
End If
End If
If DoFlac Then
mFileName = $"${mPiece.FileStub}$2.0{mPiece.SourceTrack}.${mPiece.LTFE}"$
If File.Exists(mSourceFolder, mFileName) Then
Dim Fi As JavaObject
Fi.InitializeNewInstance("java.io.File", Array(File.Combine(mSourceFolder, mFileName)))
audioFile = audioTaggerFileIO.RunMethod("read", Array(Fi))
' TagType = "Flac"
' Not used: Method0 = "hasTag"
' Method1 = "getFlacTag"
' Method2 = "createNewFlacTag"
Set_TagsToTagRecordPGValues ("Flac", "getTag", "createNewFlacTag")
' Commit the result to the music file
audioFile.RunMethod("commit", Null)
End If
End If
Catch
If LastException.Message.Contains("No enum constant") Then
Log($"Enum FieldKey ${LastException.Message.SubString(LastException.Message.LastIndexOf("FieldKey")+9)} does not exist."$)
Log($"Skipping it."$)
Else
Log($"Write_Tags: ${LastException.Message}"$)
End If
End Try
End Sub
' eg. Set_TagsToFormValues ("ID3v2", "getID3v1Tag", "createNewID3v1Tag")
Sub Set_TagsToTagRecordPGValues (TagType As String, Method1 As String, Method2 As String)
Dim joTag As JavaObject
Dim Message1, Message2 As String
Try
Message1 = $"There is no ${TagType} tag."$
Message2 = $"There is STILL no ${TagType} tag."$
' Does a set of tags exist in this music file?
' Try to get the tag set
joTag = audioFile.RunMethod(Method1, Null)
' If it doesn't exist
If Not(joTag.IsInitialized) Then
' Create one
Log(Message1)
asJO(Me).RunMethod(Method2, Array(audioFile))
' Make sure it is written to the file on disk
audioFile.RunMethod("commit", Null)
' Try again
joTag = audioFile.RunMethod(Method1, Null)
End If
' Check again - Does a set of tags exist in this music file?
If joTag.IsInitialized Then
For Each K As String In mapTags.Keys
' Get the Tag Record
Dim TagRecord As udtTagRecord
TagRecord = mapTags.Get(K)
' Write it to the tag
asJO(Me).RunMethod("setTagContents", Array(joTag, TagRecord.joTagKey, TagRecord.PGValue))
Next
' Commit the result to the music file
audioFile.RunMethod("commit", Null)
Else
Log(Message2)
End If
Catch
If LastException.Message.Contains("No enum constant") Then
Log($"Enum FieldKey ${LastException.Message.SubString(LastException.Message.LastIndexOf("FieldKey")+9)} does not exist."$)
Log($"Skipping it."$)
Else
Log($"Process_Tags2: ${LastException.Message}"$)
End If
End Try
End Sub