Combine Albums 3.2 - Updated 26/12/2012

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Combine Albums 3.2 - Updated 26/12/2012

Post by trixmoto »

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
Last edited by trixmoto on Mon Mar 10, 2008 11:32 am, edited 3 times in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

A few ideas if you feel like updating this at some point:

- The script appears to be case sensitive, so Disc 1 is not the same as disc 1, and probly should be.

- support much larger number of discs (ie for those 10+ disc box sets), ideally it would check for any disc increment up to at least 10 or 20.

- include support for multiple disc format types, ie (CD 1), CD1, (disc 1), disc 1, etc

- sync tags after updating, it appears that it currently does not, or does not properly update the tag (only the db)

- possibly an option for preview with option to cancel

- remove or make optional the summary dialog

- a toolbar icon would be convenient, as would a hotkey combo (not sure what would be a good one thats not used already)

- if you really want to get complex, It would be great if it could automatically do this for any album edit that included the above disc/cd formats via the events

That's all I can think of at the moment, but should keep ya busy(ier) for a while. 8) :o
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

The script was originally written for people who have a naming convention but wish to convert to the numbered approach (like me) so I tried to keep it simple.

You suggestions are good though, and if I have some spare time (I wish!) then I will certainly think about making this script more powerful.

Thanks as always for your comments! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Robin

Combine Albums

Post by Robin »

Brilliant concept, just what I needed.

Unfortunately, although I can see it works the tag changes are not saved by MM.

Am I doing something wrong?
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Thanks. I think you need to replace...

Code: Select all

    itm.UpdateDB
    If prog.Terminate Then Exit For
  Next
...with...

Code: Select all

    If prog.Terminate Then Exit For
  Next
  list.UpdateAll
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
tj_junk
Posts: 71
Joined: Thu Apr 13, 2006 10:10 am

Modified Trixmoto's script using regular expressions

Post by tj_junk »

I took the liberty of modifying Trixmoto's script, using regular expressions to perform the pattern match. Regular expression allow for much greater flexibility and searching capability versus the hard-coded "InStr()" commands.

As such, I think the modified script is a worthwhile improvement. Please try it out.

Here are my notes:
See below
Here is the modified script, in its entirety:

Code: Select all

See below
tj_junk
Posts: 71
Joined: Thu Apr 13, 2006 10:10 am

Forgot to quote a comment line...

Post by tj_junk »

I forgot to quote a comment line (line #53).
This script should now work fine...

Code: Select all

'=============================================================================================================================================
'
' MediaMonkey Script
'
' NAME: CombineAlbums 1.0
'
' AUTHOR: trixmoto (http://trix.dork.com)
' DATE : 16/01/2006 
'
' 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: *)
'
' [CombineAlbums]
' FileName=CombineAlbums.vbs
' ProcName=CombineAlbums
' Order=18
' DisplayName=Combine Albums
' Description=Combine Albums
' Language=VBScript
' ScriptType=0 
'
'=============================================================================================================================================
' MODIFIED BY:  tj_junk
' DATE :  2007-02-26
'
' MODIFICATIONS:
'
' - Uses regular expressions to improve the pattern matching capability and flexibility
' - Supports disc/cd numbers up to 20 (from the original author's max of 3)
' - Supports number strings (e.g., "Disc One")
' - Is case-insensitive
'
'    Basically, it searches for the text "CD" or "Disc" followed by a "disc number"
'    - The disc number can be represented by numeric digits (e.g. 1,2,3) or text (e.g., "one","two","three")
'    - The disc number can be optionally preceded by the number sign (#) and/or white space
'    - The entire string can be optionally enclosed by square brackets, curly brackets, or parentheses
'    - The entire string can be optionally preceded by a single comma and/or white space
'
'=============================================================================================================================================
' NOTES:
'
' I.   As in the original script, any disc number text (e.g., " (CD 1)" or ", [disc twelve]") is removed from the album text
'   -  An option could added in the future to "Modify album text (Y/N)?", defaulting to "Yes"
'
' II.  I purposely chose not to mess with any preceding or trailing colon characters (":")
'   -  You could easily modify the regExpPatterns to your personal preference
'
' III. This script will detect false matches on album text such as "CD5", where "CD5" refers to a 5-inch CD single.  Oh, well.
'   -  I suppose someone could implement an HTML popup that lets you preview/confirm changes (ala, Risser's Case Checker)
'
' IV.  This script can be easily modified to support regional variations of the terms "CD" or "Disc" (e.g., "disque"), 
'       as well as equivalents for the number text (e.g., "un", "deux", "trois").
'
' TO USE:
'    - Use the MediaMonkey search tool (Ctrl-F) to look for "CD" or "Disc" (or a similar term) in the album field
'    - Then, simply highlight the desired tracks and run the script ( Tools -> Script -> CombineAlbums )
'=============================================================================================================================================

Option Explicit

Dim regExpPatterns, regExpPatternsList
regExpPatterns =   ",?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(1|one|un)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(2|two|deux)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(3|three|trois)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(4|four|quatre)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(5|five|cinq)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(6|six)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(7|seven|sept)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(8|eight|huit)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(9|nine|neuf)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(10|ten|dix)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(11|eleven|onze)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(12|twelve|douze)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(13|thirteen|treize)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(14|fourteen|quatorze)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(15|fifteen|quinze)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(16|sixteen|seize)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(17|seventeen|dix-sept)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(18|eighteen|dix-huit)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(19|nineteen|dix-neuf)\b\s?[\]\}\)]?" _
		& "&,?\s?[\[\{\(]?(CD|Disc|Disque)\s?#?(20|twenty|vingt)\b\s?[\]\}\)]?"
regExpPatternsList = Split(regExpPatterns,"&")

'==========================================================================================================
Sub CombineAlbums


  Dim list,itm,prog,i,p,s,c
  Set list = SDB.CurrentSongList
    
  Set prog = SDB.Progress
  prog.Text = "Initialising script..."
  prog.MaxValue = list.Count
  c = 0

  Dim regEx, regExFound, j
  Set regEx = New RegExp   ' Create a regular expression.
  regEx.ignoreCase = True   ' Set case insensitivity.

  
  For i=0 To list.Count-1
    prog.Text = "Checking file "&(i+1)&" of "&list.Count&"..."
    prog.Value = i
    Set itm = list.Item(i)
    s = itm.AlbumName
    
    For j = 0 To UBound(regExpPatternsList)
      regEx.pattern = regExpPatternsList(j)
      regExFound = regEx.Test(s)
      If regExFound Then
          If itm.TrackOrder < 100 Then
            c = c + 1
            itm.AlbumName = regEx.Replace(s, "")
            itm.TrackOrder = ((j+1)*100)+Itm.TrackOrder
          End If
      End If
    Next    

    itm.UpdateDB
    If prog.Terminate Then Exit For
  Next
  
  prog.Text = "Finalizing script..."
  prog.Value = prog.MaxValue
  p = SDB.MessageBox("Tracks updated: "&c&" out of "&list.Count,mtInformation,Array(mbOk))
  Set prog = Nothing

End Sub
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

With MM3 this can be modified again to separate the disc and number values into the separate fields.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

New version (2.0) is now available to download from my website. Changes include...

- Added new processes using disc number in MM3
- Fixed tags not being written to
- Fixed case sensitivity

The processes available are...

1. AlbumName (CD1) -> AlbumName and Track=1##
2. AlbumName (CD1) -> AlbumName and Disc=1
3. Track=1## -> Disc=1 and Track=##
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Combine Albums 2.0

Post by chrisjj »

>convert the track number from 1 to 101 (etc)

Warning: there are discs with >100 tracks e.g. http://eng.tango.info/02480002101123 .
Chris
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Unfortunately this script doesn't cater for them, sorry.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
sommo

Post by sommo »

Working great for me :)
Just a few little things...
Instead of it just been "CD 1" could it be either
  • CD1
    1CD
    Disk 1
    Disk1
    Disc1
    Disc 1
as well as 'not in any thing', (),[],{}

and instead of converting the songs from 1 to 100 & 200 could it just follow on from 1 and auto increase?
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

You can open "CombineAlbums.vbs" in a text editor and change these lines at the top...

Code: Select all

Dim cd1 : cd1 = " (CD 1)"
Dim cd2 : cd2 = " (CD 2)"
Dim cd3 : cd3 = " (CD 3)"
This should allow you to do other naming conventions, although this script only supports three discs.

I'm not sure what you mean exactly but the last part. There is a script that's shipped with MM (I think!) for auto re-numbering tracks in order. Is that what you're after?
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
sommo

Post by sommo »

Do I have to change them every time or can I do:
Dim cd1 : cd1 = " (CD 1)"
Dim cd2 : cd2 = " (CD 2)"
Dim cd3 : cd3 = " (CD 3)"
Dim cd4 : cd4 = " (CD1)"
Dim cd5 : cd5 = " (CD2)"
Dim cd6 : cd6 = " (CD3)
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

No, you can only use "cd1", "cd2" and "cd3".
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Post Reply