by trixmoto » Tue Jun 12, 2007 10:44 am
This is another script that has been designed by someone else and requested via my website. Firstly select a Location or My Computer node that you want to split into CD sized folders. Then select the script from the Tools menu and it will ask you to select the mode and size limit (song length in minutes or file length in megabytes). When you click "Ok" it will move the files into folders of the correct size.
The installer is available to download from my website!
Code: Select all
'
' MediaMonkey Script
'
' NAME: DiscSplitter 1.2
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 22/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
'
' [DiscSplitter]
' FileName=DiscSplitter.vbs
' ProcName=DiscSplitter
' Order=100
' DisplayName=&Disc Splitter
' Description=Split tracks into groups of disc size
' Language=VBScript
' ScriptType=0
'
' FIXES: Made compatible with MM3
' Added option to split by physical size
'
Option Explicit
Dim DiskSize : DiskSize = 80 'Default CD size in minutes
Dim FileSize : FileSize = 700 'Default CD size in megabytes
Sub DiscSplitter
'get current node
Dim cur : Set cur = SDB.MainTree.CurrentNode
If cur Is Nothing Then
Call SDB.MessageBox("DiscSplitter: No node is selected.",mtError,Array(mbOk))
Exit Sub
End If
'check node type
Dim loc : loc = ""
Select Case cur.NodeType
Case 64
loc = SDB.MainTree.CurrentNode.Path
Case 62
loc = Mid(SDB.MainTree.CurrentNode.Path,2)
Case Else
Call SDB.MessageBox("DiscSplitter: Selected node type ("&cur.NodeType&") is not suitable.",mtError,Array(mbOk))
Exit Sub
End Select
'check track count
Dim dit : Set dit = SDB.Database.OpenSQL("SELECT Count(*), Sum(Songs.SongLength), Sum(Songs.FileLength) FROM Songs WHERE Songs.SongPath LIKE '"&loc&"%'")
Dim tot : tot = dit.ValueByIndex(0)
If tot = 0 Then
Call SDB.MessageBox("DiscSplitter: Selected node contains no tracks.",mtError,Array(mbOk))
Exit Sub
End If
'get options
Dim ini : Set ini = SDB.IniFile
Dim mode : mode = ini.IntValue("DiscSplitter","Mode")
If Not (ini.StringValue("DiscSplitter","Disk") = "") Then
DiskSize = ini.IntValue("DiscSplitter","Disk")
End If
If Not (ini.StringValue("DiscSplitter","File") = "") Then
FileSize = ini.IntValue("DiscSplitter","File")
End If
'create confirmation
Dim Form1 : Set Form1 = SDB.UI.NewForm
Form1.BorderStyle = 3
Form1.Caption = "Disc Splitter"
Form1.FormPosition = 4
Form1.StayOnTop = True
Form1.Common.ControlName = "DiscSplitterForm"
Form1.Common.SetRect 0,0,200,150
Dim Label1 : Set Label1 = SDB.UI.NewLabel(Form1)
Label1.Common.SetRect 10,10,65,17
Label1.Caption = "Please select options..."
Dim Label2 : Set Label2 = SDB.UI.NewLabel(Form1)
Label2.Common.SetRect 10,35,65,17
Label2.Caption = "Mode:"
Dim Label3 : Set Label3 = SDB.UI.NewLabel(Form1)
Label3.Common.SetRect 10,60,65,17
Label3.Caption = "Size:"
Dim DropDown1 : Set DropDown1 = SDB.UI.NewDropDown(Form1)
DropDown1.Common.SetRect 50,32,120,21
DropDown1.AddItem("Disk size (mins)")
DropDown1.AddItem("File size (mb)")
DropDown1.ItemIndex = mode
DropDown1.Style = 2
Dim Edit1 : Set Edit1 = SDB.UI.NewEdit(Form1)
Edit1.Common.SetRect 50,57,120,21
Select Case mode
Case 0
Edit1.Text = DiskSize
Case 1
Edit1.Text = FileSize
End Select
Dim Button1 : Set Button1 = SDB.UI.NewButton(Form1)
Button1.Cancel = True
Button1.Caption = "Cancel"
Button1.ModalResult = 2
Button1.Common.SetRect Form1.Common.Width-95,Form1.Common.Height-60,75,25
Dim Button2 : Set Button2 = SDB.UI.NewButton(Form1)
Button2.Caption = "Ok"
Button2.Default = True
Button2.ModalResult = 1
Button2.Common.SetRect Button1.Common.Left-85,Button1.Common.Top,75,25
'show confirmation
If Form1.ShowModal = 2 Then
Exit Sub
End If
If Edit1.Text = "" Or Int(Edit1.Text) = 0 Then
Call SDB.MessageBox("DiscSplitter: Size limit not specified or invalid.",mtError,Array(mbOk))
Exit Sub
End If
'save settings
mode = DropDown1.ItemIndex
ini.IntValue("DiscSplitter","Mode") = mode
Select Case mode
Case 0
DiskSize = Int(Edit1.Text)
ini.IntValue("DiscSplitter","Disk") = DiskSize
Case 1
FileSize = Int(Edit1.Text)
ini.IntValue("DiscSplitter","File") = FileSize
End Select
'check total length
Dim ds,ts
Select Case mode
Case 0
ds = DiskSize * 60
ts = dit.ValueByIndex(1) / 1000
Case 1
ds = FileSize * 1024
ts = dit.ValueByIndex(2) / 1024
End Select
If ds > ts Then
Call SDB.MessageBox("DiscSplitter: Selected node does not need to be split.",mtError,Array(mbOk))
Exit Sub
End If
'initialise
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim prog : Set prog = SDB.Progress
prog.Value = 0
prog.MaxValue = tot
prog.Text = "DiscSplitter: Initialising..."
Dim cds : cds = (ts\ds)+1
Dim num : num = 1
Dim val : val = 0
Dim fis : fis = 0
Dim fnf : fnf = 0
Dim rs : rs = ds
Dim nam : nam = Left(loc,Len(loc)-1)
nam = loc&Mid(nam,InStrRev(nam,"\"))&" "
'loop through tracks
Dim sql : sql = ""
Select Case mode
Case 0
sql = "SongLength"
Case 1
sql = "FileLength"
End Select
If SDB.VersionHi > 2 Then
sql = "SELECT Medias.DriveLetter, Songs.SongPath, Songs."&sql&" FROM Songs,Medias WHERE Songs.IDMedia = Medias.IDMedia AND Songs.SongPath LIKE '"&loc&"%' ORDER BY Songs.SongPath"
Else
sql = "SELECT Medias.DriveLetter, Songs.SongPath, Songs."&sql&" FROM Songs LEFT JOIN Medias ON Songs.IDMedia = Medias.IDMedia WHERE Songs.SongPath LIKE '"&loc&"%' ORDER BY Songs.SongPath"
End If
Set dit = SDB.Database.OpenSQL(sql)
While (Not dit.EOF) And (Not prog.Terminate)
'check song path
Dim sour : sour = Replace(dit.StringByIndex(1),loc,"")
If InStr(sour,"\") = 0 Then
'check file exists
sour = Chr(65+dit.ValueByIndex(0))&dit.StringByIndex(1)
If fso.FileExists(sour) Then
'check song length
Select Case mode
Case 0
val = dit.ValueByIndex(2)/1000
Case 1
val = dit.ValueByIndex(2)/1024
End Select
rs = rs-val
If Not (rs > 0) Then
num = num + 1
rs = ds-val
End If
'move file to folder
prog.Text = "DiscSplitter: Moving track "&(prog.Value+1)&"/"&(tot)&" to disc "&(num)&"/"&(cds)&"..."
Dim dest : dest = Chr(65+dit.ValueByIndex(0))&nam&num&"\"
If Not (fso.FolderExists(dest)) Then
Call fso.CreateFolder(dest)
End If
Call fso.MoveFile(sour,dest)
Else
prog.Text = "DiscSplitter: Skipping track "&(prog.Value+1)&"/"&(tot)&" (file not found)..."
fnf = fnf + 1
End If
Else
prog.Text = "DiscSplitter: Skipping track "&(prog.Value+1)&"/"&(tot)&" (file in subfolder)..."
fis = fis + 1
End If
'iterate
prog.Increase
dit.Next
WEnd
'final warnings
If Int(fnf+fis) = Int(tot) Then
If fnf = tot Then
Call SDB.MessageBox("DiscSplitter: No files could be found.",mtError,Array(mbOk))
Exit Sub
End If
If fis = tot Then
Call SDB.MessageBox("DiscSplitter: No files in selected folder.",mtError,Array(mbOk))
Exit Sub
End If
Call SDB.MessageBox("DiscSplitter: No files could be found in selected folder.",mtError,Array(mbOk))
End If
End Sub
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("DiscSplitter","Filename") = "DiscSplitter.vbs"
inif.StringValue("DiscSplitter","Procname") = "DiscSplitter"
inif.StringValue("DiscSplitter","Order") = "100"
inif.StringValue("DiscSplitter","DisplayName") = "&Disc Splitter"
inif.StringValue("DiscSplitter","Description") = "Split tracks into groups of disc size"
inif.StringValue("DiscSplitter","Language") = "VBScript"
inif.StringValue("DiscSplitter","ScriptType") = "0"
SDB.RefreshScriptItems
End If
End Sub
This is another script that has been designed by someone else and requested via my website. Firstly select a Location or My Computer node that you want to split into CD sized folders. Then select the script from the Tools menu and it will ask you to select the mode and size limit (song length in minutes or file length in megabytes). When you click "Ok" it will move the files into folders of the correct size.
The installer is available to download from my website! :)
[code]'
' MediaMonkey Script
'
' NAME: DiscSplitter 1.2
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 22/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
'
' [DiscSplitter]
' FileName=DiscSplitter.vbs
' ProcName=DiscSplitter
' Order=100
' DisplayName=&Disc Splitter
' Description=Split tracks into groups of disc size
' Language=VBScript
' ScriptType=0
'
' FIXES: Made compatible with MM3
' Added option to split by physical size
'
Option Explicit
Dim DiskSize : DiskSize = 80 'Default CD size in minutes
Dim FileSize : FileSize = 700 'Default CD size in megabytes
Sub DiscSplitter
'get current node
Dim cur : Set cur = SDB.MainTree.CurrentNode
If cur Is Nothing Then
Call SDB.MessageBox("DiscSplitter: No node is selected.",mtError,Array(mbOk))
Exit Sub
End If
'check node type
Dim loc : loc = ""
Select Case cur.NodeType
Case 64
loc = SDB.MainTree.CurrentNode.Path
Case 62
loc = Mid(SDB.MainTree.CurrentNode.Path,2)
Case Else
Call SDB.MessageBox("DiscSplitter: Selected node type ("&cur.NodeType&") is not suitable.",mtError,Array(mbOk))
Exit Sub
End Select
'check track count
Dim dit : Set dit = SDB.Database.OpenSQL("SELECT Count(*), Sum(Songs.SongLength), Sum(Songs.FileLength) FROM Songs WHERE Songs.SongPath LIKE '"&loc&"%'")
Dim tot : tot = dit.ValueByIndex(0)
If tot = 0 Then
Call SDB.MessageBox("DiscSplitter: Selected node contains no tracks.",mtError,Array(mbOk))
Exit Sub
End If
'get options
Dim ini : Set ini = SDB.IniFile
Dim mode : mode = ini.IntValue("DiscSplitter","Mode")
If Not (ini.StringValue("DiscSplitter","Disk") = "") Then
DiskSize = ini.IntValue("DiscSplitter","Disk")
End If
If Not (ini.StringValue("DiscSplitter","File") = "") Then
FileSize = ini.IntValue("DiscSplitter","File")
End If
'create confirmation
Dim Form1 : Set Form1 = SDB.UI.NewForm
Form1.BorderStyle = 3
Form1.Caption = "Disc Splitter"
Form1.FormPosition = 4
Form1.StayOnTop = True
Form1.Common.ControlName = "DiscSplitterForm"
Form1.Common.SetRect 0,0,200,150
Dim Label1 : Set Label1 = SDB.UI.NewLabel(Form1)
Label1.Common.SetRect 10,10,65,17
Label1.Caption = "Please select options..."
Dim Label2 : Set Label2 = SDB.UI.NewLabel(Form1)
Label2.Common.SetRect 10,35,65,17
Label2.Caption = "Mode:"
Dim Label3 : Set Label3 = SDB.UI.NewLabel(Form1)
Label3.Common.SetRect 10,60,65,17
Label3.Caption = "Size:"
Dim DropDown1 : Set DropDown1 = SDB.UI.NewDropDown(Form1)
DropDown1.Common.SetRect 50,32,120,21
DropDown1.AddItem("Disk size (mins)")
DropDown1.AddItem("File size (mb)")
DropDown1.ItemIndex = mode
DropDown1.Style = 2
Dim Edit1 : Set Edit1 = SDB.UI.NewEdit(Form1)
Edit1.Common.SetRect 50,57,120,21
Select Case mode
Case 0
Edit1.Text = DiskSize
Case 1
Edit1.Text = FileSize
End Select
Dim Button1 : Set Button1 = SDB.UI.NewButton(Form1)
Button1.Cancel = True
Button1.Caption = "Cancel"
Button1.ModalResult = 2
Button1.Common.SetRect Form1.Common.Width-95,Form1.Common.Height-60,75,25
Dim Button2 : Set Button2 = SDB.UI.NewButton(Form1)
Button2.Caption = "Ok"
Button2.Default = True
Button2.ModalResult = 1
Button2.Common.SetRect Button1.Common.Left-85,Button1.Common.Top,75,25
'show confirmation
If Form1.ShowModal = 2 Then
Exit Sub
End If
If Edit1.Text = "" Or Int(Edit1.Text) = 0 Then
Call SDB.MessageBox("DiscSplitter: Size limit not specified or invalid.",mtError,Array(mbOk))
Exit Sub
End If
'save settings
mode = DropDown1.ItemIndex
ini.IntValue("DiscSplitter","Mode") = mode
Select Case mode
Case 0
DiskSize = Int(Edit1.Text)
ini.IntValue("DiscSplitter","Disk") = DiskSize
Case 1
FileSize = Int(Edit1.Text)
ini.IntValue("DiscSplitter","File") = FileSize
End Select
'check total length
Dim ds,ts
Select Case mode
Case 0
ds = DiskSize * 60
ts = dit.ValueByIndex(1) / 1000
Case 1
ds = FileSize * 1024
ts = dit.ValueByIndex(2) / 1024
End Select
If ds > ts Then
Call SDB.MessageBox("DiscSplitter: Selected node does not need to be split.",mtError,Array(mbOk))
Exit Sub
End If
'initialise
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim prog : Set prog = SDB.Progress
prog.Value = 0
prog.MaxValue = tot
prog.Text = "DiscSplitter: Initialising..."
Dim cds : cds = (ts\ds)+1
Dim num : num = 1
Dim val : val = 0
Dim fis : fis = 0
Dim fnf : fnf = 0
Dim rs : rs = ds
Dim nam : nam = Left(loc,Len(loc)-1)
nam = loc&Mid(nam,InStrRev(nam,"\"))&" "
'loop through tracks
Dim sql : sql = ""
Select Case mode
Case 0
sql = "SongLength"
Case 1
sql = "FileLength"
End Select
If SDB.VersionHi > 2 Then
sql = "SELECT Medias.DriveLetter, Songs.SongPath, Songs."&sql&" FROM Songs,Medias WHERE Songs.IDMedia = Medias.IDMedia AND Songs.SongPath LIKE '"&loc&"%' ORDER BY Songs.SongPath"
Else
sql = "SELECT Medias.DriveLetter, Songs.SongPath, Songs."&sql&" FROM Songs LEFT JOIN Medias ON Songs.IDMedia = Medias.IDMedia WHERE Songs.SongPath LIKE '"&loc&"%' ORDER BY Songs.SongPath"
End If
Set dit = SDB.Database.OpenSQL(sql)
While (Not dit.EOF) And (Not prog.Terminate)
'check song path
Dim sour : sour = Replace(dit.StringByIndex(1),loc,"")
If InStr(sour,"\") = 0 Then
'check file exists
sour = Chr(65+dit.ValueByIndex(0))&dit.StringByIndex(1)
If fso.FileExists(sour) Then
'check song length
Select Case mode
Case 0
val = dit.ValueByIndex(2)/1000
Case 1
val = dit.ValueByIndex(2)/1024
End Select
rs = rs-val
If Not (rs > 0) Then
num = num + 1
rs = ds-val
End If
'move file to folder
prog.Text = "DiscSplitter: Moving track "&(prog.Value+1)&"/"&(tot)&" to disc "&(num)&"/"&(cds)&"..."
Dim dest : dest = Chr(65+dit.ValueByIndex(0))&nam&num&"\"
If Not (fso.FolderExists(dest)) Then
Call fso.CreateFolder(dest)
End If
Call fso.MoveFile(sour,dest)
Else
prog.Text = "DiscSplitter: Skipping track "&(prog.Value+1)&"/"&(tot)&" (file not found)..."
fnf = fnf + 1
End If
Else
prog.Text = "DiscSplitter: Skipping track "&(prog.Value+1)&"/"&(tot)&" (file in subfolder)..."
fis = fis + 1
End If
'iterate
prog.Increase
dit.Next
WEnd
'final warnings
If Int(fnf+fis) = Int(tot) Then
If fnf = tot Then
Call SDB.MessageBox("DiscSplitter: No files could be found.",mtError,Array(mbOk))
Exit Sub
End If
If fis = tot Then
Call SDB.MessageBox("DiscSplitter: No files in selected folder.",mtError,Array(mbOk))
Exit Sub
End If
Call SDB.MessageBox("DiscSplitter: No files could be found in selected folder.",mtError,Array(mbOk))
End If
End Sub
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("DiscSplitter","Filename") = "DiscSplitter.vbs"
inif.StringValue("DiscSplitter","Procname") = "DiscSplitter"
inif.StringValue("DiscSplitter","Order") = "100"
inif.StringValue("DiscSplitter","DisplayName") = "&Disc Splitter"
inif.StringValue("DiscSplitter","Description") = "Split tracks into groups of disc size"
inif.StringValue("DiscSplitter","Language") = "VBScript"
inif.StringValue("DiscSplitter","ScriptType") = "0"
SDB.RefreshScriptItems
End If
End Sub[/code]