Combine Albums 3.2 - Updated 26/12/2012
Posted: Mon Jan 16, 2006 11:06 am
This is very similar to this script. However you do not need to manually enter the disc number. What this script does is look for the string you use to represent disc number in the album name "<Album> (CD1)" and remove " (CD1)" from the album name and convert the track number from 1 to 101 (etc). This script currently works with up to 3 CDs.
Code: Select all
'
' MediaMonkey Script
'
' NAME: CombineAlbums 3.2
'
' AUTHOR: trixmoto (http://trixmoto.net)
' AUTHOR: andig (http://cpuidle.de/blog/)
' DATE : 26/12/2012
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
'
' [CombineAlbums]
' FileName=CombineAlbums.vbs
' ProcName=CombineAlbums
' Order=18
' DisplayName=Combine Albums
' Description=Change album naming conventions
' Language=VBScript
' ScriptType=0
'
' FIXES: Fixed disc numbers larger than 9 (thanks to andig)
'
Option Explicit
Sub CombineAlbums
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
SDB.ProcessMessages
Dim mode : mode = SDB.IniFile.IntValue("CombineAlbums","Mode")+1
Dim dic : Set dic = CreateObject("Scripting.Dictionary")
dic.Item("1. AlbumName (CD 1) -> AlbumName and Track=1##") = ""
dic.Item("2. AlbumName (CD 1) -> AlbumName and Disc=1") = ""
dic.Item("3. AlbumName (CD 1) -> 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
Dim re : Set re = new regexp
Dim disc,albumname,firstIndex,matches,match
Dim c : c = 0
Dim i : i = 0
For i = 0 To list.Count-1
prog.Text = "CombineAlbums: Checking file "&(i+1)&" of "&list.Count&"..."
prog.Value = i
SDB.ProcessMessages
Dim itm : Set itm = list.Item(i)
albumname = itm.AlbumName
disc = itm.DiscNumber
re.Pattern = "\s[\(\[]?(CD|DIS[CK])[_ ]?(\d+)[\)\]]?\s*$"
re.IgnoreCase = True
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)
Else
re.Pattern = "(\\|\s)[\(\[]?(CD|DIS[CK])[_ ]?(\d+)[\)\]]?\s*\\"
Set matches = re.Execute(itm.Path)
If matches.Count = 1 Then
Set match = matches.Item(0)
disc = match.SubMatches(2)
End If
End If
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
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
SDB.ProcessMessages
If prog.Terminate Then
Exit Sub
End If
Next
prog.Text = "CombineAlbums: Finalising script..."
prog.Value = prog.MaxValue
SDB.ProcessMessages
Call list.UpdateAll()
Call SDB.MessageBox("CombineAlbums: Updated "&c&" out of "&list.Count&" tracks.",mtInformation,Array(mbOk))
End Sub
' 1. AlbumName (CD 1) -> AlbumName and Track=1##
Sub process1(itm,albumname,disc)
If IsNumeric(disc) Then
disc = Int(disc)
Else
disc = Int(Asc(disc)-Asc(0))
End If
Do While (Itm.TrackOrder > 100)
Itm.TrackOrder = Itm.TrackOrder-100
Loop
itm.AlbumName = albumname
itm.TrackOrder = (disc*100)+Itm.TrackOrder
End Sub
' 2. AlbumName (CD 1) -> AlbumName and Disc=1
Sub process2(itm,albumname,disc)
If IsNumeric(disc) Then
disc = Int(disc)
Else
disc = Int(Asc(disc)-Asc(0))
End If
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,Len(s)-2))
itm.TrackOrder = Int(Mid(s,Len(s)-1))
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