Page 2 of 4

Posted: Fri May 23, 2008 7:23 pm
by lizardo
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?

Posted: Sat May 24, 2008 3:33 am
by trixmoto
That's strange. It's probably because one of your album names includes a character that VBScript doesn't like. Any extended characters, maybe Japanese or something?

Posted: Sat May 24, 2008 9:38 am
by lizardo
It's all English, but there may be some punctuation marks in there (question marks, apostrophes, etc.)

Re: Combine Albums 2.0 [MM2+3]

Posted: Sat Jun 28, 2008 12:26 pm
by sommo
I would just like to say a thank you trixmoto, for this addon!
This is one of the reason why I use MediaMonkey!
It is really helpful and I do use it :)
Keep up the good work & Happy coding!

Re: Combine Albums 2.0 [MM2+3]

Posted: Sun Jan 04, 2009 9:07 pm
by mnrbig
Hi

Can this script be used to combine albums where you have the disc number field populated with for eg 1/5 to indicate that the disc is number one of a five cd set?

Re: Combine Albums 2.0 [MM2+3]

Posted: Mon Jan 05, 2009 5:03 am
by trixmoto
It fixes track=101 to disc=1 and track=01 etc, but not disc=1 and track=01 to track=101. Is that what you're after?

Re: Combine Albums 2.0 [MM2+3]

Posted: Mon Jan 05, 2009 6:28 am
by mnrbig
Yes

Actually more like disc=1/5 (ie disc one of fivediscs) track=1 to track=101.
and disc=2/5 track=1 to track=201.

Re: Combine Albums 2.0 [MM2+3]

Posted: Mon Jan 05, 2009 8:09 am
by trixmoto
At the moment this is not an option but I will add it to the next version. :)

Re: Combine Albums 2.0 [MM2+3]

Posted: Thu Aug 27, 2009 6:52 am
by andig
Hi All,

I've expanded the regex idea a little bit:
- support for >3 disks
- support for naming conventions CD, Disc and Disk, upper and lower case
Additional naming modes:
- AlbumName CD1 -> AlbumName and Disc=1 and Track=1##
- Track=1## -> Disc=1 and Track=##

I would be happy if this could make it into the next "official" Combine Albums version- permissions granted!

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

Re: Combine Albums 2.0 [MM2+3]

Posted: Thu Aug 27, 2009 11:55 am
by trixmoto
Thanks for this, I'll certainly include this in the next version. :)

Re: Combine Albums 2.0 [MM2+3]

Posted: Fri Aug 28, 2009 11:25 am
by andig
I've updated the script again- now takes disk names also into account if they're not encoded in the album title but the path name instead. Underscores _ as separators are now supported as well.

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

Re: Combine Albums 3.0 - Updated 11/01/2010

Posted: Mon Jan 11, 2010 12:59 pm
by trixmoto
New version (3.0) is now available to download from my website. Changes include...

- Removed old MM2 code
- Added new processes 4 and 5
- Added pattern instead of string matching
- Added update server to installation package.

Thank you to andig who implemented the new processes (4. "Track=1## -> Disc=1 and Track=##" and 5. "Disc=1 -> Disc=1 and Track=1##") and also replaced my simple string matching with a much more powerful pattern matching algorithm.

Re: Combine Albums 3.0 - Updated 11/01/2010

Posted: Mon Jan 11, 2010 2:48 pm
by andig
You're welcome. Thank I don't have to maintain it ;)

Re: Combine Albums 3.0 - Updated 11/01/2010

Posted: Mon May 31, 2010 1:36 pm
by neFAST
Before running your script I would like to know if it can handle my naming convention:

\Artist - Album\CD 1\track01.mp3 with album tag = "Album - CD 1"
\Artist - Album\CD 1\track02.mp3
\Artist - Album\CD 1\track03.mp3
\Artist - Album\CD 2\track01.mp3 with album tag = "Album - CD 2"
\Artist - Album\CD 2\track02.mp3
\Artist - Album\CD 2\track03.mp3

Thanks a lot

Re: Combine Albums 3.0 - Updated 11/01/2010

Posted: Tue Jun 01, 2010 3:44 am
by trixmoto
Yeah, I think so.