Page 1 of 2

Txt Importer 1.1 [MM2+3]

Posted: Wed Feb 21, 2007 6:03 am
by trixmoto
This is a new script, as requested here.

It imports tags from a .txt file matching the track filename. The .txt file should contain tags in this format...

Code: Select all

Title=New Title
Comment=This is my comment
The installer for this script can be downloaded from my website.

Code: Select all

'
' MediaMonkey Script
'
' NAME: TxtImporter 1.1
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 27/02/2007
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' FIXES: Added possibility of multiline tags
'
' [TxtImporter]
' FileName=TxtImporter.vbs
' ProcName=TxtImporter
' Order=30
' DisplayName=TxtImporter
' Description=Import tags from txt file
' Language=VBScript
' ScriptType=0
'

Option Explicit

Sub TxtImporter
  'get list
  Dim i : i = 0
  Dim list : Set list = SDB.SelectedSongList 
  If list.Count = 0 Then 
    Set list = SDB.AllVisibleSongList 
  End If 
  If list.Count = 0 Then 
    Call SDB.MessageBox("Select tracks to be tagged.", mtError, Array(mbOk)) 
    Exit Sub 
  Else
    i = SDB.MessageBox("Import tags for "&list.Count&" tracks?", mtConfirmation, Array(mbYes,mbCancel))  
    If Not (i = mrYes) Then
      Exit Sub
    End If
  End If 

  'progress bar
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim bar : Set bar = SDB.Progress
  bar.MaxValue = list.Count
  bar.Text = "TxtImporter: Initialising..."
  
  'tag each track
  For i = 0 To list.Count-1
    'progress bar
    bar.Text = "TxtImporter: Tagging track "&(i+1)&" of "&(list.Count)&"..."
    bar.Increase
    SDB.ProcessMessages
    
    'get path of txt
    Dim itm : Set itm = list.Item(i)
    Dim path : path = Left(itm.Path,InStrRev(itm.Path,"."))&"txt"
    If fso.FileExists(path) Then
      'read file
      Dim txt : Set txt = fso.OpenTextFile(path,1,False)
      Dim pre,val,tag,str,pos
      Do While Not txt.AtEndOfStream
        str = Trim(txt.ReadLine)
        pos = InStr(str,"=")
        If pos > 0 Then
          tag = Left(str,pos-1)
          val = Mid(str,pos+1)
          On Error Resume Next
          Execute("itm."&tag&" = """&val&"""")
          Err.Clear
          On Error Goto 0
        Else
          If Not (tag = "") Then
            On Error Resume Next
            Execute("itm."&tag&" = itm."&tag&"&Chr(13)&"""&str&"""") '!
            Err.Clear
            On Error Goto 0            
          End If
        End If
      Loop
      txt.close
    Else
    End If
    If bar.Terminate Then Exit Sub
  Next
  
  'finish off
  bar.Text = "TxtImporter: Finalising..."
  SDB.ProcessMessages
  list.UpdateAll
End Sub 

Posted: Tue Feb 27, 2007 10:20 am
by trixmoto
New version (1.1) is now available from my website. It allows the possibility of having multiline tags, like this...

Code: Select all

Title=Title
Comment=Line1
Line2
Artist=Test
Please note: The first equals (=) character in any line must be directly after the field name. For multiline tags, the additional lines cannot contain an equals (=) character at all.

Anyway to do this with an excel file

Posted: Fri Jul 06, 2007 4:00 pm
by Guest
This is great but I was wondering if there was anyway to convert that script so instead of an individual txt file it would use an excel file were column A would contain the filename, then columns B, C, .... Etc would contain the fields?

this way one could update a lot of their files at once?

Thanks

Posted: Mon Jul 09, 2007 3:41 am
by trixmoto
I think a script like that could be written, but it would certainly be a different script. It's on my to do list! :)

Posted: Fri Oct 26, 2007 5:25 am
by trixmoto
There is now an MM3 installation package available from my website for this script. :)

Posted: Thu Nov 01, 2007 2:46 am
by mhendu
Hi Trixmoto,

Did you ever create the script allowing for import of tags from a tab-separated text file? I found on this forum a script that does it right now but it's based on columns and not on filenames, so it will overwrite the tags for the wrong files if you're not careful. Would be much better if the script could read the filename from the first column, match it with the file in the database and then import the tags from the remaining columns. My primary use for this would be to import BPM ratings from MixMeister. The only other issue I can see is that MixMeister exports BPM to the 2nd decimal point (e.g., 122.45) and MediaMonkey will only allow integers to be imported, so currently I have to use Excel to round the results. Anyhow, thanks for all your great scripts, I use quite a few of them!

Posted: Sun Nov 04, 2007 12:28 pm
by trixmoto
Well this script assumes a single text file for each track. I don't know if there is one which takes the filenames out of a single file. Could be written though! :)

Posted: Fri Dec 07, 2007 3:08 am
by pictureman22
So I'm kind of new at this. I've downloaded the script. I can't figure out how to get to the txt file, I believe it should just find it. So I'm not sure where to save the txt file along with the name of the file.

Thanks in advance

Posted: Fri Dec 07, 2007 9:31 am
by trixmoto
This script tries to find textfiles with the same name as the music files. So, if your music file is...

F:\Music\The Beatles\1\Love Me Do.mp3

...then the textfile should be...

F:\Music\The Beatles\1\Love Me Do.txt

Posted: Sun Mar 02, 2008 4:18 pm
by estebanrey
Hi I'm having some trouble, I'm creating the text file but only some of the fields are updating. For example I have a file called "01 - Bounce.mp3" and I have created "01 - Bounce.txt" the same directory. The text file has these lines:

Artist=Justin Timberlake featuring Timbaland, Missy Elliott & Dr. Dre
Title=Bounce
Album=Recrimination
Date=2008
Genre=R&B/Hip Hop

Now when I run the scipt only Genre and Title update, everything else stays the same. What am I doing wrong? Apart from listening to Justin Timberlake :oops:

Posted: Fri Mar 07, 2008 7:30 am
by trixmoto
Very strange, I'm not sure. Which version of MM?

Re: Txt Importer 1.1 [MM2+3]

Posted: Sun Aug 17, 2008 12:04 pm
by estebanrey
Media Monkey 3.0.3

I just don't unerstand why some of the fields update and some don't. I tried copying your example text and still no joy :(

Re: Txt Importer 1.1 [MM2+3]

Posted: Sun Aug 17, 2008 1:05 pm
by trixmoto
You need to use the scripting name for the field, which might be different. Check out the wiki for the full list of fields.

Re: Txt Importer 1.1 [MM2+3]

Posted: Tue Aug 19, 2008 3:45 pm
by estebanrey
Thanks for your help trix, sorry to be a pain but where is the wiki? Again appreciate your help, this should be an awesome tool for me in combinataion with your custom excel reports and Automate software to write txt files from the fields almost instantly.

If I can get this to work I'll be able to get my entire collection right very quickly! Great work, keep it up.

Re: Txt Importer 1.1 [MM2+3]

Posted: Tue Aug 19, 2008 3:54 pm
by Bex