Cue Tagger 1.1 - Created 10/03/2010

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Cue Tagger 1.1 - Created 10/03/2010

Re: Cue Tagger 1.1 - Created 10/03/2010

by trixmoto » Mon Dec 17, 2012 4:15 pm

No, this is a tagger script, so it appears as one of the source options when you try to tag tracks from the web.

Re: Cue Tagger 1.1 - Created 10/03/2010

by pbahnson » Sun Dec 16, 2012 7:21 pm

How do I run the script after installation? I expected Cue Tagger to appear with other scripts under the MM tools menu, but don't find it there. Using MM 4.0.7.xx
Best regards,
Peter B.

Re: Cue Tagger 1.1 - Created 10/03/2010

by trixmoto » Wed Mar 10, 2010 4:51 pm

New version (1.1) is now available to download from my website. As requested, I have added a special case which handles multiple files and a single cuesheet. This works if you have a folder of tracks (ie. "01.mp3", "02.mp3", "03.mp3"...) and a single cuesheet.

Re: Cue Tagger 1.0 - Created 03/02/2010

by Bex » Wed Feb 03, 2010 8:27 pm

Looks interesting, will check it out when I get some time! :)

Cue Tagger 1.1 - Created 10/03/2010

by trixmoto » Wed Feb 03, 2010 4:29 pm

This script was a request. It has been done as a "Auto-Tag from Web" source, so once installed you will need to select it as your source.

It is designed to loop through all the selected tracks and find a matching cuesheet (same filename with .cue on the end or instead of the track extension). It will then try and extract the album and artist details from this cuesheet.

As always, the installer is available to download from my website. Also the code is here...

Code: Select all

'
' MediaMonkey Script
'
' NAME: CueTagger 1.1
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 10/03/2010
'
' INSTALL: Copy to Scripts directory along with the images, then add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' [CueTagger]
' FileName=CueTagger.vbs
' ProcName=CueTagger
' Order=30
' DisplayName=Cue Tagger
' Description=Tag tracks using their cuesheet
' Language=VBScript
' ScriptType=3 
' 
' FIXES: Added special case for single cuesheet and numeric filenames
'

Option Explicit
Dim Debug : Debug = False

Sub StartSearch(Panel,SearchTerm,SearchArtist,SearchAlbum)
  If Debug Then 
    Call clear()
    Call out("StartSearch(Panel,"""&SearchTerm&""","""&SearchArtist&""","""&SearchAlbum&""")")
  End If
  Dim list : Set list = SDB.SelectedSongList
  
  'build panel
  Dim WB : Set WB = SDB.UI.NewActiveX(Panel,"Shell.Explorer")
  WB.Common.Align = 5
  WB.Common.ControlName = "WB"
  WB.Common.BringToFront
  
  'build query data
  Dim QD : Set QD = CreateObject("Scripting.Dictionary")
  QD.Item("cur") = -1
  QD.Item("tot") = 0
  QD.Item("max") = list.Count-1
  QD.Item("img") = "&nbsp;<img src=""file://"&Replace(SDB.ScriptsPath,"\","/")&"busy.gif"" border=""0"" alt=""Processing""/>"
 
  'build display
  Dim i : i = 0
  Dim src : src = Replace(SDB.ScriptsPath,"\","/")&"CueTagger.jpg"
  Dim html : html = "<div id=""header"" style=""float:left""><img src=""file://"&src&""" border=""0"" alt=""CueTagger""/></div>"  
  html = html&"<div id=""progress"" style=""float:left;font-family:'arial black';"">&nbsp;Progress: <span id=""percent""></span>"
  html = html&"<br />&nbsp;Success: <span id=""success""></span><br />&nbsp;Failure: <span id=""failure""></span></div>"
  If list.Count > 0 Then
    For i = 0 To list.Count-1
      Dim itm : Set itm = list.Item(i)
      QD.Item("sp"&i) = itm.Path
      QD.Item("id"&i) = itm.ID
      html = html&"<div id=""track"&i&""" style=""float:left;clear:left;font-family:'arial narrow';width:100%"">"&itm.Path
      html = html&" <span id=""result"&i&""" style=""color:red""> </span></div>"
    Next
  Else
    html = html&"<div id=""track"&i&""" style=""float:left;clear:left;font-family:'arial black';"">No tracks selected to tag!</div>"
  End If
  Call WB.SetHTMLDocument(html)  
  
  'show panel
  Dim res : Set res = SDB.NewStringList
  Call res.Add(SearchTerm)
  Call SDB.Tools.WebSearch.SetSearchResults(res)
  SDB.Tools.WebSearch.ResultIndex = 0
 
  'start timer
  Set SDB.Objects("CueTagger-WB") = WB
  Set SDB.Objects("CueTagger-QD") = QD
  Dim Tmr : Set Tmr = SDB.CreateTimer(50)
  Call Script.RegisterEvent(Tmr,"OnTimer","ContinueSearch")
End Sub

Sub ContinueSearch(Tmr)
  If Debug Then Call out("ContinueSearch(Tmr)")
  Call Script.UnregisterEvents(Tmr)
  
  'get document
  Dim WB : Set WB = SDB.Objects("CueTagger-WB")
  If WB Is Nothing Then
    Call out("WB Is Nothing!")
    Exit Sub
  End If
  Dim doc : Set doc = WB.Interf.Document  
  If doc Is Nothing Then
    Call out("Doc Is Nothing!")
    Exit Sub
  End If  
  
  'get query data
  Dim QD : Set QD = SDB.Objects("CueTagger-QD")
  If QD Is Nothing Then
    Call out("QD Is Nothing!")
    Exit Sub
  End If
  
  'update display
  Dim ele : Set ele = Nothing
  Dim cur : cur = Int(QD.Item("cur"))+1
  Dim max : max = Int(QD.Item("max"))
  Dim tot : tot = Int(QD.Item("tot"))  
  If cur > 0 Then
    Set ele = doc.getElementById("percent")
    If Not (ele Is Nothing) Then       
      ele.innerHTML = Round((cur*100)/(max+1))&"%"
    End If
    Set ele = doc.getElementById("success")
    If Not (ele Is Nothing) Then       
      ele.innerHTML = Round((tot*100)/cur)&"%"
    End If
    Set ele = doc.getElementById("failure")
    If Not (ele Is Nothing) Then       
      ele.innerHTML = Round(((cur-tot)*100)/cur)&"%"
    End If  
  End If
  If cur > max Then
    If Debug Then Call out("Finished")      
    Exit Sub
  End If  
  
  'process query
  Set ele = doc.getElementById("result"&cur)
  If Not (ele Is Nothing) Then       
    ele.innerHTML = QD.Item("img")
    ele.scrollIntoView(False)
  End If
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim mp3f : mp3f = QD.Item("sp"&cur)
  If Debug Then Call out("SongPath: "&mp3f)
  
  'check for special case ("01.mp3")
  Dim spec : spec = ""
  Dim str : str = UCase(Left(mp3f,InStrRev(mp3f,".")-1))
  str = Replace(Mid(str,InStrRev(str,"\")+1),"TRACK","")
  If IsNumeric(str) Then
    spec = str
  End If   
  
  'find cuesheet  
  Dim cuef : cuef = Left(mp3f,InStrRev(mp3f,"."))&"cue"
  If Not (fso.FileExists(cuef)) Then
    cuef = mp3f&".cue"
    If Not (fso.FileExists(cuef)) Then
      cuef = ""
      If Not (spec = "") Then
        str = Left(mp3f,InStrRev(mp3f,"\")) 
        If QD.Exists(str) Then
          cuef = QD.Item(str)
        Else
          Dim fil : Set fil = Nothing
          Dim fol : Set fol = fso.GetFolder(str).Files
          Dim j : j = 0 
          For Each fil In fol 
            If Right(fil.name,4) = ".cue" Then 
              j = j+1
              cuef = str&fil.name
            End If
          Next   
          If j = 1 Then
            QD.Item(str) = cuef
          Else
            cuef = ""
          End If
        End If
      End If
    End If
  End If
    
  'read cuesheet
  If cuef = "" Then          
    If Not (ele Is Nothing) Then
      ele.innerHTML = " - no cuesheet found!"
    End If      
    If Debug Then Call out("Cuesheet: not found")
  Else  
    If Debug Then Call out("Cuesheet: "&cuef)
    Dim cue : Set cue = fso.OpenTextFile(cuef,1,False)
    Dim boo : boo = cue.AtEndOfStream
    Dim flg : flg = True
    Dim art : art = ""
    Dim alb : alb = ""
    Dim ttl : ttl = ""
    Dim per : per = ""
    While Not (boo)
      str = Trim(cue.ReadLine)   
      boo = cue.AtEndOfStream
      Select Case Left(str,4)
        Case "PERF"
          If flg Then
            If art = "" Then
              art = Replace(Mid(str,11),Chr(34),"")
            End If
          Else
            If per = "" Then
              per = Replace(Mid(str,11),Chr(34),"")
            End If
          End If  
        Case "TITL"
          If flg Then
            If alb = "" Then
              alb = Replace(Mid(str,7),Chr(34),"")
            End If
          Else
            If ttl = "" Then 
              ttl = Replace(Mid(str,7),Chr(34),"")
            End If
          End If
        Case Else
          boo = True
      End Select
      If (boo) And (flg) Then
        If Left(str,6+Len(spec)) = "TRACK "&spec Then
          flg = False
        End If
        boo = cue.AtEndOfStream
      End If            
    WEnd
    Call cue.Close()
    If (art = "") And (alb = "") Then
      cuef = ""    
      If Not (ele Is Nothing) Then
        ele.innerHTML = " - no metadata found!"
      End If
    Else
      Dim dat : dat = ""
      If Not (alb = "") Then
        dat = ExtractYear(alb)
      End If
      
      'process results
      Dim WS : Set WS = SDB.Tools.WebSearch
      Dim i : i = 0
      For i = 0 To WS.NewTracks.Count-1
        Dim itm : Set itm = WS.NewTracks.Item(i)
        If itm.Path = mp3f Then
          If Not (ttl = "") Then
            If Debug Then Call out("Title="&ttl)
            itm.Title = ttl
          End If
          If Not (spec = "") Then
            If Debug Then Call out("TrackOrder="&spec)
            itm.TrackOrderStr = spec          
          End If                  
          If Not (alb = "") Then
            If Debug Then Call out("Album="&alb)
            itm.AlbumName = alb
          End If
          If Not (per = "") Then
            If Debug Then Call out("Artist="&per)
            itm.ArtistName = per
            If Not (art = "") Then          
              If Debug Then Call out("AlbumArtist="&art)
              itm.AlbumArtistName = art
            End If          
          Else
            If Not (art = "") Then
              If (itm.ArtistName = itm.AlbumArtistName) Or (itm.AlbumArtistName = "") Then
                If Debug Then Call out("AlbumArtist="&art)
                itm.AlbumArtistName = art
              End If
              If Debug Then Call out("Artist="&art)
              itm.ArtistName = art
            End If
          End If          
          If Not (dat = "") Then
            If Debug Then Call out("Year="&dat)
            itm.Year = dat
          End If
          WS.TrackChecked(i) = True
          Exit For
        End If
      Next
      Call WS.RefreshViews()
    End If
  End If
  
  'update display
  If Not (ele Is Nothing) Then   
    Dim div : Set div = ele.parentNode
    Dim par : Set par = div.parentNode
    par.removeChild(div)
    If cuef = "" Then
      par.appendChild(div)
    End If
  End If  
  
  'keep looping  
  If Not (SDB.Objects("CueTagger-WB") Is Nothing) Then
    QD.Item("cur") = cur
    If Not (cuef = "") Then
      QD.Item("tot") = tot+1
    End If
    Set Tmr = SDB.CreateTimer(50)
    Call Script.RegisterEvent(Tmr,"OnTimer","ContinueSearch") 
  End If
End Sub

Function ExtractYear(str)
  ExtractYear = ""
  Dim i : i = 0
  Dim l : l = Len(str)-3
  For i = 1 To l
    Dim s : s = Mid(str,i,4)    
    If IsNumeric(s) Then
      Dim y : y = Int(s)
      If (y > 1900) And (y < 2100) Then
        ExtractYear = s
        Exit Function
      End If
    End If
  Next 
End Function

Sub ShowResult(i)
  If Debug Then Call out("ShowResult("&i&")")
  Call SDB.Tools.WebSearch.ClearTracksData()
End Sub

Sub FinishSearch(Panel)
  If Debug Then Call out("FinishSearch(Panel)")
  Dim WB : Set WB = SDB.Objects("CueTagger-WB")
  If Not (WB Is Nothing) Then
    Call WB.Common.DestroyControl()
    Set WB = Nothing
  End If
  Set SDB.Objects("CueTagger-WB") = Nothing
  Set SDB.Objects("CueTagger-QD") = Nothing  
End Sub

Sub clear()
  Dim wsh : Set wsh = CreateObject("WScript.Shell")
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim loc : loc = wsh.ExpandEnvironmentStrings("%TEMP%")
  If Right(loc,1) = "\" Then
    loc = loc&"CueTagger.log"
  Else
    loc = loc&"\CueTagger.log"
  End If
  Dim logf : Set logf = fso.CreateTextFile(loc,True)
  Call logf.Close()
End Sub

Sub out(txt)
  Dim wsh : Set wsh = CreateObject("WScript.Shell")
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim loc : loc = wsh.ExpandEnvironmentStrings("%TEMP%")
  If Right(loc,1) = "\" Then
    loc = loc&"CueTagger.log"
  Else
    loc = loc&"\CueTagger.log"
  End If
  Dim logf : Set logf = fso.OpenTextFile(loc,8,True)
  Call logf.WriteLine(Time&Chr(9)&SDB.ToAscii(txt))
  Call logf.Close()
End Sub

Sub Install()
  Dim inip : inip = SDB.ScriptsPath&"Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("CueTagger","Filename") = "CueTagger.vbs"
    inif.StringValue("CueTagger","Procname") = "CueTagger"
    inif.StringValue("CueTagger","Order") = "30"
    inif.StringValue("CueTagger","DisplayName") = "Cue Tagger"
    inif.StringValue("CueTagger","Description") = "Tag tracks using their cuesheet"
    inif.StringValue("CueTagger","Language") = "VBScript"
    inif.StringValue("CueTagger","ScriptType") = "3"
    Call SDB.RefreshScriptItems()
  End If
'  Dim ini : Set ini = SDB.IniFile
'  Dim s : s = ini.StringValue("AlbumBrowser","RunningScriptName")
'  If Not (s = "CueTagger.vbs") Then
'    s = "CueTagger: Would you like to make this your default 'Auto-tag from Web' source?"
'    Dim i : i = SDB.MessageBox(s,mtConfirmation,Array(mbYes,mbNo))
'    If i = mrYes Then
'      ini.StringValue("AlbumBrowser","RunningScriptName") = "CueTagger.vbs"
'      Call ini.Flush() 
'    End If
'  End If  
End Sub

Top