Fix Trailing The 3.4 [MM2+3]

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Fix Trailing The 3.4 [MM2+3]

Post by trixmoto » Thu Nov 03, 2005 7:14 am

Here is a script which fixes, well, here's an example: "Beatles, The" -> "The Beatles". It doesn't care about case or anything and shows a confirmation box of all the changes so you can confirm. This script can be downloaded from my website.

AMMENDMENT: New version posted below! :)
Last edited by trixmoto on Tue May 08, 2007 12:36 pm, edited 7 times in total.
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.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

rovingcowboy
Posts: 14153
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy » Thu Nov 03, 2005 7:49 am

if i get this my sister will have a very large dislike of you.

because she likes the in the end of the band names.

i don't so i like this script :lol: 8)
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy 5 Android 5) 6. Proscan tablet Android 4.3 ) 7. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.

psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova » Fri Nov 04, 2005 9:54 am

Nice!!! very very usefull

Thanks Trix!!

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Fri Nov 04, 2005 10:19 am

Here is a new version of the script. It allows you to add a list of words which is useful for international users. The list is currently: "The", "Der", "Die", "Das" - the fewer words you have the faster it processes so please remove those you do not wish to use.

:o :D :o NEW CODE BELOW :o :D :o
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.
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
Contact:

Post by trixmoto » Tue Nov 22, 2005 5:02 am

This new version of the code has been fixed for MM2.5 (whilst still working in MM2.4):

:o NEW CODE BELOW :o
Last edited by trixmoto on Thu Mar 23, 2006 4:47 am, edited 1 time in total.
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.
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
Contact:

Post by trixmoto » Wed Jan 04, 2006 6:59 am

The opposite of this script is available here: http://www.mediamonkey.com/forum/viewtopic.php?t=6940
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.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

JhotIII
Posts: 21
Joined: Thu Dec 01, 2005 2:33 pm

Post by JhotIII » Wed Mar 22, 2006 9:40 am

Hi trixie
I love your scripts. This one would be fine, because I have been making "beatles, the" all over.
However. It only changes artists, and not album artist. It says it will do this, and then it appears that it does, and then after a short while, the album artist changes back to "beatles, the" again. I was suspecting "read only attribute" to be the cause of the problem, but I have tried to set that of.
Migth there be a bug. I have not tried to read You code thouroughly, but I have 3.1 version of it.[/img]

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Wed Mar 22, 2006 9:50 am

Have you tried Ctrl+S to save the changes to the files? I think someone else was having this problem but I asked for more info and they never replied.
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.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

JhotIII
Posts: 21
Joined: Thu Dec 01, 2005 2:33 pm

Post by JhotIII » Wed Mar 22, 2006 12:27 pm

Yepp. I have both tried ctrl-s and synchronise tags (which is the same thing, I can see now), and it does not help. I have tried another script (PersonalTagEnhancer) from steege, and enhanced that to update itm.albumArtistName and get the same result. It appears to do the update, but it reverts almost instantly.
If I do a normal update using properties, everything is ok. I suspect it must be something with albumArtistName scripting, or my installation is fucked up.
I could try a clean install...... yeah I can do that on another machine, and get back to you in a sec. It cannot be Your script.... since it behaves the same way in another script.

JhotIII
Posts: 21
Joined: Thu Dec 01, 2005 2:33 pm

Post by JhotIII » Wed Mar 22, 2006 12:40 pm

ok so i have tried a clean install of mm and fixtrailingthe.vbs on another machine. same result. if i switch to another node, and back, the artist field is updated, but album artist is not. strange.....

JhotIII
Posts: 21
Joined: Thu Dec 01, 2005 2:33 pm

Post by JhotIII » Wed Mar 22, 2006 1:35 pm

Fiddling around a bit I have found that calling itm.UpdateAlbum fixed this issue in the PersonalTagEnhancer script, but I cannot see that You use these methods (UpdateArtist or UpdateDB) in Your script. I do not want to mess around with your script so I will leave it up to you. If you can reproduce the error I'm sure You can add the necessary update sql statements. If it is not reproducable then i'm very puzzeled, because then it must have something to do with the settings. I have tried both id v3.1 & v3.2 tags, and it does not affect anything. I have also tried ctrl-s.
After the script has executed the album artist field is updated.
when changing focus to another node (or simply another album or artist), and then back again, it reverts to the previous value.
thanks Joern

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Thu Mar 23, 2006 4:44 am

Well itm.UpdateDB is on line 161, and should update everything (UpdateArtist and UpdateAlbum should not be necessary) - however I will add these statements and see if this fixes your problem.
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.
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
Contact:

Post by trixmoto » Thu Mar 23, 2006 4:48 am

New version (3.2) should have fixed the problem with album artist not updating properly.

Code: Select all

'
' MediaMonkey Script
'
' NAME: FixTrailingThe 3.2
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 23/03/2006
'
' Form copied from "TitleCase.vbs", March-22-2004, v1.0, written by Risser 
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' FIXES: Adding extra updates because album artist is not updating properly
'
' [FixTrailingThe]
' FileName=FixTrailingThe.vbs
' ProcName=FixTrailingThe
' Order=7
' DisplayName=Fix Trailing The
' Description="Beatles, The" -> "The Beatles"
' Language=VBScript
' ScriptType=0 
'

Option Explicit 

Dim theList(3)		'this number must match the largest item number
theList(0) = "The"	'add more lines like this one for more words
theList(1) = "Der"	'the fewer words you have the faster it will process
theList(2) = "Die"
theList(3) = "Das"


Public holdArtist, holdAlbum, holdTitle, holdAlbumArtist 
Set holdArtist = CreateObject("Scripting.Dictionary") 
Set holdAlbum = CreateObject("Scripting.Dictionary") 
Set holdTitle = CreateObject("Scripting.Dictionary") 
Set holdAlbumArtist = CreateObject("Scripting.Dictionary") 

Const mmAnchorRight = 4 
Const mmAnchorBottom = 8 
Const mmAlignTop = 1 
Const mmAlignBottom = 2 
Const mmAlignClient = 5 
Const mmListDropdown = 2 
Const mmFormScreenCenter = 4 
Public styleOn 

Function Style() 
  styleOn = Not styleOn 
  If styleOn Then 
    Style = "" 
  Else 
    Style = " class=""Dark""" 
  End If 
End Function 

Function rdQS(UnquotedString) 
  rdQS = "'" & Replace(UnquotedString, "'", "''") & "'" 
End Function 

Function fixThe(s) 
   Dim result,txt1,txt2,word,i,wlen
   result = s 

   For i=0 to UBound(theList)
     word = theList(i)
     wlen = len(word)+2
     txt1 = UCase(Right(s,wlen))
     txt2 = ", "&UCase(word)
     If txt1 = txt2 Then 
       result = word&" "&Mid(s,1,len(s)-wlen)
       Exit For
     End If
   Next

   fixThe = result 
End Function 

Sub CloseDown 
   Set holdAlbum = nothing 
   Set holdAlbumArtist = nothing 
   Set holdArtist = nothing 
   Set holdTitle = nothing 
   SDB.Objects("TheThingy") = Nothing 
   SDB.Objects("holdArtist") = Nothing 
   SDB.Objects("holdAlbumArtist") = Nothing 
   SDB.Objects("holdAlbum") = Nothing 
   SDB.Objects("holdTitle") = Nothing 
End Sub 

Sub OnCancel(Btn) 
   CloseDown 
End Sub 

Sub OnOK(Btn) 
   Set holdAlbum = SDB.Objects("holdAlbum") 
   Set holdAlbumArtist = SDB.Objects("holdAlbumArtist") 
   Set holdArtist = SDB.Objects("holdArtist") 
   Set holdTitle = SDB.Objects("holdTitle") 

   Dim itm, str, sql 
   Dim items, albumNames, artistNames 
   Set items = CreateObject("Scripting.Dictionary") 
   Set albumNames = CreateObject("Scripting.Dictionary") 
   Set artistNames = CreateObject("Scripting.Dictionary") 

   For Each itm In holdArtist 
      str = holdArtist.item(itm) 
      If Not items.exists(itm) Then 
         items.add itm, itm 
      End If 
      itm.artistName = str 
      If Not artistNames.exists(str) Then 
         sql = "UPDATE Artists SET Artists.Artist = " & rdQS(str) & " WHERE Artists.Artist= " & rdQS(Itm.ArtistName) 
         SDB.database.execSQL(sql) 
         ' This will affect ALL instances of this artist, including album artist, and on other tracks. 
         artistNames.add str, str 
      End If 
   Next 'itm 
    
   For Each itm In holdAlbumArtist 
      str = holdAlbumArtist.item(itm) 
      If Not items.exists(itm) Then 
         items.add itm, itm 
      End If 
      itm.albumArtistName = str 
      If Not artistNames.exists(str) Then 
         sql = "UPDATE Artists SET Artists.Artist = " & rdQS(str) & " WHERE Artists.Artist= " & rdQS(Itm.ArtistName) 
         SDB.database.execSQL(sql) 
         artistNames.add str, str 
      End If 
   Next 'itm 
    
   For Each itm In holdAlbum 
      str = holdAlbum.item(itm) 
      If Not items.exists(itm) Then 
         items.add itm, itm 
      End If 
      itm.albumName = str 
      If Not albumNames.exists(str) Then 
         sql = "UPDATE Albums SET Albums.Album = " & rdQS(str) & " WHERE Albums.Album= " & rdQS(Itm.AlbumName) 
         SDB.database.execSQL(sql) 
         ' This will affect ALL instances of this album, including other tracks. 
         albumNames.add str, str 
      End If 
   Next 'itm 
    
   For Each itm In holdTitle 
      str = holdTitle.item(itm) 
      If Not items.exists(itm) Then 
         items.add itm, itm 
      End If 
      itm.title = str 
   Next 'itm 
    
   For Each itm In items 
      If itm.ID>-1 Then 
         itm.UpdateArtist
         itm.UpdateAlbum
         itm.UpdateDB 
         itm.WriteTags
      End If 
   Next 'itm    
    
   Set items = nothing 
   CloseDown 
End Sub 

Function MapXML(original) 
   Dim hold 
   hold = Replace(original, "&", "&") 
   hold = Replace(hold, "  ", "  ") 
   hold = Replace(hold, "<", "<") 
   hold = Replace(hold, ">", ">") 
   Dim i 
   i=1 
   While i<=Len(hold) 
      If (AscW(Mid(hold, i, 1))>127) Then 
         hold = Mid(hold, 1, i-1)+"&#"+CStr(AscW(Mid(hold, i, 1)))+";"+Mid(hold, i+1) 
      End If 
      i=i+1 
   WEnd 
   MapXML = hold 
End Function 

Function outField (fixed, normal) 
   If fixed = normal Then 
      outField = "<td>" & MapXML(normal) & "</td>" & vbcrlf 
   Else 
      outField = "<td class=""highlight"">" & MapXML(fixed) & "</td>" & vbcrlf 
   End If 
End Function 


Sub FixTrailingThe 
   Dim UI, Form, Foot, Btn, Btn2, WB, doc 
    
   Dim trackList 
   Dim writeChanges 

   Set trackList = SDB.SelectedSongList 
   If trackList.count=0 Then 
      Set trackList = SDB.AllVisibleSongList 
   End If 

   If trackList.count=0 Then 
      res = SDB.MessageBox("Select tracks to be updated", mtError, Array(mbOk)) 
      Exit Sub 
   End If 


   Set UI = SDB.UI 

   ' Create the window to be shown 
   Set Form = UI.NewForm 
   Form.Common.SetRect 50, 50, 500, 400 
   Form.Common.MinWidth = 200 
   Form.Common.MinHeight = 150 
   Form.FormPosition = mmFormScreenCenter 
   Form.SavePositionName = "TheWindow" 
   Form.Caption = SDB.Localize("Fix Trailing The") 
   Form.StayOnTop = True 

   ' Create a web browser component 
   Set WB = UI.NewActiveX(Form, "Shell.Explorer") 
   WB.Common.Align = mmAlignClient      ' Fill all client rectangle 
   WB.Common.ControlName = "WB" 
   If SDB.VersionHi=2 and SDB.VersionLo<5 Then WB.Interf.Navigate "about:"
   Set doc = WB.Interf.Document

   ' Create a panel at the bottom of the window 
   Set Foot = UI.NewPanel(Form) 
   Foot.Common.Align = mmAlignBottom 
   Foot.Common.Height = 35 

   ' Create a button that closes the window 
   Set Btn = UI.NewButton(Foot) 
   Btn.Caption = SDB.Localize("&Cancel") 
   Btn.Common.SetRect (Foot.Common.Width - 180)/2+95, 9, 85, 24 
   Btn.Common.Anchors = mmAnchorRight + mmAnchorBottom 
   Btn.UseScript = Script.ScriptPath 
   Btn.OnClickFunc = "OnCancel" 

   ' Create a button that saves the report 
   Set Btn2 = UI.NewButton(Foot) 
   Btn2.Caption = SDB.Localize("&OK")  
   Btn2.Common.SetRect (Foot.Common.Width - 180)/2, 9, 85, 24 
   Btn2.Common.Anchors = mmAnchorRight + mmAnchorBottom 
   Btn2.UseScript = Script.ScriptPath 
   Btn2.OnClickFunc = "OnOK"  

   Form.Common.Visible = True                ' Only show the form, don't wait for user input 
   SDB.Objects("TheThingy") = Form  ' Save reference to the form somewhere, otherwise it would simply disappear 


   doc.write "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbcrlf 
   doc.write "<html>" & vbcrlf 
   doc.write "  <head>" & vbcrlf 
   doc.write "    <title>" & SDB.Localize("Fix Trailing The") & "</title>" & vbcrlf 
   doc.write "  </head>" & vbcrlf 

   doc.write "<STYLE TYPE=text/css>" & vbcrlf 
   doc.write "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}" & vbcrlf 
   doc.write "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-align:left}" & vbcrlf 
   doc.write "P{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000;}" & vbcrlf 
   doc.write "TH{font-family:'Verdana',sans-serif; font-size:9pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}" & vbcrlf 
   doc.write "TD{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}" & vbcrlf 
   doc.write "TD.highlight{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFF77; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}" & vbcrlf 
   doc.write "TR.dark{background-color:#EEEEEE}" & vbcrlf 
   doc.write "TR.aleft TH{text-align:left}" & vbcrlf 
   doc.write "</STYLE>" & vbcrlf 

   doc.write "  <body>" & vbcrlf 
   doc.write "    <H1>" & SDB.Localize("Fix Trailing The:") & "</H1>" & vbcrlf 
   doc.write "    <table border=""0"" cellspacing=""0"" cellpadding=""4"" width=""100%"">" & vbcrlf  
   doc.write "      <tr class=""aleft"">" & vbcrlf 
   doc.write "        <th>" & SDB.Localize("Artist") & "</th>" & vbcrlf 
   doc.write "        <th>" & SDB.Localize("Title") & "</th>" & vbcrlf 
   doc.write "        <th>" & SDB.Localize("Album") & "</th>" & vbcrlf 
   doc.write "        <th>" & SDB.Localize("Album Artist") & "</th>" & vbcrlf 
   doc.write "      </tr>" & vbcrlf 

   Dim i, itm 
   Dim artist, album, title, albumArtist 
   for i=0 to trackList.count-1 
      doc.write "      <tr" & Style() & ">" & vbcrlf 

      Set itm = trackList.Item(i) 
      artist = fixThe(itm.artistName) 
      title = fixThe(itm.title) 
      album = fixThe(itm.albumName) 
      albumArtist = fixThe(itm.albumArtistName) 
       
      doc.write outField(artist, itm.artistName) 
      doc.write outField(title, itm.title) 
      doc.write outField(album, itm.albumName) 
      doc.write outField(albumArtist, itm.albumArtistName) 
      If artist <> "" And artist <> itm.artistName Then 
         holdArtist.add itm, artist 
      End If 
      If albumArtist <> "" And albumArtist <> itm.albumArtistName Then 
         holdAlbumArtist.add itm, albumArtist 
      End If 
      If title <> "" And title <> itm.title Then 
         holdTitle.add itm, title 
      End If 
      If album <> "" And album <> itm.albumName Then 
         holdAlbum.add itm, album 
      End If 
      doc.write "      </tr>" & vbcrlf 
       
   next 'i 
    
   doc.write "    </table>" & vbcrlf 
   doc.write "  </body>" & vbcrlf 
   doc.write "</html>" & vbcrlf 
   doc.close 
   SDB.Objects("holdArtist") = holdArtist 
   SDB.Objects("holdAlbumArtist") = holdAlbumArtist 
   SDB.Objects("holdAlbum") = holdAlbum 
   SDB.Objects("holdTitle") = holdTitle 
End Sub 
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.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

JhotIII
Posts: 21
Joined: Thu Dec 01, 2005 2:33 pm

Post by JhotIII » Thu Mar 23, 2006 5:29 am

Thx. Works great. Jorn

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Thu Mar 23, 2006 7:46 am

Glad that's sorted it! :)
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.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

Post Reply