Ver 1.2.1 (2008-02-18)
- Added SQL which removes redundant data in the ListsSongs table if it exists. This makes the script to work properly.
Enjoy!
/Bex
-----------------------------------------------------------------------------------
Script is updated
Ver 1.2 (2007-12-14)
- Added confirmation screen with unused "items" displayed and possibility to cancel the operation
The devs has said that "Delete unused genres" will be natively implemented in MM3 RC5 so I guess this script will be a bit redundant then.
Enjoy!
/Bex
-----------------------------------------------------------------------------------
Script is updated
- Converted Script to a separate MM3 Version
- Changed script so all Unused Genres are removed
- Added possibility to remove Unused Classifications
Please back up your database before you test the script. Let me know if it works as it should!
Enjoy!
/Bex
-------------------------------------------------------------------------------------
Code: Select all
' MediaMonkey Script
' NAME: Remove Unused... 1.2 (MM3 Only)
' AUTHOR: Bex
' DATE : 2007-12-12
'
'Manual Install:
' 1) Goto "Mediamonkey\Scripts\Auto" folder. Right click and create a txt file.
' 2) Name it RemoveUnused.vbs
' Make sure the icon is a VBS icon. i.e. the file isn't named RemoveUnused.vbs.txt
' To always display all filenames with extension in explorer, do this:
' a. In explorer, go to Tools->Folder Options->View Tab
' b. Uncheck "hide file extensions for known file types"
' 3) Copy all this content into the file and save it.
' 4) (Re)start MediaMonkey
'---------------------------------------------------------------------------------------
Sub OnStartup
' Add a menu entry to the File menu
Dim Mnu
Set Mnu = SDB.UI.AddMenuItemSub(SDB.UI.Menu_File, 1, 4)
Mnu.Caption = "Remove &Unused..."
Mnu.IconIndex = 21
Mnu.UseScript=Script.ScriptPath
Dim SubMnu
Set SubMnu = SDB.UI.AddMenuItem(Mnu, 1, 0)
SubMnu.Caption = "...&Genres"
SubMnu.OnClickFunc = "RemoveUnusedGenres"
'SubMnu.IconIndex = 58
SubMnu.UseScript=Script.ScriptPath
Set SubMnu = SDB.UI.AddMenuItem(Mnu, 1, 0)
SubMnu.Caption = "...&Tempos"
SubMnu.OnClickFunc = "RemoveUnusedTempos"
'SubMnu.IconIndex = 29
SubMnu.UseScript=Script.ScriptPath
Set SubMnu = SDB.UI.AddMenuItem(Mnu, 1, 0)
SubMnu.Caption = "...&Moods"
SubMnu.OnClickFunc = "RemoveUnusedMoods"
'SubMnu.IconIndex = 30
SubMnu.UseScript=Script.ScriptPath
Set SubMnu = SDB.UI.AddMenuItem(Mnu, 1, 0)
SubMnu.Caption = "...&Occasions"
SubMnu.OnClickFunc = "RemoveUnusedOccasions"
'SubMnu.IconIndex = 31
SubMnu.UseScript=Script.ScriptPath
Set SubMnu = SDB.UI.AddMenuItem(Mnu, 1, 0)
SubMnu.Caption = "...&Qualities"
SubMnu.OnClickFunc = "RemoveUnusedQualities"
'SubMnu.IconIndex = 32
SubMnu.UseScript=Script.ScriptPath
Set SubMnu = SDB.UI.AddMenuItem(Mnu, 1, 0)
SubMnu.Caption = "&All Above"
SubMnu.OnClickFunc = "RemoveAllAbove"
'SubMnu.IconIndex = 32
SubMnu.UseScript=Script.ScriptPath
End sub
Sub RemoveUnusedGenres(o)
Dim sql,Cnt,txt1,txt2,genres,YesNo,i,b
sql = "FROM Genres WHERE IDGenre NOT IN (SELECT DISTINCT IDGenre FROM GenresSongs)"
Cnt = SDB.Database.OpenSQL("SELECT COUNT(*) " & sql).ValueByIndex(0)
If Cnt = 0 Then
SDB.MessageBox "No Unused Genres Found.", mtInformation, Array(mbOK)
Exit Sub
Else
If Cnt = 1 Then
txt1 = "Genres"
txt2 = "it?"
Else
txt1 = "Genres"
txt2 = "them?"
End If
b = Round(Cnt/50)
Set iter = SDB.Database.OpenSQL("SELECT Genrename " & sql)
While Not iter.EOF
i=i+1
genres = genres & " - " & Iter.StringByIndex(0)
If b=i Then
genres = genres & vbNewLine
i=0
End If
iter.Next
WEnd
YesNo = SDB.MessageBox(Cnt & " Unused "& txt1 &" Found:" & vbNewLine & genres & vbNewLine &_
vbNewLine & "Do you wish to remove " & txt2, mtConfirmation, Array(mbYes,mbNo))
If Not (YesNo = mrYes) Then
Exit Sub
Else
SDB.Database.ExecSQL("DELETE " & sql)
End If
End If
End Sub
Sub RemoveUnusedTempos(o)
Call RemoveUnusedClassifications(1,"Tempo","Tempos")
End Sub
Sub RemoveUnusedMoods(o)
Call RemoveUnusedClassifications(2,"Mood","Moods")
End Sub
Sub RemoveUnusedOccasions(o)
Call RemoveUnusedClassifications(3,"Occasion","Occasions")
End Sub
Sub RemoveUnusedQualities(o)
Call RemoveUnusedClassifications(4,"Quality","Qualities")
End Sub
Sub RemoveUnusedClassifications(Classification,Sing,Plur)
Dim sql,sql1,sql2,sql3,Cnt,txt1,txt2,classi
sql = "FROM Lists WHERE IDListType="& Classification &" AND ID NOT IN (SELECT IDList FROM ListsSongs)"
Cnt = SDB.Database.OpenSQL("SELECT COUNT(*) " & sql).ValueByIndex(0)
If Cnt = 1 Then
txt1 = Sing
txt2 = "it?"
Else
txt1 = Plur
txt2 = "them?"
End If
If Cnt = 0 Then
SDB.MessageBox "No Unused "& txt1 &" Found.", mtInformation, Array(mbOK)
Exit Sub
Else
Set iter = SDB.Database.OpenSQL("SELECT TextData " & sql)
While Not iter.EOF
classi = classi & vbNewLine & " - " & Iter.StringByIndex(0)
iter.Next
WEnd
YesNo = SDB.MessageBox(Cnt & " Unused "& txt1 &" Found:" & vbNewLine & classi & vbNewLine &_
vbNewLine & "Do you wish to remove " & txt2, mtConfirmation, Array(mbYes,mbNo))
If Not (YesNo = mrYes) Then
Exit Sub
Else
SDB.Database.ExecSQL("DELETE " & sql)
End If
End If
End Sub
Sub RemoveAllAbove(o)
Dim sqlg,sqlc,Cnt,msg,txt1,txt2,genres,YesNo,classi,NoFound,c,i
sqlg = "FROM Genres WHERE IDGenre NOT IN (SELECT DISTINCT IDGenre FROM GenresSongs)"
Cnt = SDB.Database.OpenSQL("SELECT COUNT(*) " & sqlg).ValueByIndex(0)
If Cnt = 0 Then
msg = "No Unused Genres Found." & vbNewLine & vbNewLine
NoFound = 1
Else
If Cnt = 1 Then
txt1 = "Genre"
c=c+1
Else
txt1 = "Genres"
c=2
End If
Set iter = SDB.Database.OpenSQL("SELECT Genrename " & sqlg)
While Not iter.EOF
genres = genres & " - " & Iter.StringByIndex(0)
iter.Next
WEnd
msg = Cnt & " Unused "& txt1 &" Found:" & vbNewLine & genres & vbNewLine & vbNewLine
End If
For i = 1 to 4
sqlc = "FROM Lists WHERE IDListType="& i &" AND ID NOT IN (SELECT IDList FROM ListsSongs)"
Cnt = SDB.Database.OpenSQL("SELECT COUNT(*) " & sqlc).ValueByIndex(0)
Select Case i
Case 1
If Cnt = 1 Then
txt1 = "Tempo"
c=c+1
Else
txt1 = "Tempos"
c=2
End If
Case 2
If Cnt = 1 Then
txt1 = "Mood"
c=c+1
Else
txt1 = "Moods"
c=2
End If
Case 3
If Cnt = 1 Then
txt1 = "Occasion"
c=c+1
Else
txt1 = "Occasions"
c=2
End If
Case 4
If Cnt = 1 Then
txt1 = "Quality"
c=c+1
Else
txt1 = "Qualities"
c=2
End If
End Select
If Cnt = 0 Then
msg = msg & "No Unused "& txt1 &" Found." & vbNewLine & vbNewLine
NoFound = NoFound + 1
Else
Set iter = SDB.Database.OpenSQL("SELECT TextData " & sqlc)
While Not iter.EOF
classi = classi & " - " & Iter.StringByIndex(0)
iter.Next
WEnd
msg = msg & Cnt & " Unused "& txt1 &" Found:" & vbNewLine & classi & vbNewLine & vbNewLine
End If
Next
If NoFound = 5 Then
SDB.MessageBox msg, mtInformation, Array(mbOK)
Else
If c = 1 Then txt2 = "it?" Else txt2 = "them?"
msg = msg & vbNewLine & "Do You wish to remove " & txt2
YesNo = SDB.MessageBox(msg, mtConfirmation, Array(mbYes,mbNo))
If Not (YesNo = mrYes) Then
Exit Sub
Else
SDB.Database.ExecSQL("DELETE " & sqlg)
SDB.Database.ExecSQL("DELETE FROM Lists WHERE ID NOT IN (SELECT IDList FROM ListsSongs)")
End If
End If
End Sub
Download:
Latest version:
MM3 (Installer)
http://www.mediafire.com/?rfb5gbkfhd4trzp
Installation Instructions:
- New Install or upgrade:
MM3 (Installer)
Avoid "Product installation error"
- Vista Users:
- - To be able to install scripts you must Run MM as an administrator.
- - It means that you must right click the MM icon and select "Run as administrator" even if you are logged in as an administrator.
- All Users:
- - Check in your task manager that you only have one instance of MediaMonkey.exe running.
1. Download the file and double click on it.
2. Goto File->Remove Unused... To run the script