Posted: Fri May 23, 2008 7:23 pm
I downloaded and installed the latest version of this script into MM3, but it isn't working: It runs nearly to the end of my files (42283 of 42341), then freezes up -- and also freezes MM. Any ideas?
The Music Manager for Serious Collectors
http://www.mediamonkey.com/forum/
Code: Select all
'
' MediaMonkey Script
'
' NAME: CombineAlbums 3.0 Reloaded
'
' AUTHOR: trixmoto (http://trixmoto.net)
' AUTHOR: andig (http://cpuidle.de/blog/)
' DATE : 24/01/2008
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
' Set up text for your albums (see below: *)
'
' [CombineAlbums2]
' FileName=CombineAlbums2.vbs
' ProcName=CombineAlbums2
' Order=18
' DisplayName=Combine Albums 2
' Description=Change album naming conventions
' Language=VBScript
' ScriptType=0
'
Option Explicit
'* The text which wants to be removed from the album name
Dim cd1 : cd1 = " (CD 1)"
Dim cd2 : cd2 = " (CD 2)"
Dim cd3 : cd3 = " (CD 3)"
Sub CombineAlbums2
Dim list : Set list = SDB.CurrentSongList
If list.Count = 0 Then
Call SDB.MessageBox("CombineAlbums: No tracks selected to process.",mtError,Array(mbOk))
Exit Sub
End If
Dim prog : Set prog = SDB.Progress
prog.Text = "CombineAlbums: Initialising script..."
prog.MaxValue = list.Count
Dim c : c = 0
Dim i : i = 0
Dim mode : mode = 0
If SDB.VersionHi > 2 Then
mode = SDB.IniFile.IntValue("CombineAlbums","Mode")+1
Dim dic : Set dic = CreateObject("Scripting.Dictionary")
dic.Item("1. AlbumName"&cd1&" -> AlbumName and Track=1##") = ""
dic.Item("2. AlbumName"&cd1&" -> AlbumName and Disc=1") = ""
dic.Item("3. AlbumName"&cd1&" -> AlbumName and Disc=1 and Track=1##") = ""
dic.Item("4. Track=1## -> Disc=1 and Track=##") = ""
dic.Item("5. Disc=1 -> Disc=1 and Track=1##") = ""
Dim temp : temp = SkinnedListBox("Please select a mode:","CombineAlbums",dic.Keys,mode)
If temp = "" Then
Exit Sub
End If
mode = Int(Left(temp,1))-1
SDB.IniFile.IntValue("CombineAlbums","Mode") = mode
End If
Dim re
Dim disc, firstIndex
Dim matches, match
Set re = new regexp 'Create the RegExp object
re.Pattern = "\s[\(\[]?(CD|DIS[CK])\s?(\d+)[\)\]]?\s*$"
re.IgnoreCase = true
For i = 0 To list.Count-1
prog.Text = "CombineAlbums: Checking file "&(i+1)&" of "&list.Count&"..."
prog.Value = i
Dim itm : Set itm = list.Item(i)
Set matches = re.Execute(itm.AlbumName)
If matches.Count = 1 Then
Set match = matches.Item(0)
firstIndex = match.FirstIndex
disc = match.SubMatches(1)
' msgbox (match &": "& match.SubMatches.Count &" - "& match.SubMatches(1) &" - "& firstIndex)
End If
Select Case mode
Case 0
If matches.Count = 1 Then
c = c + 1
Call process1(itm, disc, firstIndex)
End If
Case 1
If matches.Count = 1 Then
c = c + 1
Call process2(itm, disc, firstIndex)
End If
Case 2
If matches.Count = 1 Then
c = c + 1
Call process1(itm, disc, firstIndex)
Call process2(itm, disc, firstIndex)
End If
Case 3
c = c + 1
Call process3(itm,c)
Case 4
c = c + 1
firstIndex = Len(itm.AlbumName)
disc = itm.DiscNumber
Call process1(itm, disc, firstIndex)
Call process2(itm, disc, firstIndex)
Case Else
Call SDB.MessageBox("CombineAlbums: Unknown mode '"&mode&"'.",mtError,Array(mbOk))
Exit Sub
End Select
If prog.Terminate Then
Exit Sub
End If
Next
prog.Text = "CombineAlbums: Finalising script..."
prog.Value = prog.MaxValue
Call list.UpdateAll
Call SDB.MessageBox("CombineAlbums: Updated "&c&" out of "&list.Count&" tracks.",mtInformation,Array(mbOk))
End Sub
' 1. AlbumName"&cd1&" -> AlbumName and Track=1##
Sub process1(itm, disc, firstIndex)
Dim s : s = itm.AlbumName
If Left(disc, 1) = "0" Then
disc = Mid(disc, 2)
End If
disc = (Asc(disc) - Asc(0)) * 100
do while Itm.TrackOrder > 100
Itm.TrackOrder = Itm.TrackOrder - 100
loop
' msgbox(Left(s, firstIndex))
' msgbox(disc + Itm.TrackOrder)
itm.AlbumName = Left(s, firstIndex)
itm.TrackOrder = disc + Itm.TrackOrder
End Sub
' 2. AlbumName"&cd1&" -> AlbumName and Disc=1
Sub process2(itm, disc, firstIndex)
Dim s : s = itm.AlbumName
If Left(disc, 1) = "0" Then
disc = Mid(disc, 2)
End If
disc = Asc(disc) - Asc(0)
' msgbox(Left(s, firstIndex))
' msgbox(disc)
itm.AlbumName = Left(s, firstIndex)
itm.DiscNumber = disc
End Sub
' 3. Track=1## -> Disc=1 and Track=##
Sub process3(itm,c)
Dim s : s = itm.TrackOrderStr
If Len(s) > 2 Then
c = c + 1
itm.DiscNumber = Int(Left(s,1))
itm.TrackOrder = Int(Mid(s,2))
End If
End Sub
Function SkinnedListBox(Text, Caption, Options, Default)
Dim Form, Label, Edt, btnOk, btnCancel, modalResult, i
' 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.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.NewDropDown(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.Style = 2
Edt.AddItem("Please select...")
For i = 0 To UBound(Options)
Edt.AddItem(Options(i))
Next
Edt.ItemIndex = Default
' 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) And (Edt.ItemIndex > 0) Then
SkinnedListBox = Options(Edt.ItemIndex-1)
Else
SkinnedListBox = ""
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("CombineAlbums","Filename") = "CombineAlbums.vbs"
inif.StringValue("CombineAlbums","Procname") = "CombineAlbums"
inif.StringValue("CombineAlbums","Order") = "18"
inif.StringValue("CombineAlbums","DisplayName") = "Combine Albums"
inif.StringValue("CombineAlbums","Description") = "Change album naming conventions"
inif.StringValue("CombineAlbums","Language") = "VBScript"
inif.StringValue("CombineAlbums","ScriptType") = "0"
SDB.RefreshScriptItems
End If
End Sub
Code: Select all
'
' MediaMonkey Script
'
' NAME: CombineAlbums 3.0 Reloaded
'
' AUTHOR: trixmoto (http://trixmoto.net)
' AUTHOR: andig (http://cpuidle.de/blog/)
' DATE : 24/01/2008
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
' Set up text for your albums (see below: *)
'
' [CombineAlbums2]
' FileName=CombineAlbums2.vbs
' ProcName=CombineAlbums2
' Order=18
' DisplayName=Combine Albums 2
' Description=Change album naming conventions
' Language=VBScript
' ScriptType=0
'
Option Explicit
'* The text which wants to be removed from the album name
Dim cd1 : cd1 = " (CD 1)"
Dim cd2 : cd2 = " (CD 2)"
Dim cd3 : cd3 = " (CD 3)"
Sub CombineAlbums2
Dim list : Set list = SDB.CurrentSongList
If list.Count = 0 Then
Call SDB.MessageBox("CombineAlbums: No tracks selected to process.",mtError,Array(mbOk))
Exit Sub
End If
Dim prog : Set prog = SDB.Progress
prog.Text = "CombineAlbums: Initialising script..."
prog.MaxValue = list.Count
Dim c : c = 0
Dim i : i = 0
Dim mode : mode = 0
If SDB.VersionHi > 2 Then
mode = SDB.IniFile.IntValue("CombineAlbums","Mode")+1
Dim dic : Set dic = CreateObject("Scripting.Dictionary")
dic.Item("1. AlbumName"&cd1&" -> AlbumName and Track=1##") = ""
dic.Item("2. AlbumName"&cd1&" -> AlbumName and Disc=1") = ""
dic.Item("3. AlbumName"&cd1&" -> AlbumName and Disc=1 and Track=1##") = ""
dic.Item("4. Track=1## -> Disc=1 and Track=##") = ""
dic.Item("5. Disc=1 -> Disc=1 and Track=1##") = ""
Dim temp : temp = SkinnedListBox("Please select a mode:","CombineAlbums",dic.Keys,mode)
If temp = "" Then
Exit Sub
End If
mode = Int(Left(temp,1))-1
SDB.IniFile.IntValue("CombineAlbums","Mode") = mode
End If
Dim re
Dim disc, albumname, firstIndex
Dim matches, match
Set re = new regexp 'Create the RegExp object
For i = 0 To list.Count-1
prog.Text = "CombineAlbums: Checking file "&(i+1)&" of "&list.Count&"..."
prog.Value = i
Dim itm : Set itm = list.Item(i)
albumname = itm.AlbumName
disc = itm.DiscNumber
re.Pattern = "\s[\(\[]?(CD|DIS[CK])[_ ]?(\d+)[\)\]]?\s*$"
re.IgnoreCase = true
' match on album name
Set matches = re.Execute(itm.AlbumName)
If matches.Count = 1 Then
Set match = matches.Item(0)
firstIndex = match.FirstIndex
disc = match.SubMatches(1)
albumname = Left(itm.AlbumName, firstIndex)
' msgbox (match &": "& match.SubMatches.Count &" - "& match.SubMatches(1) &" - "& firstIndex)
' alternatively match on path name
Else
re.Pattern = "(\\|\s)[\(\[]?(CD|DIS[CK])[_ ]?(\d+)[\)\]]?\s*\\"
Set matches = re.Execute(itm.Path)
'msgbox("matches.Count: "&matches.Count)
If matches.Count = 1 Then
Set match = matches.Item(0)
'msgbox("match.SubMatches.Count: "&match.SubMatches.Count)
'msgbox(match)
disc = match.SubMatches(2)
'msgbox("disc: "&disc)
End If
'msgbox("itm.Path: "&itm.Path)
End If
' update according to mode
Select Case mode
Case 0
If matches.Count = 1 Then
c = c + 1
Call process1(itm, albumname, disc)
End If
Case 1
If matches.Count = 1 Then
c = c + 1
Call process2(itm, albumname, disc)
End If
Case 2
If matches.Count = 1 Then
c = c + 1
Call process1(itm, albumname, disc)
Call process2(itm, albumname, disc)
End If
Case 3
' operations are counted inside procedure
Call process3(itm,c)
Case 4
c = c + 1
albumname = itm.AlbumName
disc = itm.DiscNumber
Call process1(itm, albumname, disc)
Call process2(itm, albumname, disc)
Case Else
Call SDB.MessageBox("CombineAlbums: Unknown mode '"&mode&"'.",mtError,Array(mbOk))
Exit Sub
End Select
If prog.Terminate Then
Exit Sub
End If
Next
prog.Text = "CombineAlbums: Finalising script..."
prog.Value = prog.MaxValue
Call list.UpdateAll
Call SDB.MessageBox("CombineAlbums: Updated "&c&" out of "&list.Count&" tracks.",mtInformation,Array(mbOk))
End Sub
' 1. AlbumName"&cd1&" -> AlbumName and Track=1##
Sub process1(itm, albumname, disc)
'msgbox("proc1 "&albumname&" "&disc)
If Left(disc, 1) = "0" Then
disc = Mid(disc, 2)
End If
disc = (Asc(disc) - Asc(0)) * 100
do while Itm.TrackOrder > 100
Itm.TrackOrder = Itm.TrackOrder - 100
loop
' msgbox(Left(s, firstIndex))
' msgbox(disc + Itm.TrackOrder)
itm.AlbumName = albumname
itm.TrackOrder = disc + Itm.TrackOrder
End Sub
' 2. AlbumName"&cd1&" -> AlbumName and Disc=1
Sub process2(itm, albumname, disc)
If Left(disc, 1) = "0" Then
disc = Mid(disc, 2)
End If
disc = Asc(disc) - Asc(0)
' msgbox(Left(s, firstIndex))
' msgbox(disc)
itm.AlbumName = albumname
itm.DiscNumber = disc
End Sub
' 3. Track=1## -> Disc=1 and Track=##
Sub process3(itm,c)
Dim s : s = itm.TrackOrderStr
If Len(s) > 2 Then
c = c + 1
itm.DiscNumber = Int(Left(s,1))
itm.TrackOrder = Int(Mid(s,2))
End If
End Sub
Function SkinnedListBox(Text, Caption, Options, Default)
Dim Form, Label, Edt, btnOk, btnCancel, modalResult, i
' 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.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.NewDropDown(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.Style = 2
Edt.AddItem("Please select...")
For i = 0 To UBound(Options)
Edt.AddItem(Options(i))
Next
Edt.ItemIndex = Default
' 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) And (Edt.ItemIndex > 0) Then
SkinnedListBox = Options(Edt.ItemIndex-1)
Else
SkinnedListBox = ""
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("CombineAlbums","Filename") = "CombineAlbums.vbs"
inif.StringValue("CombineAlbums","Procname") = "CombineAlbums"
inif.StringValue("CombineAlbums","Order") = "18"
inif.StringValue("CombineAlbums","DisplayName") = "Combine Albums"
inif.StringValue("CombineAlbums","Description") = "Change album naming conventions"
inif.StringValue("CombineAlbums","Language") = "VBScript"
inif.StringValue("CombineAlbums","ScriptType") = "0"
SDB.RefreshScriptItems
End If
End Sub