Import Tags From Text file

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

iwas15
Posts: 3
Joined: Mon Jan 24, 2022 2:26 am

Import Tags From Text file

Post by iwas15 »

I have been replacing my MM5 MP3 music with a new collection of FLAC files. I have exported to a text file all my MP3 TAGS for each Album and Track. I now want to IMPORT all the TAGS to my NEW FLAC files.
I recently found a vbs script written way back in 2008 (See listing below). This script is designed to do what I require and import from a text file my music tags.
I am runninng MM5.0.4.2690 and as far as I can see vbs scripts are not supported only mmip.

Is there ANYONE on this forum that can convert this VBS script to a Media Monkey mmip file?

Here's hoping

David Parker
-----------------------------------------------------------------------------------------------------------
'Forum: http://mediamonkey.com/forum/viewtopic. ... =15#p71332

Code: Select all

'Modified by Eyal 2008-09-15, 2011-03-05 & 2011-07-04.
Option Explicit

Sub OnStartUp
      Dim MenuItem
      Set MenuItem = SDB.UI.AddMenuItem(SDB.UI.Menu_Tools, 1, -3)
         MenuItem.Caption = "Auto-Tag from Tag-List..."
         MenuItem.IconIndex = 26
         MenuItem.UseScript = Script.ScriptPath
         MenuItem.OnClickFunc = "TagFromTagList"
      Set MenuItem = Nothing
End Sub

Sub TagFromTagList(MenuItem)
   Dim Form, Label, Button, Dialog, DropDownMask
   Dim EditPath, DropDownMaskMask
   Dim FileSys, File
   Set FileSys = CreateObject("Scripting.FileSystemObject")
   Dim Content
   Dim a
   
   Set Form = SDB.UI.NewForm
   Form.Common.SetRect 0, 0, 310, 180
   Form.FormPosition = 4   ' Screen Center
   Form.BorderStyle = 3    ' Dialog
   Form.Caption = "Auto-Tag from Tag-List"
   
   Set Label = SDB.UI.NewLabel(Form)
   Label.Common.SetRect 10, 15, 280, 18
   Label.Caption = "Tag-List File:"
   
   Set EditPath = SDB.UI.NewEdit(Form)
   EditPath.Common.SetRect 10, 30, 280, 18
   EditPath.Text = SDB.SelectedSongList.Item(0).Path      'Mod by Eyal: use path of first selected track.
   
   Set Dialog = SDB.CommonDialog
   Dialog.InitDir = EditPath.Text
   Dialog.Filter = "*.txt|*.txt|*.csv|*.csv|*.*|*.*"
   Dialog.ShowOpen
   if Dialog.OK then
      EditPath.Text = Dialog.Filename
      
      'show first line of file
      Set File = FileSys.OpenTextFile(EditPath.Text, 1, False, -1)
         Set Label = SDB.UI.NewLabel(Form)
        Label.Common.SetRect 10, 94, 280, 18
        Content   = File.ReadLine
         If Left(Content, 3) = "" Then Content = Mid(Content, 4)
         Label.Caption = Content
      Set File = Nothing
   Else
	Exit Sub
   end if
   Set Dialog = Nothing
    Set Label = SDB.UI.NewLabel(Form)
  Label.Common.SetRect 10, 54, 280, 18
  Label.Caption = "Mask:"
   
   Set DropDownMask = SDB.UI.NewDropDown(Form)
  DropDownMask.Common.SetRect 10, 69, 280, 18
   DropDownMask.Common.Hint = "<Tabulator>" & Chr(13)
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & "<Return>" & Chr(13)
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%T") & Chr(13) '<Track#>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%S") & Chr(13) '<Title>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%A") & Chr(13) '<Artist>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%R") & Chr(13) '<Album Artist>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%L") & Chr(13) '<Album>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%Y") & Chr(13) '<Year>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%G") & Chr(13) '<Genre>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%B") & Chr(13) '<Bitrate>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%M") & Chr(13) '<BPM>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%C") & Chr(13) '<Composer>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%P") & Chr(13) '<Folder>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%F") & Chr(13) '<Filename>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%X") & Chr(13) '<Skip>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%ZH") & Chr(13) '<Original Artist>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%ZD") & Chr(13) '<Comment>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%U") & Chr(13) '<Custom1>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%V") & Chr(13) '<Custom2>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%W") & Chr(13) '<Custom3>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%J") & Chr(13) '<Custom4>
   DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%K")           '<Custom5>
   
      
   for a = 1 to 10
      Content = SDB.INIFile.StringValue("TagsFromFileList", "LastMask" & a)
      if Content <> "" then
         DropDownMask.AddItem(Content)
         if a = 1 then DropDownMask.Text = Content
      end if
   next

  Set Button = SDB.UI.NewButton( Form)
  Button.Caption = SDB.Localize("&Ok")
  Button.Common.SetRect 115, 110, 75, 25
  Button.ModalResult = 1
  Button.Default = True

  Set Button = SDB.UI.NewButton( Form)
  Button.Caption = SDB.Localize("&Cancel")
  Button.Common.SetRect 215, 110, 75, 25
  Button.ModalResult = 2
  Button.Cancel = True

  if Form.ShowModal = 1 then
     Dim Tracks, Track
     Dim FileListPos
     Dim Mask, MaskLines
     Dim TagListContent, TagListLines, LastFileListPos
     Dim intTemp
    
     Set Tracks = SDB.SelectedSongList
      
      for a = 1 to 10
         SDB.INIFile.DeleteKey "TagsFromFileList", "LastMask" & a
      next
      for a = 0 to DropDownMask.ItemCount
         if a = 0 then
            Content = DropDownMask.Text
         else
            Content = DropDownMask.ItemText(a - 1)
         end if
         if Content <> "" then SDB.INIFile.StringValue("TagsFromFileList", "LastMask" & (a + 1)) = Content
         
         'clear Duplicates in DropDownList
         for intTemp = a to DropDownMask.ItemCount - 1
            if DropDownMask.ItemText(intTemp) = Content then DropDownMask.DeleteItem(intTemp)
         next
      next
    
      if not SDB.Tools.FileSystem.FileExists(EditPath.Text) then
         SDB.MessageBox "File " & EditPath.Text & " not found!", mtError, Array(mbOK)
         Exit Sub
      end if
    
     Set File = FileSys.OpenTextFile(EditPath.Text, 1, False, -1)
    
     Mask = SDB.Tools.UFText2Mask(DropDownMask.Text)
     Mask = Replace(Mask, "<Tabulator>", Chr(9))
      Mask = Replace(Mask, "<Return>", Chr(13))
     MaskLines = Count(Mask, Chr(13))
    
     TagListContent = File.ReadAll
     
    'modified by MJM 01-05-2007
    TagListLines = Count(TagListContent, Chr(13)) - 1 
    
    'MsgBox "Int(TagListLines / MaskLines): " & Int(TagListLines / MaskLines) 
    'MsgBox "TagListLines / MaskLines: " & TagListLines / MaskLines 
    
     If (TagListLines / MaskLines) <> Int(TagListLines / MaskLines) Then
         if TagListLines <> (Int(TagListLines / MaskLines)*MaskLines + 1) then
            SDB.MessageBox "Number of Lines in Tag-List and Mask doesn't fit!", mtError, Array(mbOK)
          Exit Sub
         end if
     End If
     If Tracks.Count <> Int(TagListLines / MaskLines) Then
         SDB.MessageBox "Number of Lines in Tag-List and Track-List doesn't fit!", mtError, Array(mbOK)
       Exit Sub
     End If
    
     FileListPos = 0
     LastFileListPos = 0
     TagListContent = TagListContent + Chr(13)
     For intTemp = 1 To (TagListLines / MaskLines) 'soviele Tracks
         Set Track = Tracks.Item(intTemp - 1)
      
       For a = 1 To MaskLines
         FileListPos = InStr(FileListPos + 1, TagListContent, Chr(13))
       Next
       Content = Trim(Mid(TagListContent, LastFileListPos + 1, FileListPos - LastFileListPos-1))
         If Left(Content, 3) = "" Then Content = Mid(Content, 4)
         'necessary for ParseText:
         if InStr(Mask, "%A") then Track.ArtistName = ""
         if InStr(Mask, "%L") then Track.AlbumName = ""
         if InStr(Mask, "%R") then Track.AlbumArtistName = ""
         if InStr(Mask, "%G") then Track.Genre = ""

         Track.ParseText Content, Mask

       LastFileListPos = FileListPos + 1
         Set Track = Nothing
     Next
      
      'Refresh Screen
      SDB.MainTracksWindow.RemoveSelectedTracks
      for a = 0 to Tracks.Count - 1
         SDB.MainTracksWindow.AddTrack(Tracks.Item(a))
      next
      SDB.MainTracksWindow.FinishAdding
    
     If SDB.MessageBox("Correct?", mtConfirmation, Array(mbYes, mbNo)) = mrYes Then
       Tracks.UpdateAll
     Else
       SDB.MainTracksWindow.Refresh
     End If
  End if
End Sub

Function Count(Text, Seperator)
   Dim intTemp
   Count = 0
   intTemp = 1
   Do
     Count = Count + 1
     intTemp = InStr(intTemp + 1, Text, Seperator)
   Loop While intTemp > 0
End Function
Lowlander
Posts: 56659
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Re: Import Tags From Text file

Post by Lowlander »

MMIP is the container, for MediaMonkey 4 it would use VBS most commonly. MediaMonkey 5 moved to JavaScript: viewtopic.php?t=86756
joshb
Posts: 27
Joined: Fri Dec 30, 2011 3:34 pm

Re: Import Tags From Text file

Post by joshb »

David - I suggest you try free program MP3tag
https://www.mp3tag.de/en/
which can import tags in a text file and apply them to .FLAC files.
MP3tag can do this with tag masks and can read in text files that are CSV format, to apply several tags at a time to each .FLAC.
After you've tagged your .FLACS you can them import into MM5 and do further tagging there, and remember to "Auto-organize Files" to write your fixed-up titles etc. to the .FLAC filenames.

best, Josh
Post Reply