Script idea: auto download album art

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Script idea: auto download album art

by trixmoto » Thu Feb 02, 2006 10:42 am

The first full version of this script is available here: http://www.mediamonkey.com/forum/viewtopic.php?t=7967

by trooper95 » Wed Feb 01, 2006 7:25 pm

What I meant was to not have it work off the "Now Playing" track.

In other words, highlight an album name from the directory structure and then run the script to find the album art.

Does that make more sense?

by Teknojnky » Wed Feb 01, 2006 3:25 pm

Had the access errors pop up again, not sure whats causing that.

Just now had the following error after renaming a (playing) track title:

"Error #-214748113 - SongsDb.SDBApplication
System Error. Code: 5.
Access is denied
File: "J:\Program Files\MediaMonkey\Scripts\LastFMArtFinder.vbs", Line: 44, Column: 2"

This seemed to be repeatable, I renamed (the tag not filename) an Alanis Morissette track "Wake Up" to "Wake Up/Your House" and back again and got the errors.

(MM 2.5.2 beta1)

by Teknojnky » Wed Feb 01, 2006 2:06 pm

WOW!

I must say that is quite the fantastic concept code!

It seems to work perfect if, A) lastfm has matching album, B) lastfm has album art!

A couple comments:

- The window seems to open in the same place and doesnt remember where it is last position (not sure if the window position can be persisted via scripting)

- Ideally (for me) the script would not run if album art already exists (not sure how this can be checked, maybe somehow via the 'files to edit > unknow album art' node?)

- While I do LOVE last fm, the art may not necessarily be the album art as users can submit any picture and its just a matter of users voting approval.


Compare the lastfm results for "Moby Early Underground", "John Denver The Country Roads Collection (disc 1)" with Google images.

Compilations albums also can throw a wrench into the search, example: "Salt-N-Pepa Now Dance 91" vs google images "Now Dance 91"
Lastfm "Various Heavenly Hardcore" & Google "Various Heavenly Hardcore"

I guess I'm starting to suspect google may be the best default search because it should find images from lastfm, discogs, amazon, etc automatically.

I understand you can't yet write album art to tags directly, what about sending it to the library and let MM or the user sync tags later?

For tracks that do not have album info, perhaps displaying an artist picture (from lastfm or google or wherever).

Also, After a while I started to get access violations:

- Access violation at address 0040E74 in module 'mediamonkey.exe' read of address 0000005c

- Access violation at address OED08281. Write of address 0000006c

After I restarted they did not yet appear again.


Awesome job tho, mad props! Image

by trixmoto » Wed Feb 01, 2006 1:20 pm

As I've said, there are no methods for adding album art to the library (nor the tags). However, CrossEyed is currently working on reading/writing the ID3 tags directly which will allow this. So I'll add this option when the methods become available.

by Teknojnky » Wed Feb 01, 2006 1:02 pm

judas wrote:Teknjnky would like to:
auto download album art as a track plays (only if album art does not exist).
...i think he refers to auto-saving the image to the song tag?

:-)


judas.

Right, Ideally the script could use whatever common options are, save to tag, save to albumart.jpg, save to a specific folder, etc.

The only option I am concerned about is, saving to the id3 tags so that MM will display them on the album art viewer!

:)

I will check out the script with great anticipation!

by trixmoto » Wed Feb 01, 2006 11:34 am

You will also need this code saved as "LastFmArtFinder2.vbs" in your Scripts folder.

Code: Select all

'
' MediaMonkey Script
'
' NAME: LastFmArtFinder 1.0
'
' AUTHOR: trixmoto (http://trix.dork.com)
' DATE : 01/02/2006
'
' INSTALL: Helper script for 'LastFmArtFinder.vbs'
'          Needs to be in '{MM}\Scripts\'
'

Set SDB = CreateObject("SongsDB.SDBApplication")
Set IE = SDB.Objects("WBIE")
Do While IE.ReadyState <> 4
  WScript.Sleep 500
Loop
Set IE = Nothing

by trixmoto » Wed Feb 01, 2006 11:32 am

Here is the concept code! It simply displays the best matching result Last.fm has to offer, whenever a track starts playing. If you want the image, you can right click on it and select "save as". Please comment on how you want this to work, and I'll do my best to provide.

Code: Select all

'
' MediaMonkey Script
'
' NAME: LastFmArtFinder 1.0
'
' AUTHOR: trixmoto (http://trix.dork.com)
' DATE : 01/02/2006
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' [LastFmArtFinder]
' FileName=LastFmArtFinder.vbs
' ProcName=LastFmArtFinder
' Order=27
' DisplayName=Last.Fm Art Finder
' Description=Find album art from Last.fm
' Language=VBScript
' ScriptType=2 
'

Option Explicit
Dim IE,url,img

Sub LastFmArtFinder

  Dim Form,WB
  Dim song,artist,album
    
  'setup search
  Set song = SDB.Player.CurrentSong
  artist = mapname(song.ArtistName)
  album = mapname(song.AlbumName)
  url = "http://www.last.fm/explore/search.php?q="&artist&"+"&album&"&m=albums"
  img = 0

  'create form    
  Set Form = SDB.UI.NewForm
  Form.Common.SetRect 100, 100, 600, 400
  Form.BorderStyle  = 2
  Form.FormPosition = 4
  Form.Caption = "Last.fm Art Finder"
  Form.Common.Visible = True
  SDB.Objects("ArtFinder") = Form
  
  'create web component
  Set WB = SDB.UI.NewActiveX(Form, "Shell.Explorer") 
  WB.Common.Align = 5
  WB.Common.ControlName = "WB" 
  Set IE = WB.Interf
  SDB.Objects("WBIE") = IE
  
  'perform initial search
  Search()
        
End Sub
 
Function Search
  
  Dim wsh,cmd,src,list,i
  Search = False
  
  'wait for page to load
  IE.Navigate url
  cmd = SDB.ApplicationPath&"Scripts\LastFmArtFinder2.vbs"
  If SDB.Tools.FileSystem.FileExists(cmd) Then
    Set wsh = CreateObject("WScript.Shell")
    i = wsh.Run("wscript "&Chr(34)&cmd&Chr(34), 1, 1)
    Set wsh = Nothing
  End If
 
  'find image
  Set list = IE.Document.Images
  For i = 0 to list.Length-1
    src = list.Item(i).src
    If UCase(Right(src,4)) = ".JPG" Then
      ShowResult(mapurl(src))
      Search = True
      Exit Function
    End If
  Next
  
  'error if no image found
End Function

Function ShowResult(src)

  Dim doc
  
  Set doc = IE.Document
  doc.Write "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"&vbcrlf
  doc.Write "<html>"&vbcrlf 
  doc.Write "  <head>"&vbcrlf
  doc.Write "    <title>"&vbcrlf
  doc.Write "      Last.fm Art Finder"&vbcrlf
  doc.Write "    </title>"&vbcrlf
  doc.Write "  </head>"&vbcrlf 
  doc.Write "  <body>"&vbcrlf
  doc.Write "    <img src="""&src&""" align=left>"&vbcrlf
  
  
  
  doc.Write "  </body>"&vbcrlf
  doc.Write "</html>"&vbcrlf
  doc.Close
  
End Function

Function saveimage(src,dest)
  Dim HTTP,Stream
  Set HTTP = CreateObject("Microsoft.XMLHTTP")
  HTTP.open "GET", src, False
  HTTP.send
  Set Stream = CreateObject("adodb.stream")
  Stream.type = 1 'binary
  Stream.open
  Stream.write HTTP.responseBody
  Stream.savetofile dest, 1 'ifnotexist, overwrite=2
  Set Stream = nothing
  Set HTTP = nothing
  saveimage = True
End Function
 
Function mapname(name)
  Dim i,c,l
  mapname = ""
  For i = 1 to Len(name)
    c = Asc(Mid(name,i))
    l = Len(mapname)
    If c > 32 Then
      If c < 48 Then
        mapname = mapname&"%"&CStr(Hex(c))
      Else
        If c > 57 Then
          If c < 65 Then
            mapname = mapname&"%"&CStr(Hex(c))
          Else
            If c > 90 Then
              If c < 97 Then
                mapname = mapname&"%"&CStr(Hex(c))
              Else
                If c > 122 Then
                  If c < 127 Then
                    mapname = mapname&"%"&CStr(Hex(c))
                  End If
                End If
              End If
            End If
          End If
        End If
      End If
    End If
    If l = Len(mapname) Then 
      mapname = mapname&Chr(c)
    End If
  Next
  mapname = Replace(mapname," ","+")
End Function
 
Function mapurl(url)
  url = Replace(url,"50x50","300x300")
  url = Replace(url,"THUMB","LZZZZ")
  mapurl = url
End Function 

by trixmoto » Wed Feb 01, 2006 11:26 am

What do you mean about not incorporating Now Playing? Just doing it in batch for all the selected songs?

by trooper95 » Wed Feb 01, 2006 10:59 am

Speaking for myself and my own personal preference, I save album art to its corresponding Album folder with the file name of "folder.jpg".
I'm sure evryone does it slightly different or uses a different file name.
There are probably people who have folders of music not organized that way, ie., 1 folder with 100 songs of all different artists. That would present a problem me thinks.

Maybe 2 options: store in centralized folder with all album art -or- as mentioned above, in corresponding Album folder.

Just my 2 cents. Regardless, such a script would be awesome.

As a side suggestion: Can this work without incorporating the "Now Playing" option??

Thanks trixmoto for your work on this.

by trixmoto » Wed Feb 01, 2006 10:34 am

Well at the moment there are not methods for adding album art to tags. I guess the only choices at the moment are "save to album folder" or "save to central album art folder". I guess I could just give both options! :)

by judas » Wed Feb 01, 2006 9:00 am

Teknjnky would like to:
auto download album art as a track plays (only if album art does not exist).
...i think he refers to auto-saving the image to the song tag?

:-)


judas.

by trixmoto » Wed Feb 01, 2006 6:57 am

I now have a working concept which uses Last.Fm to find album art and with my music it is fairly reliable. At the moment it just displays the art in a window though. What were you hoping this script would do with the image?

by trixmoto » Tue Jan 31, 2006 11:44 am

Actually Last.Fm uses quite a lot of amazon images as well.

by Teknojnky » Tue Jan 31, 2006 11:23 am

Musicbrainz is actively moderated, I would think it would have a very high accuracy for both album art and track listings.

Top