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

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

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

Postby Bex » Fri Jun 22, 2007 6:53 am

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

Postby Eyal » Fri Jun 22, 2007 4:26 pm

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 ].
Eyal
 
Posts: 3099
Joined: Sun Jun 26, 2005 9:27 am
Location: Québec

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

Postby Teknojnky » Fri Jun 22, 2007 4:37 pm

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



Fixed #3 for ya :)
Teknojnky
 
Posts: 5521
Joined: Tue Sep 06, 2005 11:01 pm

Postby snacks » Mon Jul 02, 2007 8:33 am

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

Postby trixmoto » Mon Jul 02, 2007 9:16 am

Yes, the database structure has changed for MM3, so this script is probably MM2 only.
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Postby snacks » Mon Jul 02, 2007 9:39 am

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

Postby Bex » Mon Jul 02, 2007 10:50 am

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

Postby snacks » Mon Jul 02, 2007 10:53 am

Thanks Bex, I really appreciate it!
snacks
 
Posts: 89
Joined: Sun Jan 14, 2007 6:37 pm

Postby Bex » Tue Dec 11, 2007 11:56 pm

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

Postby nohitter151 » Wed Dec 12, 2007 12:11 am

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

Postby Randall_Lind » Wed Dec 12, 2007 3:44 pm

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.
Randall_Lind
 
Posts: 133
Joined: Sat Jul 29, 2006 11:17 am

Postby onkel_enno » Wed Dec 12, 2007 3:53 pm

Thanks a lot Bex!
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx
onkel_enno
 
Posts: 2145
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany

Postby MusicBringer » Wed Dec 12, 2007 4:40 pm

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.
MusicBringer
 
Posts: 622
Joined: Wed Oct 25, 2006 12:53 pm

Postby snacks » Wed Dec 12, 2007 4:55 pm

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

Postby nohitter151 » Thu Dec 13, 2007 12:03 am

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

Next

Return to Need Help with Addons?

Who is online

Users browsing this forum: No registered users and 21 guests