Page 2 of 4

Posted: Mon Oct 23, 2006 3:45 am
by trixmoto
All my newer scripts create a temporary html file on your local machine and then navigate to this page. This is primarily for security reasons, as IE has been tightening up the direct access to the document object. There are older scripts which need updating, but I'm only one guy and I've written a lot of scripts with html interfaces!

The updateArtist and updateAlbum are not supposed to be necessary, but it does appear to force this to work correctly. Again, I have not had time to go through all my scripts and fix this. One day, I might! :D

Posted: Mon Oct 23, 2006 8:54 pm
by Montana
I figured the document.write buggage was due to newer IE restrictions, as there are some hack/exploitation techniques that utilize it across browser windows/frames.

I dunno about the Update funtions, I am still too new and the online-linked documentation is also broken now :(

There's also the .UpdateAll technique using Songlists, but I didn't test that: I saw you and others had looked into it, and there were some questions about it possibly being lethargic. However, with ANY huge batch job, the multithreading just isn't possible with old-skool vbs scripts; and pulling up the confirmation window can take forever. So I try to limit my usage to about 1000 tags per script run! I don't think anyone has done a compare of the same functionality obtained by piping the changed rows into a Songlist and seeing how long UpdateAll takes versus the individual Updates and WriteTags... have they?

I can send you (or just cut and paste) what I did to make it all work. I updated FixTrailingThe, FindMissingThe, and AdvancedRename.

Posted: Tue Oct 24, 2006 2:56 am
by trixmoto
UpdateAll is better in the sense that it uses the user's settings to decide whether or not to write to the tags. It also triggers events which are not triggered by UpdateDB or WriteTags. This extra functioanlity does take time, especially if you have scripts installed which use events such as OnTrackProperties.

I would certainly like to see the modifications you have made, please email me the code at your convenience.

Posted: Wed Oct 25, 2006 9:10 pm
by Montana
I actually don't have email on this machine >_>

So here are the two revised functions in AdvancedRename:

Code: Select all

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 
         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 items 
      If itm.ID>-1 Then 
         itm.UpdateArtist
         itm.UpdateAlbum
         itm.UpdateDB 
         itm.WriteTags
      End If 
   Next 'itm

'Test this next!
'  Dim list
'  Set list = SDB.NewSongList
'  For Each itm In items
'    list.Add( itm)
'  Next
  
'  list.UpdateAll
    
   Set items = nothing 
   CloseDown 
End Sub 


Sub AdvancedRename 
   Dim UI, Form, Foot, Btn, Btn2, WB, HTML
    
   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 
   
   SetPrefixes(prefixes)
   SetPostfixes(postfixes)
   SetExceptions(exceptions)

   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.Caption = SDB.Localize("Advanced Rename") 
   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:"

   ' 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" 
   Btn.Cancel = true

   ' 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" 
   Btn2.Default = true

   Form.SavePositionName = "AdvancedRenameWindow" 
   Form.Common.Visible = True                ' Only show the form, don't wait for user input 
   SDB.Objects("AdvancedRenameForm") = Form  ' Save reference to the form somewhere, 

otherwise it would simply disappear 

   HTML = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbcrlf 
   HTML = HTML & "<html>" & vbcrlf 
   HTML = HTML & "  <head>" & vbcrlf 
   HTML = HTML & "    <title>" & SDB.Localize("Advanced Rename") & "</title>" & vbcrlf 
   HTML = HTML & "  </head>" & vbcrlf 

   HTML = HTML & "<STYLE TYPE=text/css>" & vbcrlf 
   HTML = HTML & "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; 

font-size:9pt; color:#000000;}" & vbcrlf 
   HTML = HTML & "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; 

color:#AAAAAA; text-align:left}" & vbcrlf 
   HTML = HTML & "P{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000;}" & 

vbcrlf 
   HTML = HTML & "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 
   HTML = HTML & "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 
   HTML = HTML & "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 
   HTML = HTML & "TR.dark{background-color:#EEEEEE}" & vbcrlf 
   HTML = HTML & "TR.aleft TH{text-align:left}" & vbcrlf 
   HTML = HTML & "</STYLE>" & vbcrlf 

   HTML = HTML & "  <body>" & vbcrlf 
   HTML = HTML & "    <H1>" & SDB.Localize("Advanced Rename:") & "</H1>" & vbcrlf 
   HTML = HTML & "    <table border=""0"" cellspacing=""0"" cellpadding=""4"" 

width=""100%"">" & vbcrlf  
   HTML = HTML & "      <tr class=""aleft"">" & vbcrlf 
   HTML = HTML & "        <th>" & SDB.Localize("Artist") & "</th>" & vbcrlf  
   HTML = HTML & "        <th>" & SDB.Localize("Album Artist") & "</th>" & vbcrlf 
   HTML = HTML & "      </tr>" & vbcrlf 

   Dim i, itm 
   Dim artist, albumArtist 
   for i=0 to trackList.count-1 
      HTML = HTML & "      <tr" & Style() & ">" & vbcrlf 
      Set itm = trackList.Item(i) 
      
      Select Case mode
        Case 0
          artist = rename(itm.artistName) 
          albumArtist = rename(itm.albumArtistName) 
        Case 1
          artist = rename2(itm.artistName) 
          albumArtist = rename2(itm.albumArtistName) 
        Case Else
          artist = itm.artistName
          albumArtist = itm.albumArtistName
      End Select
      
      HTML = HTML & outField(artist, itm.artistName) 
      HTML = HTML & 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 
      HTML = HTML & "      </tr>" & vbcrlf 
       
   next 'i 
    
   HTML = HTML & "    </table>" & vbcrlf 
   HTML = HTML & "  </body>" & vbcrlf 
   HTML = HTML & "</html>" & vbcrlf 

   WB.SetHTMLDocument(HTML)

   SDB.Objects("holdArtist") = holdArtist 
   SDB.Objects("holdAlbumArtist") = holdAlbumArtist 
End Sub 
The same was applied to other scripts of yours as well. Not sure how to remove the unfortunately hard-line breaking in the above code section!

Posted: Thu Oct 26, 2006 3:22 am
by trixmoto
Thanks. What do you mean "hard-line breaking"?

Posted: Thu Oct 26, 2006 3:42 pm
by Montana
line wrapping that isn't really a hard break, just looks like one - caused by pasting text into small boxes. like if you cut and pasted the above, you'd have to fix the lines that "wrapped" around due to excess horizontal width.

Posted: Sun Dec 17, 2006 10:57 am
by gab
Trix:

A couple of questions regarding this script:

(1) Is there a way to apply the script just to the Artist field without it impacting the Album Artist field? When I run it, the script changes Various Artists to Artists, Various. I don't want to do this.

(2) Also, is there an options panel for this? Or do you need to modify the actual script for the Exceptions.

Thanks.

Posted: Mon Dec 18, 2006 5:25 am
by trixmoto
You need to modify the script itself to add exceptions. If you add "Various Artists" to the exceptions then surely this will not be a problem for you?

Posted: Mon Dec 18, 2006 5:17 pm
by gab
Thanks Trix. I was hoping to avoid actually going into the script (a phobia of mine since I don't write code). However, I conquered my fear :D and found that it was pretty easy. Thanks for the help and great script. I just used it to tag a bunch of compilations that I hadn't bothered to clean up. Fast and easy.

Posted: Tue Dec 19, 2006 4:45 am
by trixmoto
I do add options sheets to my larger scripts that have lots of options, but in this case it's just a couple of lists to change. I'm glad you gave it a go and succeeded, and that the script help you! :)

Posted: Mon Nov 12, 2007 11:45 am
by trixmoto
New version (2.2) is now available to download from website. It has now been made compatible with MM3 so there is an installation package available too. :)

Posted: Mon Dec 03, 2007 9:12 am
by Randall_Lind
How do you change this so it copes first name, last name? wgeb I used this it wanted to do last,first which I hate.

Posted: Mon Dec 03, 2007 11:35 am
by trixmoto
You need to edit the script file in a text editor. Near the top you should find the lines...

Code: Select all

mode = 0 'Firstname Lastname -> Lastname, Firstname
'mode = 1 'Lastname, Firstname -> Firstname Lastname 
...which you should modify to be...

Code: Select all

'mode = 0 'Firstname Lastname -> Lastname, Firstname
mode = 1 'Lastname, Firstname -> Firstname Lastname 

Posted: Mon Dec 24, 2007 2:04 pm
by kdeemer
This is a great script. I'd like to go through and reorganize my entire collection. But two things. First, I notice that the Artist and Album folders seem to remain in MM, even though they are empty after having the Firstname and Lastname reversed. How do I get rid of these. Second, is there a way to automatically change the artist folder names as well as the tracks, eg. change the folder Bob Dylan to Dylan, Bob?

Many thanks

Posted: Wed Jan 02, 2008 4:52 am
by trixmoto
You can change the folders using auto-organise. I don't think there's any way to add this to the script itself though, sorry.