Make Trailing The 2.1 [MM2+3]

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Make Trailing The 2.1 [MM2+3]

Postby trixmoto » Wed Dec 14, 2005 11:24 am

As requested, I have written a script which does the exact opposite of my "Fix Trailing The" script. Therefore it will convert "The Beatles" into "Beatles, The". This is multilingual (editable by the list at the top of the script) and shows a confirmation screen before any changes are made.

Code: Select all
'
' MediaMonkey Script
'
' NAME: MakeTrailingThe 2.1
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 12/11/2007
'
' 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: Fixed SQL used to update artist instead of scripting methods
'
' [MakeTrailingThe]
' FileName=MakeTrailingThe.vbs
' ProcName=MakeTrailingThe
' Order=7
' DisplayName=Make Trailing The
' Description="The Beatles" -> "Beatles, The"
' 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, holdAlbumArtist
Set holdArtist = 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)+1
     txt1 = UCase(Left(s,wlen))
     txt2 = UCase(word)&" "
     If txt1 = txt2 Then
       result = Mid(s,wlen+1)&", "&word
       Exit For
     End If
   Next

   fixThe = result
End Function

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

Sub OnCancel(Btn)
   CloseDown
End Sub

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

   Dim itm, str, sql
   Dim items, artistNames
   Set items = 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 
         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
         artistNames.add str, str
      End If
   Next 'itm
   
   Dim list : Set list = SDB.NewSongList
   For Each itm In items
      If itm.ID>-1 Then
         itm.UpdateArtist
         itm.UpdateAlbum
         list.Add(itm)
      End If
   Next 'itm   
   list.UpdateAll   
   
   Set items = nothing
   CloseDown
End Sub

Function MapXML(original)
   Dim hold
   hold = Replace(original, "&", "&")
   hold = Replace(hold, "  ", "  ")
   hold = Replace(hold, "<", "&lt;")
   hold = Replace(hold, ">", "&gt;")
   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 MakeTrailingThe
   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("Make 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("Make 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("Make 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("Album Artist") & "</th>" & vbcrlf
   doc.write "      </tr>" & vbcrlf

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

      Set itm = trackList.Item(i)
      artist = fixThe(itm.artistName)
      albumArtist = fixThe(itm.albumArtistName)
       
      doc.write outField(artist, itm.artistName)
      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
      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
End Sub

Sub Install()
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("MakeTrailingThe","Filename") = "MakeTrailingThe.vbs"
    inif.StringValue("MakeTrailingThe","Procname") = "MakeTrailingThe"
    inif.StringValue("MakeTrailingThe","Order") = "7"
    inif.StringValue("MakeTrailingThe","DisplayName") = "Make Trailing The"
    inif.StringValue("MakeTrailingThe","Description") = "The Beatles -> Beatles, The"
    inif.StringValue("MakeTrailingThe","Language") = "VBScript"
    inif.StringValue("MakeTrailingThe","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Last edited by trixmoto on Mon Nov 12, 2007 11:27 am, edited 2 times in total.
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: Hull, UK

Postby trixmoto » Wed Dec 14, 2005 3:48 pm

Version 2.0 - this does not affect Title and Album (only Artist and Album Artist).
Last edited by trixmoto on Mon Nov 12, 2007 11:28 am, edited 1 time in total.
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: Hull, UK

Postby Scott N » Wed Dec 14, 2005 4:12 pm

Hi Rik, this rocks! thank you so much for making the code change you have saved me a ton of time for all of those one hit wonders from the 50s-70s that all start with "The"
Scott N
 

Postby trixmoto » Wed Jan 04, 2006 6:59 am

The opposite of this script is available here: http://www.mediamonkey.com/forum/viewtopic.php?t=6319
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: Hull, UK

Postby Sammy20 » Tue Jan 31, 2006 7:56 pm

Just tried to use this script.

It poped up alright, but when I pressed OK. I got error at line number 129

Do you think its a magic nodes conflict?

I'm using MM 2.51


Edit: The error is displayed as:

MakeTrailingThe.vbs Line:129, Column:9
Sammy20
 
Posts: 110
Joined: Thu Feb 17, 2005 5:42 am

Postby trixmoto » Wed Feb 01, 2006 5:28 am

The offending line is
Code: Select all
itm.UpdateDB
so I really don't understand what the error is. Can you email me a screenshot?
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: Hull, UK

Postby Sammy20 » Wed Feb 01, 2006 9:41 am

Just emailed you a screen shot of the error.
Sammy20
 
Posts: 110
Joined: Thu Feb 17, 2005 5:42 am

Postby Sammy20 » Wed Feb 01, 2006 12:59 pm

Ok, it's fixed now.

I just switched off the 'override skin with windows theme' option, and now it works without a hitch.

Thank you.
Sammy20
 
Posts: 110
Joined: Thu Feb 17, 2005 5:42 am

Postby trixmoto » Wed Feb 01, 2006 1:16 pm

Well I said (in my email response) that it wasn't something directly to with the script, but I was expecting it to be more closely linked than that! Very strange, but I'm glad you've got it working now. :)
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: Hull, UK

Postby jefftucker » Thu Aug 16, 2007 2:31 pm

This is exactly what I'm looking for, only I need something that will work with albums as well. For example I want to turn "The Empire Strikes Back" into "Empire Strikes Back, The."

Is there a script that has this functionality, or am I out of luck?
jefftucker
 
Posts: 1
Joined: Thu Aug 16, 2007 1:48 pm

Postby trixmoto » Mon Aug 20, 2007 10:52 am

No, but if you did a global replace of "AlbumArtist" with "Album" in the script file, then I think that would do the trick. :)
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: Hull, UK

Postby cadmanmeg » Wed Aug 22, 2007 1:12 am

Is there a simple way to edit this script so that it always fixesa the "the" issue with folders and sub folders? I know it can be as simple as the rename function for one folder, but then what if you want to do multiple folders and subfolders? While typing this I thought to myself, how will this work across several folders by different artist? So is it possible? I think that would be a great addition and improvement! Thanks much for yet another fine script!
cadmanmeg
 
Posts: 309
Joined: Sun Nov 19, 2006 5:28 am

Postby trixmoto » Wed Aug 22, 2007 3:30 am

If you want to change folders you can use MM's auto-organise feature.
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: Hull, UK

Postby trixmoto » Mon Nov 12, 2007 11:29 am

New version (2.1) is now available to download from my website. It's been updated for MM3 so there is now an installation package too. :)
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: Hull, UK

Re: Make Trailing The 2.1 [MM2+3]

Postby matts2 » Fri Feb 29, 2008 10:21 pm

I have a strange problem with this script. I ran the script and it seemed to work fine. That is, when I looked at, say, a Who song the Artist/Album Artist were "Who, The". But when I tried to auto-organize the files it kept on wanting to put it in \The Who\. I tried to exit MM and return, but the problem remained.

Then things go weirder. I moved the files outside of MM, manually deleted the entries from the DB, and told MM to re-scan the folders. When done the Artist/Album Artist are back as "The Who".

I don't know if it matters, but I have lots of songs, about 30K songs and 200GB.

Any idea of what might be happening? I would look myself, but I am not all that familiar with VBS.
matts2
 
Posts: 34
Joined: Thu Apr 07, 2005 11:48 am

Next

Return to Need Help with Addons?

Who is online

Users browsing this forum: No registered users and 11 guests