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

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

Moderators: Peke, Gurus

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

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

Post 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
Last edited by Bex on Sat Feb 07, 2009 10:10 am, edited 12 times in total.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Eyal
Posts: 3116
Joined: Sun Jun 26, 2005 9:27 am
Location: Québec

Post 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.
Last edited by Eyal on Fri Jun 22, 2007 6:41 pm, edited 2 times in total.
Skins for MediaMonkey: Cafe, Carbon, Helium, Spotify, Zekton. [ Wiki Zone ].
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

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

Post by Teknojnky »

Bex wrote: 3. Goto FILE->Remove Unused Genres, to run the script.

Fixed #3 for ya :)
snacks
Posts: 89
Joined: Sun Jan 14, 2007 6:37 pm

Post 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
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Yes, the database structure has changed for MM3, so this script is probably MM2 only.
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.
snacks
Posts: 89
Joined: Sun Jan 14, 2007 6:37 pm

Post 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?
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Since the devs have said that MM3 allows you to delete the built in genres, I'll see what I can do.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
snacks
Posts: 89
Joined: Sun Jan 14, 2007 6:37 pm

Post by snacks »

Thanks Bex, I really appreciate it!
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post 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
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
nohitter151
Posts: 23640
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA
Contact:

Post by nohitter151 »

Wow! I just tried it and it found 137 unused Genre's. Who knew?? :lol:
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?

Please no PMs in reply to a post. Just reply in the thread.
Randall_Lind
Posts: 134
Joined: Sat Jul 29, 2006 11:17 am

Post 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.
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

Thanks a lot Bex!
MusicBringer
Posts: 622
Joined: Wed Oct 25, 2006 12:53 pm

Post 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.
snacks
Posts: 89
Joined: Sun Jan 14, 2007 6:37 pm

Post 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
nohitter151
Posts: 23640
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA
Contact:

Post 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)
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?

Please no PMs in reply to a post. Just reply in the thread.
Post Reply