PUID Generator 2.3 - Updated 18/07/2010

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

PUID Generator 2.3 - Updated 18/07/2010

Postby trixmoto on Tue Jan 05, 2010 12:03 am

This new script was requested here... viewtopic.php?f=2&t=45560

It is designed to process all the selected tracks in the background, looping through them and generating the PUID. You will be asked to enter a field name which is one of the SongData properties. You will then get a confirmation screen before processing begins. Just a warning, this takes around 10 seconds per track, so don't select too many unless you've got plenty of time to spare! :)

As always, the installation package can be downloaded from my website. Here is this code...

Code: Select all
'
' MediaMonkey Script
'
' NAME: PUIDGenerator 2.3
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 18/07/2010
'
' Thanks to Steegy for the SkinnedInputBox
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
'          Don't forget to remove comments (') and set the order appropriately
'
' [PUIDGenerator]
' FileName=MIPT\PUIDGenerator.vbs
' ProcName=PUIDGenerator
' Order=50
' DisplayName=&PUID Generator
' Description=Generate PUID for selected tracks
' Language=VBScript
' ScriptType=0
'
' FIXES: Fixed AAC files should not have analysis archived
'

Option Explicit
Dim Archive : Archive = True

Sub PUIDGenerator
  'get selected tracks
  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("PUIDGenerator: There are no selected tracks.",mtError,Array(mbOk))
    Exit Sub
  End If
 
  'get field name
  Dim temp : temp = SDB.IniFile.StringValue("PUIDGenerator","Field")
  Dim name : name = SkinnedInputBox("Please enter field name:","PUIDGenerator",temp,"PUIDGenerator")
  SDB.IniFile.StringValue("PUIDGenerator","Field") = name
 
  'check field name
  If name = "" Then
    Call SDB.MessageBox("PUIDGenerator: No field name was specified.",mtError,Array(mbOk))
    Exit Sub
  Else
    On Error Resume Next
    Execute("temp = list.Item(0)."&name)   
    If Err.Number <> 0 Then
      Err.Clear
      Call SDB.MessageBox("PUIDGenerator: Invalid field name was specified.",mtError,Array(mbOk))
      Exit Sub
    End If
    Execute("list.Item(0)."&name&" = """"")
    If Err.Number <> 0 Then
      Err.Clear
      Call SDB.MessageBox("PUIDGenerator: Numeric field was specified.",mtError,Array(mbOk))
      Exit Sub
    Else
      Execute("list.Item(0)."&name&" = temp")
    End If
    On Error Goto 0
  End If
 
  'check application
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  If Not (fso.FileExists(SDB.ScriptsPath&"MIPT\genpuid.exe")) Then
    Call SDB.MessageBox("PUIDGenerator: File 'genpuid.exe' is missing - search failed.",mtError,Array(mbOk))
    Exit Sub
  End If
  If Not (fso.FileExists(SDB.ScriptsPath&"MIPT\mipcore.exe")) Then
    Call SDB.MessageBox("PUIDGenerator: File 'micpcore.exe' is missing - search failed.",mtError,Array(mbOk))
    Exit Sub
  End If
  If Not (fso.FileExists(SDB.ScriptsPath&"MIPT\libexpat.dll")) Then
    Call SDB.MessageBox("PUIDGenerator: File 'libexpat.dll' is missing - search will be limited.",mtInformation,Array(mbOk))
  End If     
 
  'user confirmation
  Dim k : k = SDB.MessageBox("PUIDGenerator: Populate field '"&name&"' with PUID for "&list.Count&" tracks?",mtConfirmation,Array(mbYes,mbNo))
  If Not (k = mrYes) Then
    Exit Sub
  End If 

  'create progress bar
  Set SDB.Objects("PUID-Data") = SDB.NewSongData
  Dim prog : Set prog = SDB.Progress
  prog.Value = 0
  prog.MaxValue = list.Count
  prog.Text = "PUIDGenerator: Initialising..."
 
  'initialise 
  Dim wsh : Set wsh = CreateObject("WScript.Shell")
  Dim loc : loc = wsh.ExpandEnvironmentStrings("%TEMP%")
  If Right(loc,1) = "\" Then
    loc = loc&"PUID.xml"
  Else
    loc = loc&"\PUID.xml"
  End If
  Dim tmp : Set tmp = fso.CreateTextFile(loc,True)
  Call tmp.Close()
  Dim exe : exe = fso.GetFile(SDB.ScriptsPath&"MIPT\genpuid.exe").ShortPath
  Dim dat : dat = fso.GetFile(loc).ShortPath
  Dim beg : beg = Timer   
  Dim num : num = 0
 
  'process tracks
  For k = 0 To list.Count-1
    Dim str : str = ""
    If k > 0 And list.Count > 3 Then
      Dim dif : dif = Timer-beg
      If dif < 0 Then
        dif = dif+86400
      End If     
      Dim sec : sec = (dif*list.Count/(k+1))-dif
      If num > 0 Then
        num = ((sec*.55)+(num*.45))
      Else
        num = sec
      End If
      Dim m : m = num\60
      Dim h : h = m\60 
      Dim s : s = num Mod 60
      m = (m Mod 60)
      If h > 0 Then
        If h > 1 Then
          str = h&" hours and "
        Else
          str = "1 hour and "
        End If
        If m = 1 Then
          str = str&"1 minute"
        Else
          str = str&m&" minutes"
        End If
      Else
        If m > 0 Then
          If m > 1 Then
            str = m&" minutes and "
          Else
            str = "1 minute and "
          End If   
        End If
        If s > 0 Then
          If s = 1 Then   
            str = str&"1 second"
          Else
            str = str&s&" seconds"
          End If
        End If
      End If
      str = " (time remaining: "&str&")"
    End If
    prog.Text = "PUIDGenerator: Processing track "&(k+1)&" of "&(list.Count)&str&"..."
    SDB.ProcessMessages
   
    'call application   
    If fso.FileExists(dat) Then
      fso.DeleteFile(dat)
    End If
    Dim itm : Set itm = list.Item(k)
    If fso.FileExists(itm.Path) Then
      Dim mp3 : mp3 = fso.GetFile(itm.Path).ShortPath   
      Dim cmd : cmd = "%comspec% /c "&exe&" f25c7a6acad172541066f475175465a7"
      If Archive Then
        Dim ext : ext = UCase(Right(mp3,4))
        If (ext = ".M4A") Or (ext = ".M4B") Then
          'don't archive
        Else
          cmd = cmd&" -archive"
        End If
      End If
      cmd = cmd&" -rmd=2 """&mp3&""" >"&dat
      Call wsh.Run(cmd,0,True)
      SDB.ProcessMessages
      If fso.FileExists(dat) Then
        Dim fil : Set fil = fso.OpenTextFile(dat,1,True)
        str = Replace(fil.ReadAll,"mip:","")
        Dim i : i = InStr(str,"file=")-1
        If i > 0 Then
          Dim j : j = InStr(Mid(str,i+7),"""")+i+8
          str = Left(str,i)&Mid(str,j)
        End If
        fil.Close()
        Set fil = fso.OpenTextFile(dat,2,True)
        fil.Write(str)
        fil.Close()
        SDB.ProcessMessages
        Dim xml : Set xml = CreateObject("Microsoft.XMLDOM")   
        xml.async = True     
        Call xml.Load(dat)
        Dim cnt : cnt = 0
        While (xml.readyState < 4 And cnt < 300)
          Call SDB.Tools.Sleep(100)
          SDB.ProcessMessages
          cnt = cnt+1
        WEnd     
        If xml.readyState > 3 Then
          If xml.parseError.errorCode = 0 Then
            For Each tmp In xml.getElementsByTagName("track")
              str = tmp.getAttribute("puid")           
              If Not (str = "") Then
                Dim val : val = ""
                Execute("val = itm."&name)
                If Not (val = str) Then
                  Execute("itm."&name&" = str")
                  Dim l : Set l = SDB.NewSongList
                  Call l.Add(itm)
                  Call l.UpdateAll()
                End If
                Exit For             
              End If
            Next
          End If
        End If
      End If       
    End If
    prog.Increase
    SDB.ProcessMessages
    If prog.Terminate Then
      Set SDB.Objects("PUID-Data") = Nothing
      Exit Sub
    End If
  Next
  Set SDB.Objects("PUID-Data") = Nothing     
End Sub

Function SkinnedInputBox(Text, Caption, Input, PositionName)
   Dim Form, Label, Edt, btnOk, btnCancel, modalResult

   ' Create the window to be shown
   Set Form = SDB.UI.NewForm
   Form.Common.SetRect 100, 100, 360, 130
   Form.BorderStyle  = 2   ' Resizable
   Form.FormPosition = 4   ' Screen Center
   Form.SavePositionName = PositionName
   Form.Caption = Caption
     
   ' Create a button that closes the window
   Set Label = SDB.UI.NewLabel(Form)
   Label.Caption = Text
   Label.Common.Left = 5
   Label.Common.Top = 10
     
   Set Edt = SDB.UI.NewEdit(Form)
   Edt.Common.Left = Label.Common.Left
   Edt.Common.Top = Label.Common.Top + Label.Common.Height + 5
   Edt.Common.Width = Form.Common.Width - 20
   Edt.Common.ControlName = "Edit1"
   Edt.Common.Anchors = 1+2+4 'Left+Top+Right
   Edt.Text = Input
       
   ' Create a button that closes the window
   Set BtnOk = SDB.UI.NewButton(Form)
   BtnOk.Caption = "&OK"
   BtnOk.Common.Top = Edt.Common.Top + Edt.Common.Height + 10
   BtnOk.Common.Hint = "OK"
   BtnOk.Common.Anchors = 4   ' Right
   BtnOk.UseScript = Script.ScriptPath
   BtnOk.Default = True
   BtnOk.ModalResult = 1
   
   Set BtnCancel = SDB.UI.NewButton(Form)
   BtnCancel.Caption = "&Cancel"
   BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width - 15
   BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width - 10
   BtnCancel.Common.Top = BtnOK.Common.Top
   BtnCancel.Common.Hint = "Cancel"
   BtnCancel.Common.Anchors = 4   ' Right
   BtnCancel.UseScript = Script.ScriptPath
   BtnCancel.Cancel = True
   BtnCancel.ModalResult = 2
       
   If Form.showModal = 1 Then
     SkinnedInputBox = Edt.Text
   Else
     SkinnedInputBox = ""
   End If 
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("PUIDGenerator","Filename") = "MIPT\PUIDGenerator.vbs"
    inif.StringValue("PUIDGenerator","Procname") = "PUIDGenerator"
    inif.StringValue("PUIDGenerator","Order") = "50"
    inif.StringValue("PUIDGenerator","DisplayName") = "&PUID Generator"
    inif.StringValue("PUIDGenerator","Description") = "Generate PUID for selected tracks"
    inif.StringValue("PUIDGenerator","Language") = "VBScript"
    inif.StringValue("PUIDGenerator","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Getting "Product Installation Error" when installing scripts? - Try this
Subscribe to my RSS feed for all the latest news
trixmoto
 
Posts: 8509
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby Bex on Tue Jan 05, 2010 12:58 am

Nice one, I like it! :D
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
Bex
 
Posts: 5924
Joined: Fri May 21, 2004 10:44 am
Location: Sweden

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby gpzbc on Tue Jan 05, 2010 1:27 am

Thanks for developing this Trixmoto! It seems like it could really be handy. MusicIP is pretty cool.

Although, I'm having a hard time convincing myself that my library needs this. Can someone explain a scenario where they use PUID's and where they would be valuable?
--
The gpzbc
gpzbc
 
Posts: 644
Joined: Sat Sep 13, 2008 5:02 am
Location: Colorado, USA

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby nynaevelan on Tue Jan 05, 2010 1:32 am

Thanks I am going to give this a whirl. :D
3.2x - Win7 Ultimate (Zen X-Fi 32GB/Zen 8GB/Zen Vision M 60GB)
Link to Favorite Scripts/Skins
nynaevelan
 
Posts: 4712
Joined: Thu Feb 08, 2007 4:07 am
Location: New Jersey, USA

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby trixmoto on Tue Jan 05, 2010 9:40 am

In the next version of my "MusicIP Tagger" script you will be able to use existing PUID values instead of recalculating them, so separating this processing would make the tagging part much quicker. I guess any script that calls MusicBrainz or MusicIP could use this value, in fact I might add it as an external panel to "Monkey Rok" in the next version as well.
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Getting "Product Installation Error" when installing scripts? - Try this
Subscribe to my RSS feed for all the latest news
trixmoto
 
Posts: 8509
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby nynaevelan on Tue Jan 05, 2010 3:12 pm

Cool, and it worked like a charm. :D
3.2x - Win7 Ultimate (Zen X-Fi 32GB/Zen 8GB/Zen Vision M 60GB)
Link to Favorite Scripts/Skins
nynaevelan
 
Posts: 4712
Joined: Thu Feb 08, 2007 4:07 am
Location: New Jersey, USA

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby gpzbc on Tue Jan 05, 2010 4:05 pm

sounds good! Thanks Trixmoto!
--
The gpzbc
gpzbc
 
Posts: 644
Joined: Sat Sep 13, 2008 5:02 am
Location: Colorado, USA

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby jimmy1one on Thu Jan 07, 2010 5:49 am

Thanks, A great script as always it's like a gift from heaven to a Blues lover
jimmy1one :wink:

OK there seems to be a problem on my end. I entered Lyricist the script returned
eae32853-09d9-5fbe-f1b1-a3b8b43c7311. This is just an example it returns a different value for each song
For example it returned 94b19084-38ba-8e15-4f82-c8155b6f198a as the lyricist for 702 Finally. I have the lyrics for the song on file but not the lyricist or composer. Am I missing the idea, lyricist is in the Songdata file as a viable field? Again thanks in advance for any help you maybe able to provide
jimmy1one
Never let the truth influence your opinion, you can't fix stupid
jimmy1one
 
Posts: 14
Joined: Tue Sep 22, 2009 11:52 am

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby nynaevelan on Thu Jan 07, 2010 2:23 pm

JImmy:

You are using the wrong script, this one only downloads the PUID for the track. You want to use Trixmoto's MusicIP Tagger or maybe one of the other web taggers in order to download the lyricist's info.
3.2x - Win7 Ultimate (Zen X-Fi 32GB/Zen 8GB/Zen Vision M 60GB)
Link to Favorite Scripts/Skins
nynaevelan
 
Posts: 4712
Joined: Thu Feb 08, 2007 4:07 am
Location: New Jersey, USA

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby jimmy1one on Fri Jan 08, 2010 11:52 am

Thanks nynaevelan what I'm getting is the identifier. I already use the MusicIP script to get the tag info. It's just that I need more info than is available from the services it's not the flaw of the scripts. I'm just trying to find a way to finish this project in my life time :lol: Thanks again
jimmy
Never let the truth influence your opinion, you can't fix stupid
jimmy1one
 
Posts: 14
Joined: Tue Sep 22, 2009 11:52 am

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby trixmoto on Fri Jan 08, 2010 6:41 pm

What other information are you after?
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Getting "Product Installation Error" when installing scripts? - Try this
Subscribe to my RSS feed for all the latest news
trixmoto
 
Posts: 8509
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby Vyper on Sat Jan 09, 2010 10:28 pm

I've been trying to understand all this PUID business and I think I do now but I do have one question. You say it asks for a field to use, does it matter? What field should I use?
Stop Button Freak
Vyper
 
Posts: 690
Joined: Tue May 23, 2006 10:53 pm

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby nynaevelan on Sat Jan 09, 2010 10:31 pm

I used custom4, it was previously used, but I switched things around because I wanted a field that is selectable as a viewable column. With the help of this script and Trixmoto's MusicIP script, I was able to use Bex's Adv Dupe Find & Fix scritp to find additional dupes.
3.2x - Win7 Ultimate (Zen X-Fi 32GB/Zen 8GB/Zen Vision M 60GB)
Link to Favorite Scripts/Skins
nynaevelan
 
Posts: 4712
Joined: Thu Feb 08, 2007 4:07 am
Location: New Jersey, USA

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby Vyper on Sat Jan 09, 2010 10:54 pm

Cool. Thanks Nyn. :)
Stop Button Freak
Vyper
 
Posts: 690
Joined: Tue May 23, 2006 10:53 pm

Re: PUID Generator 1.0 [MM3] - Created 04/01/2010

Postby trixmoto on Sun Jan 10, 2010 11:55 am

The field is just the one which is used to store the value, so you can select any field which you are not already using for something else.
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Getting "Product Installation Error" when installing scripts? - Try this
Subscribe to my RSS feed for all the latest news
trixmoto
 
Posts: 8509
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Next

Return to Need Help with Addons?

Who is online

Users browsing this forum: Ask Jeeves [Bot], Google [Bot], MSN [Bot] and 7 guests