Page 1 of 5

Remove Unused Genres/Classification 1.2.1 (2008-02-18)

Posted: Fri Jun 22, 2007 6:53 am
by Bex
Script is updated
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

Posted: Fri Jun 22, 2007 4:26 pm
by Eyal
I thought that custom genres listed were already only those used.
Once there is no more tracks with a certain genre, the genre is automatically
removed from the list when you close and re-open MM.

Re: Remove Unused Genres 1.0 [Script] (2007-06-22)

Posted: Fri Jun 22, 2007 4:37 pm
by Teknojnky
Bex wrote: 3. Goto FILE->Remove Unused Genres, to run the script.

Fixed #3 for ya :)

Posted: Mon Jul 02, 2007 8:33 am
by snacks
Hey - love the script, was just about to write a thread asking how to remove unused genres, I have about 50... however, I can't seem to get the script to work. It appears in the "file" as "remove unused genres" as advertised but when I click on it I get a message "no unused genres." Any idea as to why it's not recognizing my unused genres? I'm using Alpha 5, could this be it? Thanks in advance for any help.
Snacks

Posted: Mon Jul 02, 2007 9:16 am
by trixmoto
Yes, the database structure has changed for MM3, so this script is probably MM2 only.

Posted: Mon Jul 02, 2007 9:39 am
by snacks
Thanks - I thought this might be the case. Do you know of any other way to removed unwanted/unused genres from the drop down menu?

Posted: Mon Jul 02, 2007 10:50 am
by Bex
Since the devs have said that MM3 allows you to delete the built in genres, I'll see what I can do.

Posted: Mon Jul 02, 2007 10:53 am
by snacks
Thanks Bex, I really appreciate it!

Posted: Tue Dec 11, 2007 11:56 pm
by 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

Posted: Wed Dec 12, 2007 12:11 am
by nohitter151
Wow! I just tried it and it found 137 unused Genre's. Who knew?? :lol:

Posted: Wed Dec 12, 2007 3:44 pm
by Randall_Lind
I love it but, I would like to see it show the list of genres before it is removed on an updated version if possible.

I ran it and it removed 38 unused genres but I have no clue what they were.

Posted: Wed Dec 12, 2007 3:53 pm
by onkel_enno
Thanks a lot Bex!

Posted: Wed Dec 12, 2007 4:40 pm
by MusicBringer
Randall_Lind wrote:I love it but, I would like to see it show the list of genres before it is removed on an updated version if possible.

I ran it and it removed 38 unused genres but I have no clue what they were.
Yeah I have to agree. That was my feeling too. A bit uncertain what had been taken away. This version is great, and a report in the next version would be wonderful.

Posted: Wed Dec 12, 2007 4:55 pm
by snacks
Bex, thanks for all the hard work - and I hate to be a pain in the ass, but for some reason I can't install it - I get an error, "Product Installation Error." I'm using Vista and MMRC4, could that have anything to do with it?
Thanks again,
Cory

Posted: Thu Dec 13, 2007 12:03 am
by nohitter151
Installing a MediaMonkey 3.0 extension sometimes results in: "Product installation error." This occurs on Vista systems when the user attempting to install the extension does not have Administrative rights.

To get around this, log in with Administrative rights, run MediaMonkey, and then attempt to install the Extension.

(From the FAQ: http://www.mediamonkey.com/faq/index.ph ... artlang=en)