Txt Importer 1.1 [MM2+3]

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Txt Importer 1.1 [MM2+3]

Post 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 
Last edited by trixmoto on Mon Jul 09, 2007 3:43 am, edited 3 times in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post 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.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Anyway to do this with an excel file

Post 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
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post 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! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

There is now an MM3 installation package available from my website for this script. :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
mhendu
Posts: 100
Joined: Thu Jan 12, 2006 11:18 am

Post 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!
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post 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! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
pictureman22
Posts: 5
Joined: Fri Dec 07, 2007 3:04 am

Post 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
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post 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
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
estebanrey
Posts: 4
Joined: Wed Feb 20, 2008 12:57 pm

Post 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:
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Very strange, I'm not sure. Which version of MM?
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
estebanrey
Posts: 4
Joined: Wed Feb 20, 2008 12:57 pm

Re: Txt Importer 1.1 [MM2+3]

Post 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 :(
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Txt Importer 1.1 [MM2+3]

Post 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.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
estebanrey
Posts: 4
Joined: Wed Feb 20, 2008 12:57 pm

Re: Txt Importer 1.1 [MM2+3]

Post 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.
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: Txt Importer 1.1 [MM2+3]

Post by Bex »

Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Post Reply