Import MPC as TXT 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:

Import MPC as TXT 1.1 [MM2+3]

Post by trixmoto »

This script imports an "MP3 Collectorz" database that has been exported as a TXT. It is a custom script so will probably need modifying for your own export.

A log file (.log) is created with your .txt database file, this lists any lines which could not be imported.

Please read this before using: http://www.mediamonkey.com/forum/viewtopic.php?t=6994

An installer can be download from my website (as always) :)

Code: Select all

'
' MediaMonkey Script
'
' NAME: ImportMPCasTXT 1.1
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 22/12/2005 
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' FIXES: More stable when converting numeric strings
'
' [ImportMPCasTXT]
' FileName=ImportMPCasTXT.vbs
' ProcName=ImportMPCasTXT
' Order=16
' DisplayName=Import MPC as TXT
' Description=Import MPC as TXT
' ScriptType=0 
'

Sub ImportMPCasTXT

  res = InputBox ("Enter filename of TXT to import:","Import MPC as TXT")
  Set progress = SDB.Progress
  progress.Text = "Initialising..."&res
  Set filesys = CreateObject("Scripting.FileSystemObject")
  If filesys.FileExists(res) Then
    progress.Text = "Creating logfile..."
    path = Left(res,InStrRev(res,"."))&"log"
    Set logfile = filesys.CreateTextFile(path, True)
    logfile.WriteLine("Import MPC as TXT") 
    logfile.WriteLine("By Trixmoto")
    logfile.WriteLine("")
    
    progress.Text = "Opening file: "&res
    logfile.WriteLine("Opening file: "&res)
    Set file = filesys.OpenTextFile(res, 1, false)
    If not file.AtEndOfStream Then
      line = file.ReadLine
      head = Split(line,chr(9))
      progress.Text = "Reading "&UBound(head)+1&" headers..."
      logfile.WriteLine("Number of fields = "&(UBound(head)+1))
      For i = 0 to UBound(head)
        head(i) = Mid(head(i),2,Len(head(i))-2)
      Next
    End If
    
    progress.Text = "Counting rows..."
    curr = 0
    count = 0
    total = 0
    Do while not file.AtEndOfStream
      line = file.ReadLine
      total = total + 1
    Loop
    progress.MaxValue = total
    logfile.WriteLine("Number of lines  = "&total)
    logfile.WriteLine("")
    
    Set file = filesys.OpenTextFile(res, 1, false)
    line = file.ReadLine
    Do while not file.AtEndOfStream
      line = file.ReadLine
      curr = curr + 1
      progress.Text = "Reading row "&curr&" of "&total&"..."
      progress.Value = curr
      row = Split(line,chr(9))
      If UBound(row) = UBound(head) Then
        count = count + 1
        Set track = SDB.NewSongData
        For i = 0 to UBound(row)
          field = Mid(row(i),2,Len(row(i))-2)
          If field <> "" Then
            Select Case head(i)
              Case "Filepath"
                track.Path = field
              Case "Track Artist" 
                track.ArtistName = field
              Case "Title"
                track.Title = field
              Case "Album"
                track.AlbumName = field
              Case "Length"
                track.SongLength = getmilli(field)
              Case "Size"
                track.FileLength = getbytes(field)
              Case "Format"
                'ignore
              Case "Bitrate"
                track.Bitrate = getbitrate(field)
              Case "Genre"
                track.Genre = field
              Case "Location"
                track.Custom1 = field
              Case "Notes"
                track.Comment = field
              Case "Year"
                If isNumeric(field) Then track.Year = Clng(field)
            End Select
          End If
        Next 
        track.updateDB
        Set track = Nothing
      Else
        logfile.WriteLine("Error on line "&curr&": "&line)
      End If
      If progress.Terminate Then Exit Do
    Loop
    
    If count = total Then
      If count = 0 Then
        res = SDB.MessageBox("Database not imported", mtError, Array(mbOk)) 
      Else
        res = SDB.MessageBox("Database successfully imported", mtError, Array(mbOk))
      End If
    Else
      If count < total Then
        res = SDB.MessageBox((total-count)&" rows could not be imported", mtError, Array(mbOk))
      Else
        res = SDB.MessageBox((count-total)&" rows have been imported more than once", mtError, Array(mbOk))
      End If
    End If
    
    logfile.WriteLine("")
    logfile.WriteLine("Number of lines read     = "&curr)
    logfile.WriteLine("Number of lines imported = "&count)
    logfile.WriteLine("Number of errors         = "&(curr-count))
    
    file.Close
    logfile.Close
    Set file = Nothing 
    Set logfile = Nothing
  Else
    res = SDB.MessageBox("This database could not be found", mtError, Array(mbOk))
  End If
  
  Set progress = Nothing
  Set filesys = Nothing

End Sub 

Function getmilli(str)
  mil = Clng(0)
  pos = InStr(str,":")
  str1 = Left(str,pos-1)
  If isNumeric(str1) Then
    str2 = Mid(str,pos+1,Len(str)-pos)
    If isNumeric(str2) Then
      min = Clng(str1)
      sec = Clng(str2)
      mil = sec*1000 + min*60000
    End If
  End If
  getmilli = Clng(mil)
End Function

Function getbytes(str)
  bs = Clng(0)
  str = Replace(str," KB","")
  str = Replace(str,".","")
  If isNumeric(str) Then
    bs = Clng(str)*1024
  End If
  getbytes = Clng(bs)
End Function

Function getbitrate(str)
  bps = Clng(0)
  pos = InStr(str,"k")
  str = Left(str,pos-1)
  If isNumeric(str) Then
    bps = Clng(str)*1000
  End If
  getbitrate = Clng(bps)
End Function

Sub Install()
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("ImportMPCasTXT","Filename") = "ImportMPCasTXT.vbs"
    inif.StringValue("ImportMPCasTXT","Procname") = "ImportMPCasTXT"
    inif.StringValue("ImportMPCasTXT","Order") = "16"
    inif.StringValue("ImportMPCasTXT","DisplayName") = "ImportMPCasTXT"
    inif.StringValue("ImportMPCasTXT","Description") = "Import MPC library as text"
    inif.StringValue("ImportMPCasTXT","Language") = "VBScript"
    inif.StringValue("ImportMPCasTXT","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Last edited by trixmoto on Wed Nov 07, 2007 12:07 pm, edited 4 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 »

:o NEW CODE BELOW :o
Last edited by trixmoto on Thu Dec 22, 2005 6:27 am, edited 1 time 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.
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

Let's not forget the script to relink imported database entries to their cd when it is entered. 8)
http://www.mediamonkey.com/forum/viewto ... 1039#31039

Cheers
Steegy
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I did ask them to read that whole thread, but yes, that script is certainly an important part of it! :)
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 more stable when importing numeric strings (file size, bitrate and song length).

Code: Select all

See first post
Last edited by trixmoto on Wed Nov 07, 2007 11:27 am, edited 1 time 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 »

Why have you quoted my code - did you not have anything to say?
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.
Lowlander
Posts: 56465
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Post by Lowlander »

This occurs frequently on the forum. Some "guest" things it's necessary to quote a post without posting any thing him/herself. Rather useless I think.
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Ive seen that alot! Could it be spammers who test something?
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
Lowlander
Posts: 56465
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Post by Lowlander »

I've checked the posts and there are no hidden links.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

An MM3 installation package is now available from my website.
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.
Post Reply