New script: Change track# format to <disc#><trk#

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: New script: Change track# format to <disc#><trk#

Re: New script: Change track# format to <disc#><trk#

by skywalka » Sat Jul 12, 2014 8:07 pm

Had to reinstall Windows & spent hours looking for this again. It's very handy & shouldn't only be found buried away in the forum.

Re: New script: Change track# format to <disc#><trk#

by skywalka » Mon Nov 04, 2013 6:58 am

roylayer wrote:I really dislike albums tagged like "Yessongs (disc 1)" and "Yessongs (disc 2)." It's really all one album! Using that scheme, the tracks are usually labeled 1-n within each disc.

I prefer having one album entry per album and giving each track a unique number. 1-n would be fine, but an alternative that is especially useful if track numbers already exist under the "disc n" philosophy is to label them with a <disc#><trk#> scheme. Thus, disc 1, trk 3 becomes track# 103. I have developed a script to do this. (My first script! Yay!) Here it is:

FILENAME: FixTrkNo.vbs

'changes track# from format t to dtt (e.g. disc 1, trk 3 becomes track# 103)
'where t = trk# and d = disc#
'only works for track#s 99 or less

Option Explicit

Sub FixTrkNo
'Define variables
Dim list, itm, i, tmp, discno

discno = inputbox("Enter disc number")

'Get list of selected tracks from MediaMonkey
Set list = SDB.SelectedSongList
If list.count=0 Then
Set list = SDB.AllVisibleSongList
End If

'Process all selected tracks
For i=0 To list.count-1
Set itm = list.Item(i)

if itm.trackorder < 10 then
itm.TrackOrder = discno & "0" & itm.TrackOrder
else
itm.TrackOrder = discno & itm.TrackOrder
end if

'Update the changes in DB
itm.UpdateDB
Next
End Sub

ADD THIS ENTRY TO YOUR SCRIPTS.INI FILE:

[FixTrkNo]
FileName=FixTrkNo.vbs
ProcName=FixTrkNo
Order=2
DisplayName=&Format Track# to dnn
Description=Change Track# to disc number + track#
Language=VBScript
ScriptType=0

To use, highlight the tracks you want to change, then execute the script. It will ask you which disc# you want and will then do the rename.
Loving this script.

Thanx heaps.

Re:

by B68987 » Wed Aug 10, 2011 10:16 pm

roylayer wrote:Glad you like it!

P.S. As you can see in the script, I was able to work around not knowing how to format the track number with a leading zero. Just curious about it for future reference.

Just use itm.TrackOrderStr instead of itm.TrackOrder

by andig » Sat Mar 17, 2007 7:12 am

Made a little extension that will also check path name if album name check fails:

Code: Select all

  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
    path = itm.Path ' alternatively check for path name, too
   
    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
	  Else
	  		' alternatively check for path name, too
			regExFound = regEx.Test(path)
			If regExFound Then
			  If itm.TrackOrder < 100 Then
				c = c + 1
				itm.TrackOrder = ((j+1)*100)+Itm.TrackOrder
			  End If
			End If
      End If
    Next   

    itm.UpdateDB
    If prog.Terminate Then Exit For
  Next

(Forgot to quote a comment line...)

by tj_junk » Mon Feb 26, 2007 11:23 am

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

Try this improvement on TrixMoto's script...

by tj_junk » Mon Feb 26, 2007 11:16 am

Try this improvement on TrixMoto's script... I modified the original script, using regular expressions to perform the pattern match, instead of "InStr()" commands. Regular expressions are much more powerful and flexible (but they do require a slight learning curve if you're unfamiliar).

Here are my notes from the modified script:
' - 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 )
Here is the modified script, in its entirety:

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

by Guest » Sat Jan 20, 2007 12:18 pm

Sorry for the n00b question, but how do you get the renumbered tracks numbers to be updated in the tag for the files, it looks like it just updates it in the MM database.

by trixmoto » Mon Jan 16, 2006 11:20 am

This script can be used to automatically fill in the disc number as well (assuming that your album names are named systematically): http://www.mediamonkey.com/forum/viewtopic.php?t=7588

Formatting with leading zero

by GuidoR13 » Tue Aug 23, 2005 11:12 am

roylayer wrote:Glad you like it!
P.S. As you can see in the script, I was able to work around not knowing how to format the track number with a leading zero. Just curious about it for future reference.
Perhaps a solution in my small script here, I use a string of zeros and the left function. Works for me with 700+ songs ...

by Guest » Fri Jul 29, 2005 2:10 pm

Looks good, RK! I still use my original script all the time, but it's also nice to have these variations available for special cases.

by rk » Fri Jul 29, 2005 3:56 am

May I suggest a further improvement of the script (by the way: my first script :D ). The last version leaves the track number untouched if it is already set. But probably you still want the disc# as a prefix.

How about this ...

Code: Select all

'creates a track# in the dtt format (e.g. disc 1, trc i becomes track# 10i) 
'goes through all selected tracks sequentially, always starting with track# 1 
'Writes disc#+track# if trck# already set, otherwiese disc#+list position

Option Explicit 

Sub CorrectTrackNumber

'Define variables 
Dim list, itm, i
Dim discno, trackno

discno = inputbox("Enter disc number") 
'Remember: discno can be entered empty!

'-----------------
'Get list of selected tracks from MediaMonkey 
'-----------------
Set list = SDB.SelectedSongList 
If list.count=0 Then 
  Set list = SDB.AllVisibleSongList 
End If 

'-----------------
'Process all selected tracks 
'-----------------
For i=1 To list.count
  Set itm = list.Item(i-1) 

' Determine the track# to use
  if itm.trackorder < 1 then 
    trackno = i
  else 
    trackno = itm.trackorder
  end if

' concatenate disc# and track#
  if trackno < 10 then 
    itm.TrackOrder = discno & "0" & trackno
  else 
    itm.TrackOrder = discno & trackno
  end if 

  'Update the changes in DB 
  itm.UpdateDB 
Next

End Sub 

by roylayer » Thu Mar 18, 2004 9:52 am

Thanks, docbobo. This could come in handy at times! Usually, I've been able to set track numbers via "tag from filename," but this could save me from having to do that step. I look forward to future updates.

P.S. You might want to use the "Code" button in the forum to post your code. It should preserve any indentations that way and make it easier to read. (I didn't know about that myself when I posted the original script!)

Modified Script to CREATE Track numbers

by docbobo » Thu Mar 18, 2004 5:28 am

This is a great script! I took the liberty of modifying it so that I can automatically create track numbers on tracks that do not have one yet. It's simple, but it works. Will work on it more to give a start number and pass tracks that already have a number without increasing the counter.

Here we go:

[b]---cut here---[/b]
'creates a track# in the dtt format (e.g. disc 1, trc i becomes track# 10i)
'goes through all selected tracks sequentially, always starting with track# 1
'should skip all tracks that do have numbers

Option Explicit

Sub MkTrkNo
'Define variables
Dim list, itm, i, tmp, discno

discno = inputbox("Enter disc number")

'Get list of selected tracks from MediaMonkey
Set list = SDB.SelectedSongList
If list.count=0 Then
Set list = SDB.AllVisibleSongList
End If

'Process all selected tracks
For i=1 To list.count
Set itm = list.Item(i-1)

if itm.trackorder < 1 then
if i < 10 then
itm.TrackOrder = discno & "0" & i
else
itm.TrackOrder = discno & i
end if
end if

'Update the changes in DB
itm.UpdateDB
Next
End Sub
[b]---cut here---[/b]

This needs to go into Scripts.ini

[b]---cut here---[/b]
[MkTrkNo]
FileName=MkTrkNo.vbs
ProcName=MkTrkNo
Order=2
DisplayName=&Make Track# in dnn format
Description=Create Track# (starting at 1) in disc number + track#
Language=VBScript
ScriptType=0

by Pablo » Mon Mar 01, 2004 3:14 am

Nice Script! (the concept... haven't tried it yet). Also it's a simple and clean script which is good to look at to learn scripting...

Pablo

by roylayer » Mon Mar 01, 2004 12:41 am

Glad you like it!

P.S. As you can see in the script, I was able to work around not knowing how to format the track number with a leading zero. Just curious about it for future reference.

Top