Powered by (used to be )
As always there is an installation package available on my website. Let me know what you think!
Code: Select all
'
' MediaMonkey Script
'
' NAME: MusicIPTagger 2.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 28/07/2012
'
' INSTALL: Copy to Scripts\MIPT directory along with the images and components, then add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
'
' NOTE: This script needs "genpuid.exe", "mipcore.exe" and "libexpat.dll" to perform lookup
'
' Thanks to Aff for all his hard work fixing bugs with this script
'
' [MusicIPTagger]
' FileName=MIPT\MusicIPTagger.vbs
' ProcName=MusicIPTagger
' Order=30
' DisplayName=MusicIP Tagger
' Description=Tag tracks using MusicIP
' Language=VBScript
' ScriptType=3
'
' FIXES: Fixed getting short path with new API method
' Fixed webservice calls to use version 2
' Removed track number (not provided by version 2)
' Fixed year and original year not always updating
'
Option Explicit
Dim Debug : Debug = False
Dim UpTtl : UpTtl = True
Dim UpArt : UpArt = True
Dim UpYer : UpYer = True
Dim UpGnr : UpGnr = True
Dim UpAlb : UpAlb = True
Dim UpAAr : UpAAr = False
Dim UpOYr : UpOYr = False
Dim UpOAr : UpOAr = False
Dim UpOTt : UpOTt = False
Dim Field : Field = 0 '1-5=Custom# 6=Mood 7=Occasion 8=Quality 9=Tempo 10=Comment 11=Grouping
Dim Prior : Prior = False
Dim Archi : Archi = False
Sub StartSearch(Panel,SearchTerm,SearchArtist,SearchAlbum)
'default settings
Dim ini : Set ini = SDB.IniFile
If ini.StringValue("MusicIPTagger","Debug") = "" Then
ini.BoolValue("MusicIPTagger","Debug") = Debug
Else
Debug = ini.BoolValue("MusicIPTagger","Debug")
End If
If ini.StringValue("MusicIPTagger","UpTtl") = "" Then
ini.BoolValue("MusicIPTagger","UpTtl") = UpTtl
End If
If ini.StringValue("MusicIPTagger","UpArt") = "" Then
ini.BoolValue("MusicIPTagger","UpArt") = UpArt
End If
If ini.StringValue("MusicIPTagger","UpYer") = "" Then
ini.BoolValue("MusicIPTagger","UpYer") = UpYer
End If
If ini.StringValue("MusicIPTagger","UpGnr") = "" Then
ini.BoolValue("MusicIPTagger","UpGnr") = UpGnr
End If
If ini.StringValue("MusicIPTagger","UpAlb") = "" Then
ini.BoolValue("MusicIPTagger","UpAlb") = UpAlb
End If
If ini.StringValue("MusicIPTagger","UpAAr") = "" Then
ini.BoolValue("MusicIPTagger","UpAAr") = UpAAr
End If
If ini.StringValue("MusicIPTagger","UpOYr") = "" Then
ini.BoolValue("MusicIPTagger","UpOYr") = UpOYr
End If
If ini.StringValue("MusicIPTagger","UpOAr") = "" Then
ini.BoolValue("MusicIPTagger","UpOAr") = UpOAr
End If
If ini.StringValue("MusicIPTagger","UpOTt") = "" Then
ini.BoolValue("MusicIPTagger","UpOTt") = UpOTt
End If
If ini.StringValue("MusicIPTagger","Field") = "" Then
ini.IntValue("MusicIPTagger","Field") = Field
End If
If ini.StringValue("MusicIPTagger","Prior") = "" Then
ini.BoolValue("MusicIPTagger","Prior") = Prior
End If
If ini.StringValue("MusicIPTagger","Archi") = "" Then
ini.BoolValue("MusicIPTagger","Archi") = Archi
End If
'initialise
If Debug Then
Call clear()
Call out("StartSearch(Panel,"""&SearchTerm&""","""&SearchArtist&""","""&SearchAlbum&""")")
End If
Dim list : Set list = SDB.SelectedSongList
'check application
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FileExists(SDB.ScriptsPath&"MIPT\genpuid.exe")) Then
If Debug Then Call out("File 'genpuid.exe' missing.")
Call SDB.MessageBox("MusicIP Tagger: File 'genpuid.exe' is missing - search failed.",mtError,Array(mbOk))
Exit Sub
End If
If Not (fso.FileExists(SDB.ScriptsPath&"MIPT\mipcore.exe")) Then
If Debug Then Call out("File 'mipcore.exe' missing.")
Call SDB.MessageBox("MusicIP Tagger: File 'micpcore.exe' is missing - search failed.",mtError,Array(mbOk))
Exit Sub
End If
If Not (fso.FileExists(SDB.ScriptsPath&"MIPT\libexpat.dll")) Then
If Debug Then Call out("File 'libexpat.dll' missing.")
Call SDB.MessageBox("MusicIP Tagger: File 'libexpat.dll' is missing - search will be limited.",mtInformation,Array(mbOk))
End If
Dim loc : loc = SDB.TemporaryFolder
If Right(loc,1) = "\" Then
loc = loc&"MIPT.xml"
Else
loc = loc&"\MIPT.xml"
End If
Dim xml : Set xml = fso.CreateTextFile(loc,True)
Call xml.Close()
'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") = " <img src=""file://"&Replace(SDB.ScriptsPath,"\","/")&"MIPT/mipt.gif"" border=""0"" alt=""MusicIP""/>"
QD.Item("psd") = ""
'build display
Dim i : i = 0
Dim src : src = Replace(SDB.ScriptsPath,"\","/")&"MIPT/mipt.jpg"
Dim html : html = "<div id=""header"" style=""float:left""><img src=""file://"&src&""" border=""0"" alt=""MusicIP""/></div>"
html = html&"<div id=""progress"" style=""float:left;font-family:'arial black';""> Progress: <span id=""percent""></span>"
html = html&"<br /> Success: <span id=""success""></span><br /> Failure: <span id=""failure""></span></div>"
html = html&"<div id=""killexes"" style=""float:right;""><input type=""button"" value=""Kill"" /></div>"
html = html&"<div id=""settings"" style=""float:right;""><input type=""button"" value=""Settings"" /> </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)
'register event
Dim doc : Set doc = WB.Interf.Document
Dim btn : Set btn = doc.getElementById("settings")
Call Script.RegisterEvent(btn,"onclick","InitSettings")
Set btn = doc.getElementById("killexes")
Call Script.RegisterEvent(btn,"onclick","InitKillEXEs")
'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("MIPT-WB") = WB
Set SDB.Objects("MIPT-QD") = QD
Dim Tmr : Set Tmr = SDB.CreateTimer(50)
Call Script.RegisterEvent(Tmr,"OnTimer","ContinueSearch")
End Sub
Sub ContinueSearch(Tmr)
Debug = SDB.IniFile.BoolValue("MusicIPTagger","Debug")
If Debug Then Call out("ContinueSearch(Tmr)")
Call Script.UnregisterEvents(Tmr)
'get document
Dim WB : Set WB = SDB.Objects("MIPT-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("MIPT-QD")
If QD Is Nothing Then
Call out("QD Is Nothing!")
Exit Sub
End If
If QD.Item("psd") = "KILL" Then
Call out("Killed")
Exit Sub
End If
If QD.Item("psd") = "YES" Then
Call out("Paused...")
Set Tmr = SDB.CreateTimer(1000)
Call Script.RegisterEvent(Tmr,"OnTimer","ContinueSearch")
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 boo : boo = True
Dim puid : puid = ""
If SDB.IniFile.BoolValue("MusicIPTagger","Prior") Then
Field = SDB.IniFile.IntValue("MusicIPTagger","Field")
If Field > 0 Then
Dim iter : Set iter = SDB.Database.QuerySongs("AND Songs.ID="&QD.Item("id"&cur))
If Not (iter.EOF) Then
Select Case Field
Case 1
puid = iter.Item.Custom1
Case 2
puid = iter.Item.Custom2
Case 3
puid = iter.Item.Custom3
Case 4
puid = iter.Item.Custom4
Case 5
puid = iter.Item.Custom5
Case 6
puid = iter.Item.Mood
Case 7
puid = iter.Item.Occasion
Case 8
puid = iter.Item.Quality
Case 9
puid = iter.Item.Tempo
Case 10
puid = iter.Item.Comment
Case 11
puid = iter.Item.Grouping
End Select
End If
Set iter = Nothing
End If
End If
If puid = "" Then
boo = False
Call CreatePUID(ele,QD.Item("sp"&cur),puid)
Else
If Debug Then Call out("PUID="&puid)
End If
If Not (ele Is Nothing) Then
If Not (puid = "") Then
UpAlb = SDB.IniFile.BoolValue("MusicIPTagger","UpAlb")
If UpAlb Then
ele.innerHTML = QD.Item("img")&QD.Item("img")
puid = GetExtra(ele,QD.Item("sp"&cur),puid,boo)
If puid = "" Then
ele.innerHTML = " - no album found!"
End If
End If
End If
Dim div : Set div = ele.parentNode
Dim par : Set par = div.parentNode
par.removeChild(div)
If puid = "" Then
par.appendChild(div)
End If
End If
'keep looping
If Not (SDB.Objects("MIPT-WB") Is Nothing) Then
QD.Item("cur") = cur
If Not (puid = "") Then
QD.Item("tot") = tot+1
End If
Set Tmr = SDB.CreateTimer(50)
Call Script.RegisterEvent(Tmr,"OnTimer","ContinueSearch")
End If
End Sub
Function GetExtra(ele,mp3,puid,boo)
GetExtra = ""
Dim ini : Set ini = SDB.IniFile
Debug = ini.BoolValue("MusicIPTagger","Debug")
If Debug Then Call out("GetExtra(ele,"""&mp3&""","""&puid&""","&boo&")")
'call musicbrainz
Dim xml : Set xml = CreateObject("Microsoft.XMLDOM")
xml.async = True
Dim url : url = "http://musicbrainz.org/ws/2/puid/"&puid&"?inc=releases+artists"
If Debug Then Call out("URL="&url)
Call xml.Load(url)
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 < 4 Then
If Debug Then Call out("XML timeout at 30s")
Exit Function
End If
On Error Resume Next
Dim trk : Set trk = xml.getElementsByTagName("recording").Item(0)
If (Err.Number <> 0) Or (trk Is Nothing) Then
If Debug Then Call out("XML file is empty")
Err.Clear
Exit Function
End If
On Error Goto 0
'load settings
UpAlb = ini.BoolValue("MusicIPTagger","UpAlb")
If boo Then
UpTtl = ini.BoolValue("MusicIPTagger","UpTtl")
UpOTt = ini.BoolValue("MusicIPTagger","UpOTt")
UpArt = ini.BoolValue("MusicIPTagger","UpArt")
UpAAr = ini.BoolValue("MusicIPTagger","UpAAr")
UpOAr = ini.BoolValue("MusicIPTagger","UpOAr")
UpYer = ini.BoolValue("MusicIPTagger","UpYer")
UpOYr = ini.BoolValue("MusicIPTagger","UpOYr")
End If
'load results
Dim AD : Set AD = CreateObject("Scripting.Dictionary")
Dim alb,str,off,num,nam,art,ttl,tid,rel
For Each alb In xml.getElementsByTagName("release")
On Error Resume Next
str = GetText(alb.getElementsByTagName("title").Item(0))
rel = GetText(alb.getElementsByTagName("date").Item(0))
On Error Goto 0
AD.Item(str) = Left(rel,4)
Next
If boo Then
ttl = ""
art = ""
On Error Resume Next
Set trk = xml.getElementsByTagName("recording").Item(0)
ttl = GetText(trk.getElementsByTagName("title").Item(0))
Set alb = xml.getElementsByTagName("artist").Item(0)
art = GetText(alb.getElementsByTagName("name").Item(0))
On Error Goto 0
Else
If AD.Count = 0 Then
If Debug Then Call out("No albums found")
Exit Function
End If
End If
'process results
Dim WS : Set WS = SDB.Tools.WebSearch
For cnt = 0 To WS.NewTracks.Count-1
Dim itm : Set itm = WS.NewTracks.Item(cnt)
If itm.Path = mp3 Then
If boo Then
If Not (ttl = "") Then
If UpTtl Then
If Debug Then Call out("Title="&ttl)
itm.Title = ttl
End If
If UpOTt Then
If Debug Then Call out("OriginalTitle="&ttl)
itm.OriginalTitle = ttl
End If
End If
If Not (art = "") Then
art = Replace(art," / ","; ")
If UpArt Then
If Debug Then Call out("Artist="&art)
itm.ArtistName = art
End If
If UpAAr Then
If (itm.ArtistName = itm.AlbumArtistName Or itm.AlbumArtistName = "") Then
If Debug Then Call out("AlbumArtist="&art)
itm.AlbumArtistName = art
End If
End If
If UpOAr Then
If Debug Then Call out("OriginalArtist="&art)
itm.OriginalArtist = art
End If
End If
End If
If AD.Count > 0 Then
Dim arr : arr = AD.Keys
str = ""
nam = itm.AlbumName
If AD.Count = 1 Or nam = "" Then
str = arr(0) 'only one match or nothing to match with
Else
If Not (nam = "") And (AD.Exists(nam)) Then
str = nam 'current album matches
Else
nam = StripName(nam)
For num = 0 To UBound(arr)
If MatchName(nam,arr(num)) Then
str = arr(num) 'album name matches
Exit For
End If
Next
End If
If str = "" Then
str = arr(0) 'no matches so use first result
End If
End If
If UpAlb Then
If Debug Then Call out("Album="&str)
itm.AlbumName = str
End If
rel = AD.Item(str)
If Not (rel = "") Then
If UpYer Then
If Debug Then Call out("Year="&rel)
itm.Year = rel
End If
If UpOYr Then
If Debug Then Call out("OriginalYear="&rel)
itm.OriginalYear = rel
End If
End If
End If
WS.TrackChecked(cnt) = True
GetExtra = puid
Exit For
End If
Next
Call WS.RefreshViews()
End Function
Function StripName(nam)
Debug = SDB.IniFile.BoolValue("MusicIPTagger","Debug")
If Debug Then Call out("StripName("""&nam&""")")
'check inputs
StripName = ""
If nam = "" Then
Exit Function
End If
'strip string
Dim s : s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ÅÄÂÃÁÀÆËÊÉÈÏÎÍÌÖÔÕÓÒØÜÛÚÙÝÇÐÑß"
Dim t : t = UCase(SDB.ToAscii(nam))
Dim i : i = 0
For i = 1 To Len(t)
Dim c : c = Mid(t,i,1)
If InStr(s,c) > 0 Then
StripName = StripName&c
End If
Next
End Function
Function MatchName(abc,def)
Dim ghi : ghi = StripName(def)
Debug = SDB.IniFile.BoolValue("MusicIPTagger","Debug")
If Debug Then Call out("MatchName("""&abc&""","""&ghi&""")")
'check inputs
MatchName = False
If abc = "" Then
Exit Function
End If
'compare strings
Dim n : n = Len(ghi)
Dim o : o = Len(abc)
If n = o Then
If ghi = abc Then
MatchName = True 'no trim match
End If
Else
If n > o Then
If Left(ghi,o) = abc Then
MatchName = True 'trim new match
End If
Else
If Left(abc,n) = ghi Then
MatchName = True 'trim old match
End If
End If
End If
End Function
Sub CreatePUID(ele,mp3,puid)
Debug = SDB.IniFile.BoolValue("MusicIPTagger","Debug")
If Debug Then Call out("CreatePUID(ele,"""&mp3&""","""&puid&""")")
Archi = SDB.IniFile.BoolValue("MusicIPTagger","Archi")
'check existing
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FileExists(mp3)) Then
If Debug Then Call out("File '"&mp3&"' does not exist")
Exit Sub
End If
'call application
Dim loc : loc = SDB.ScriptsPath&"MIPT\genpuid.exe"
Dim exe : exe = GetFile(fso,loc)
loc = SDB.TemporaryFolder
If Right(loc,1) = "\" Then
loc = loc&"MIPT.xml"
Else
loc = loc&"\MIPT.xml"
End If
Dim dat : dat = GetFile(fso,loc)
If fso.FileExists(dat) Then
Call fso.DeleteFile(dat)
End If
loc = GetFile(fso,mp3)
Dim wsh : Set wsh = CreateObject("WScript.Shell")
Dim cmd : cmd = ""
If InStr(exe," ") > 0 Then
cmd = "%comspec% /c """&exe&""" f25c7a6acad172541066f475175465a7"
Else
cmd = "%comspec% /c "&exe&" f25c7a6acad172541066f475175465a7"
End If
If Archi Then
Dim ext : ext = UCase(Right(loc,4))
If (ext = ".M4A") Or (ext = ".M4B") Then
'don't archive
Else
cmd = cmd&" -archive"
End If
End If
If InStr(loc," ") > 0 Then
cmd = cmd&" -rmd=2 """&loc&""" >"&dat
Else
cmd = cmd&" -rmd=2 "&loc&" >"&dat
End If
If Debug Then Call out(">"&cmd)
Call wsh.Run(cmd,0,True)
If SDB.Objects("MIPT-WB") Is Nothing Then
If Debug Then Call out("MIPT-WB is nothing")
Exit Sub
End If
'check results
If Not (fso.FileExists(dat)) Then
If Debug Then Call out("Application error")
If Not (ele Is Nothing) Then
ele.innerHTML = " - application error!"
End If
Exit Sub
End If
Dim xml : Set xml = CreateObject("Microsoft.XMLDOM")
If xml Is Nothing Then
If Debug Then Call out("XML is Nothing")
If Not (ele Is Nothing) Then
ele.innerHTML = " - xml object error!"
End If
Exit Sub
End If
xml.async = True
Dim fil : Set fil = fso.OpenTextFile(dat,1,True)
If fil.AtEndOfStream Then
If Debug Then Call out("File is empty")
If Not (ele Is Nothing) Then
ele.innerHTML = " - no results!"
End If
Exit Sub
End If
Dim s : s = Replace(fil.ReadAll,"mip:","")
If s = "MusicDNS servers cannot be reached right now." Then
If Debug Then Call out("MusicDNS servers cannot be reached right now")
If Not (ele Is Nothing) Then
ele.innerHTML = " - servers unavailable!"
End If
Exit Sub
End If
Dim i : i = InStr(s,"file=")-1
If i > 0 Then
Dim j : j = InStr(Mid(s,i+7),"""")+i+8
s = Left(s,i)&Mid(s,j)
End If
fil.Close()
If Not (Left(s,1) = "<") Then
If Debug Then Call out("File does not contain valid XML")
If Not (ele Is Nothing) Then
ele.innerHTML = " - no results!"
End If
Exit Sub
End If
'load results
Set fil = fso.OpenTextFile(dat,2,True)
fil.Write(s)
fil.Close()
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 < 4 Then
If Debug Then Call out("XML timeout at 30s")
If Not (ele Is Nothing) Then
ele.innerHTML = " - xml timeout!"
End If
Exit Sub
End If
If xml.parseError.errorCode < 0 Then
If Debug Then Call out(xml.parseError.reason&" (Line "&xml.parseError.line&")")
If Not (ele Is Nothing) Then
ele.innerHTML = " - "&xml.parseError.reason&"!"
End If
Exit Sub
End If
'load settings
Dim ini : Set ini = SDB.IniFile
UpTtl = ini.BoolValue("MusicIPTagger","UpTtl")
UpArt = ini.BoolValue("MusicIPTagger","UpArt")
UpYer = ini.BoolValue("MusicIPTagger","UpYer")
UpGnr = ini.BoolValue("MusicIPTagger","UpGnr")
UpAAr = ini.BoolValue("MusicIPTagger","UpAAr")
UpOYr = ini.BoolValue("MusicIPTagger","UpOYr")
UpOAr = ini.BoolValue("MusicIPTagger","UpOAr")
UpOTt = ini.BoolValue("MusicIPTagger","UpOTt")
Field = ini.IntValue("MusicIPTagger","Field")
'get web search
Dim WS : Set WS = SDB.Tools.WebSearch
If WS.NewTracks Is Nothing Then
If Debug Then Call out("NewTracks Is Nothing")
If Not (ele Is Nothing) Then
ele.innerHTML = " - no new tracks!"
End If
Exit Sub
End If
'process results
Dim trk,str,ttl,art,rel,gen,aan
For Each trk In xml.getElementsByTagName("track")
str = trk.getAttribute("status")
If Not (str = "") Then
If Debug Then Call out("Status="&str)
If Not (ele Is Nothing) Then
ele.innerHTML = " - "&str&"!"
End If
Exit Sub
End If
puid = trk.getAttribute("puid")
If Not (puid = "") Then
If Debug Then Call out("PUID="&puid)
End If
On Error Resume Next
ttl = GetText(trk.getElementsByTagName("title").Item(0))
art = GetText(trk.getElementsByTagName("artist").Item(0).ChildNodes.Item(0))
rel = GetText(trk.getElementsByTagName("first-release-date").Item(0))
gen = GetText(trk.getElementsByTagName("genre-list").Item(0).ChildNodes.Item(0).ChildNodes.Item(0))
On Error Goto 0
For cnt = 0 To WS.NewTracks.Count-1
Dim itm : Set itm = WS.NewTracks.Item(cnt)
If itm.Path = mp3 Then
If Not (ttl = "") Then
If UpTtl Then
If Debug Then Call out("Title="&ttl)
itm.Title = ttl
End If
If UpOTt Then
If Debug Then Call out("OriginalTitle="&ttl)
itm.OriginalTitle = ttl
End If
End If
If Not (art = "") Then
If UpArt Then
If Debug Then Call out("Artist="&art)
itm.ArtistName = art
End If
If UpAAr Then
If (itm.ArtistName = itm.AlbumArtistName Or itm.AlbumArtistName = "") Then
If Debug Then Call out("AlbumArtist="&art)
itm.AlbumArtistName = art
End If
End If
If UpOAr Then
If Debug Then Call out("OriginalArtist="&art)
itm.OriginalArtist = art
End If
End If
If Not (rel = "") Then
If UpYer Then
If Debug Then Call out("Year="&rel)
itm.Year = rel
End If
If UpOYr Then
If Debug Then Call out("OriginalYear="&rel)
itm.OriginalYear = rel
End If
End If
If Not (gen = "") Then
If UpGnr Then
gen = Replace(gen," / ","; ")
If Debug Then Call out("Genre="&gen)
itm.Genre = gen
End If
End If
Dim sql : sql = ""
If Not (puid = "") And (Field > 0) Then
Select Case Field
Case 1
If Debug Then Call out("Custom1="&puid)
itm.Custom1 = puid
sql = "Custom1"
Case 2
If Debug Then Call out("Custom2="&puid)
itm.Custom2 = puid
sql = "Custom2"
Case 3
If Debug Then Call out("Custom3="&puid)
itm.Custom3 = puid
sql = "Custom3"
Case 4
If Debug Then Call out("Custom4="&puid)
itm.Custom4 = puid
sql = "Custom4"
Case 5
If Debug Then Call out("Custom5="&puid)
itm.Custom5 = puid
sql = "Custom5"
Case 6
If Debug Then Call out("Mood="&puid)
itm.Mood = puid
sql = "Mood"
Case 7
If Debug Then Call out("Occasion="&puid)
itm.Occasion = puid
sql = "Occasion"
Case 8
If Debug Then Call out("Quality="&puid)
itm.Quality = puid
sql = "Quality"
Case 9
If Debug Then Call out("Tempo="&puid)
itm.Tempo = puid
sql = "Tempo"
Case 10
If Debug Then Call out("Comment="&puid)
itm.Comment = puid
sql = "Comment"
Case 11
If Debug Then Call out("Grouping="&puid)
itm.Grouping = puid
sql = "GroupDesc"
End Select
End If
If (Debug) And (sql <> "") Then
sql = "SELECT COUNT(*) FROM Songs WHERE "&sql&"='"&puid&"' AND Id NOT IN (0,"&itm.ID&")"
Call out("SQL="&sql)
Dim itr : Set itr = SDB.Database.OpenSQL(sql)
If Not (itr.EOF) Then
If itr.ValueByIndex(0) > 0 Then
Call out("Duplicate PUID warning: "&itr.ValueByIndex(0))
End If
End If
Set itr = Nothing
End If
WS.TrackChecked(cnt) = True
Exit For
End If
Next
Call WS.RefreshViews()
Next
End Sub
Function GetText(ele)
If ele Is Nothing Then
GetText = ""
Else
GetText = ele.Text
End If
End Function
Sub ShowResult(i)
Debug = SDB.IniFile.BoolValue("MusicIPTagger","Debug")
If Debug Then Call out("ShowResult("&i&")")
Call SDB.Tools.WebSearch.ClearTracksData()
End Sub
Sub FinishSearch(Panel)
Debug = SDB.IniFile.BoolValue("MusicIPTagger","Debug")
If Debug Then Call out("FinishSearch(Panel)")
Dim WB : Set WB = SDB.Objects("MIPT-WB")
If Not (WB Is Nothing) Then
Call WB.Common.DestroyControl()
Set WB = Nothing
End If
Set SDB.Objects("MIPT-WB") = Nothing
Set SDB.Objects("MIPT-QD") = Nothing
End Sub
Sub clear()
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim loc : loc = SDB.TemporaryFolder
If Right(loc,1) = "\" Then
loc = loc&"MIPT.log"
Else
loc = loc&"\MIPT.log"
End If
Dim logf : Set logf = fso.CreateTextFile(loc,True)
Call logf.Close()
End Sub
Sub out(txt)
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim loc : loc = SDB.TemporaryFolder
If Right(loc,1) = "\" Then
loc = loc&"MIPT.log"
Else
loc = loc&"\MIPT.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("MusicIPTagger","Filename") = "MIPT\MusicIPTagger.vbs"
inif.StringValue("MusicIPTagger","Procname") = "MusicIPTagger"
inif.StringValue("MusicIPTagger","Order") = "30"
inif.StringValue("MusicIPTagger","DisplayName") = "MusicIP Tagger"
inif.StringValue("MusicIPTagger","Description") = "Tag tracks using MusicIP"
inif.StringValue("MusicIPTagger","Language") = "VBScript"
inif.StringValue("MusicIPTagger","ScriptType") = "3"
Call SDB.RefreshScriptItems()
End If
' Dim ini : Set ini = SDB.IniFile
' Dim s : s = ini.StringValue("AlbumBrowser","RunningScriptName")
' If Not (s = "MIPT\MusicIPTagger.vbs") Then
' s = "MusicIP Tagger: 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") = "MIPT\MusicIPTagger.vbs"
' Call ini.Flush()
' End If
' End If
End Sub
Sub InitSettings()
Dim QD : Set QD = SDB.Objects("MIPT-QD")
If QD Is Nothing Then
Call out("QD Is Nothing!")
Exit Sub
End If
QD.Item("psd") = "YES"
Dim obj,prc,col
Set obj = GetObject("WinMgmts:")
Set col = obj.ExecQuery("SELECT * FROM Win32_Process WHERE Name='MIPCORE.exe'")
For Each prc in col
Call prc.Terminate()
Next
Set col = obj.ExecQuery("SELECT * FROM Win32_Process WHERE Name='genpuid.exe'")
For Each prc in col
Call prc.Terminate()
Next
Dim ini : Set ini = SDB.IniFile
Dim Form : Set Form = SDB.UI.NewForm
Form.Common.SetRect 100, 100, 360, 360
Form.BorderStyle = 3 ' Non-Resizable
Form.FormPosition = 4 ' Screen Center
Form.SavePositionName = "MusicIPTaggerPos"
Form.Caption = "MusicIP Tagger"
Dim Label : Set Label = SDB.UI.NewLabel(Form)
Label.Caption = "Store PUID in:"
Label.Common.Left = 10
Label.Common.Top = 15
Dim EdtField : Set EdtField = SDB.UI.NewDropdown(Form)
EdtField.Common.Left = 92
EdtField.Common.Top = Label.Common.Top -4
EdtField.Common.Width = 200
EdtField.AddItem("(None)")
EdtField.AddItem("Custom1 ("&ini.StringValue("CustomFields","Fld1Name")&")")
EdtField.AddItem("Custom2 ("&ini.StringValue("CustomFields","Fld2Name")&")")
EdtField.AddItem("Custom3 ("&ini.StringValue("CustomFields","Fld3Name")&")")
EdtField.AddItem("Custom4 ("&ini.StringValue("CustomFields","Fld4Name")&")")
EdtField.AddItem("Custom5 ("&ini.StringValue("CustomFields","Fld5Name")&")")
EdtField.AddItem("Mood")
EdtField.AddItem("Occasion")
EdtField.AddItem("Quality")
EdtField.AddItem("Tempo")
EdtField.AddItem("Comment")
EdtField.AddItem("Grouping")
EdtField.ItemIndex = ini.IntValue("MusicIPTagger","Field")
EdtField.Style = 2
Dim EdtUpTtl : Set EdtUpTtl = SDB.UI.NewCheckbox(Form)
EdtUpTtl.Common.Left = 10
EdtUpTtl.Common.Top = Label.Common.Top +25
EdtUpTtl.Common.Width = 165
EdtUpTtl.Caption = "Update track title?"
EdtUpTtl.Checked = ini.BoolValue("MusicIPTagger","UpTtl")
Dim EdtUpArt : Set EdtUpArt = SDB.UI.NewCheckbox(Form)
EdtUpArt.Common.Left = 10
EdtUpArt.Common.Top = EdtUpTtl.Common.Top +25
EdtUpArt.Common.Width = 165
EdtUpArt.Caption = "Update track artist?"
EdtUpArt.Checked = ini.BoolValue("MusicIPTagger","UpArt")
Dim EdtUpYer : Set EdtUpYer = SDB.UI.NewCheckbox(Form)
EdtUpYer.Common.Left = 10
EdtUpYer.Common.Top = EdtUpArt.Common.Top +25
EdtUpYer.Common.Width = 165
EdtUpYer.Caption = "Update track year?"
EdtUpYer.Checked = ini.BoolValue("MusicIPTagger","UpYer")
Dim EdtUpGnr : Set EdtUpGnr = SDB.UI.NewCheckbox(Form)
EdtUpGnr.Common.Left = 10
EdtUpGnr.Common.Top = EdtUpYer.Common.Top +25
EdtUpGnr.Common.Width = 165
EdtUpGnr.Caption = "Update track genre?"
EdtUpGnr.Checked = ini.BoolValue("MusicIPTagger","UpGnr")
Dim EdtUpAlb : Set EdtUpAlb = SDB.UI.NewCheckbox(Form)
EdtUpAlb.Common.Left = 10
EdtUpAlb.Common.Top = EdtUpGnr.Common.Top +25
EdtUpAlb.Common.Width = 165
EdtUpAlb.Caption = "Update album name?"
EdtUpAlb.Checked = ini.BoolValue("MusicIPTagger","UpAlb")
Dim EdtUpAAr : Set EdtUpAAr = SDB.UI.NewCheckbox(Form)
EdtUpAAr.Common.Left = 10
EdtUpAAr.Common.Top = EdtUpAlb.Common.Top +25
EdtUpAAr.Common.Width = 165
EdtUpAAr.Caption = "Update album artist?"
EdtUpAAr.Checked = ini.BoolValue("MusicIPTagger","UpAAr")
Dim EdtUpOAr : Set EdtUpOAr = SDB.UI.NewCheckbox(Form)
EdtUpOAr.Common.Left = 10
EdtUpOAr.Common.Top = EdtUpAAr.Common.Top +25
EdtUpOAr.Common.Width = 165
EdtUpOAr.Caption = "Update original artist?"
EdtUpOAr.Checked = ini.BoolValue("MusicIPTagger","UpOAr")
Dim EdtUpOYr : Set EdtUpOYr = SDB.UI.NewCheckbox(Form)
EdtUpOYr.Common.Left = 10
EdtUpOYr.Common.Top = EdtUpOAr.Common.Top +25
EdtUpOYr.Common.Width = 165
EdtUpOYr.Caption = "Update original year?"
EdtUpOYr.Checked = ini.BoolValue("MusicIPTagger","UpOYr")
Dim EdtUpOTt : Set EdtUpOTt = SDB.UI.NewCheckbox(Form)
EdtUpOTt.Common.Left = 10
EdtUpOTt.Common.Top = EdtUpOYr.Common.Top +25
EdtUpOTt.Common.Width = 165
EdtUpOTt.Caption = "Update original title?"
EdtUpOTt.Checked = ini.BoolValue("MusicIPTagger","UpOTt")
Dim EdtDebug : Set EdtDebug = SDB.UI.NewCheckbox(Form)
EdtDebug.Common.Left = 180
EdtDebug.Common.Top = EdtUpTtl.Common.Top
EdtDebug.Common.Width = 165
EdtDebug.Caption = "Create debug logfile?"
EdtDebug.Checked = ini.BoolValue("MusicIPTagger","Debug")
Dim EdtPrior : Set EdtPrior = SDB.UI.NewCheckbox(Form)
EdtPrior.Common.Left = 180
EdtPrior.Common.Top = EdtUpArt.Common.Top
EdtPrior.Common.Width = 165
EdtPrior.Caption = "Use existing PUID value?"
EdtPrior.Checked = ini.BoolValue("MusicIPTagger","Prior")
Dim EdtArchi : Set EdtArchi = SDB.UI.NewCheckbox(Form)
EdtArchi.Common.Left = 180
EdtArchi.Common.Top = EdtUpYer.Common.Top
EdtArchi.Common.Width = 165
EdtArchi.Caption = "Archive file analysis?"
EdtArchi.Checked = ini.BoolValue("MusicIPTagger","Archi")
Dim BtnCancel : Set BtnCancel = SDB.UI.NewButton(Form)
BtnCancel.Caption = "&Cancel"
BtnCancel.Cancel = True
BtnCancel.ModalResult = 2
BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width -20
BtnCancel.Common.Top = EdtUpOTt.Common.Top +25
Dim BtnOk : Set BtnOk = SDB.UI.NewButton(Form)
BtnOk.Caption = "&Ok"
BtnOk.Default = True
BtnOk.ModalResult = 1
BtnOk.Common.Left = BtnCancel.Common.Left - BtnOk.Common.Width -10
BtnOk.Common.Top = BtnCancel.Common.Top
'show confirmation screen
If Form.ShowModal = 1 Then
ini.IntValue("MusicIPTagger","Field") = EdtField.ItemIndex
ini.BoolValue("MusicIPTagger","UpTtl") = EdtUpTtl.Checked
ini.BoolValue("MusicIPTagger","UpArt") = EdtUpArt.Checked
ini.BoolValue("MusicIPTagger","UpYer") = EdtUpYer.Checked
ini.BoolValue("MusicIPTagger","UpGnr") = EdtUpGnr.Checked
ini.BoolValue("MusicIPTagger","UpAlb") = EdtUpAlb.Checked
ini.BoolValue("MusicIPTagger","UpAAr") = EdtUpAAr.Checked
ini.BoolValue("MusicIPTagger","UpOYr") = EdtUpOYr.Checked
ini.BoolValue("MusicIPTagger","UpOAr") = EdtUpOAr.Checked
ini.BoolValue("MusicIPTagger","UpOTt") = EdtUpOTt.Checked
ini.BoolValue("MusicIPTagger","Debug") = EdtDebug.Checked
ini.BoolValue("MusicIPTagger","Prior") = EdtPrior.Checked
ini.BoolValue("MusicIPTagger","Archi") = EdtArchi.Checked
End If
QD.Item("psd") = ""
End Sub
Sub InitKillEXEs()
Dim QD : Set QD = SDB.Objects("MIPT-QD")
If QD Is Nothing Then
Call out("QD Is Nothing!")
Exit Sub
End If
QD.Item("psd") = "KILL"
Call Script.UnRegisterAllEvents()
Dim mip : mip = False
Dim gen : gen = False
Dim prc : Set prc = Nothing
Dim obj : Set obj = GetObject("WinMgmts:")
Dim col : Set col = obj.ExecQuery("SELECT * FROM Win32_Process WHERE Name='MIPCORE.exe'")
For Each prc in col
Call prc.Terminate()
mip = True
Next
Set col = obj.ExecQuery("SELECT * FROM Win32_Process WHERE Name='genpuid.exe'")
For Each prc in col
Call prc.Terminate()
gen = True
Next
Dim str : str = Chr(13)&Chr(13)&"MIPCORE.exe - "&mip&Chr(13)&"genpuid.exe - "&gen
Call SDB.MessageBox("MusicIP Tagger: processes killed..."&str,mtInformation,Array(mbOk))
End Sub
Function GetFile(fso,loc)
If SDB.VersionHi > 3 Then
GetFile = SDB.Tools.FileSystem.GetShortPath(loc)
Else
Dim fil : Set fil = fso.GetFile(loc)
If fil Is Nothing Then
If Debug Then Call out("File '"&loc&"' cannot be shortened")
GetFile = loc
Else
GetFile = fil.ShortPath
End If
End If
End Function