| Author |  | 
      
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          This thread will document my macros for displaying album art in a web page for the currently playing track in Winamp.
           | Posted: May 08 2006 at 22:58 | IP Logged |   |  
           | 
 |  
 My music is organized by Artist/Album folders and my art files follow the Windows Media Player standard of either folder.jpg (large image) or albumartsmall.jpg (smaller image).
 
 The basis of my plan revolves around, and is made possible by, loading the current playlist into the UserData1 table. This is necessary because, for some reason, Winamp does not expose the path of the currently playing track via Windows Messaging.
 
 A Winamp m3u playlist file contains the song length, song title, and path of the song with filename. Once we know the path, we know where to find the related image.
 
 Since the ID field of the userdata1 table only allows 25 characters, I can't use this for the song title, since some of my titles are longer than that. I'll just use "SONG 1", "SONG 2", etc. and then trim out the name from in between the path and extension (i.e. mp3, wma). Not pretty, but it's a start. The path and filename will be put into the Value string column and the length will be in the Value number column.
 
 My macro only reads in each song length and path/filename so far, but that is enough for tonight!
 
 Next steps will be to insert this data into the table. After that, I'll create another macro to occasionaly get the art for the track while Winamp is playing.
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          I now have the data being inserted into the table.
           | Posted: May 11 2006 at 00:10 | IP Logged |   |  
           | 
 |  
 One problem was that "insert into userdata1 on existing update..." seems not to work, so my work-around was to delete the table contents at the beginning. This was tricky, too, since it seems that permissions are not sufficient to allow a complete delete. The work around for this was to do a "delete from userdata1 where type=1" (all entries are type 1 so far).
 
 Another problem was that it didn't like seeing single quotes in filenames, so I "ph_replaceall" them with two single quotes to escape them.
 
 The last problem is speed: only about 11 songs per second. I don't dare try to load my main playlist yet, as it is >2000 songs. The killer here seems to be the replace function (about twice as fast without it).
 
 Here is the code so far...
 
 
 
| Code: 
 
    
    | 
      
       | 10 Formula Post     ph_directsql("delete from userdata1 where type=1") 20 Set System [LOCAL1] ph_readfile("c:\music\a list.m3u")
 30 Comment Set Position Counter
 40 Set System [LOCAL2] 1
 50 Comment Set Song Counter
 60 Set System [LOCAL7] 0
 70 Label FIND
 80 Comment Get song length
 90 Set System [LOCAL3] ph_regexdiff( "#EXTINF:", ",", "[LOCAL1]", [LOCAL2], 0)
 100 Comment Get filename
 110 Set System [LOCAL4] ph_regex( "^.+\.[wma][mp3][wav]", "[LOCAL1]", [LOCAL2], 0, 5, 6)
 120 Set System [LOCAL4] if( pos("[LOCAL4]", "'")>0, ph_replaceall( "[LOCAL4]", "'", "''"), "[LOCAL4]")
 130 Set System [LOCAL2] [LOCAL5] + [LOCAL6]
 140 Jump if( [LOCAL2] = 0, 999, 1)
 150 Set System [LOCAL7] [LOCAL7] + 1
 160 Formula Post ph_directsql("insert into userdata1 values (1, 'SONG [LOCAL7]', [LOCAL7], today(), 'c:\music\[LOCAL4]', [LOCAL3], today())")
 170 Goto Label if( pos( "[LOCAL1]", "#EXTINF:", [LOCAL2]) = 0, "OUT", "FIND")
 |  |  |  
 
 Edited by TonyNo - May 11 2006 at 00:17
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          Update: Turning off Direct SQL logging helped the speed.
           | Posted: May 12 2006 at 08:43 | IP Logged |   |  
           | 
 |  
 I've found that a formula does not work, but seems that it should...
 
 ph_rtne( ph_sqlselectinto ( 1, "select * from userdata1 where valstring like '%sweetness.wma'" )) + [LOCAL3]
 
 This returns a "!".
   
 Edited by TonyNo - May 12 2006 at 08:45
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Tony,
           | Posted: May 12 2006 at 13:00 | IP Logged |   |  
           | 
 |  
 I checked it out and only see one small problem.  The problem if your SQL returns no data.  In this case, nothing will be in [LOCAL3] which will get substituted with nothing.  You'll then have an empty string with a '+' sign.
 
 You can fix this with a simple change:
 
 
 
| Code: 
 
    
    | 
      
       | ph_rtne(ph_sqlselectinto ( 1, "select * from userdata1 where valstring like '%sweetness.wma'" )) + ph_getvar_s(1,3)
 
 |  |  |  
 See if that helps.
 
 Dave.
 
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          I'll try that. I never got a '+', though, always the '!'.
           | Posted: May 12 2006 at 14:03 | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |       | 
       
       
        |  | 
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Getting a '!' is correct.  If you typed "" + in the formula evaluator, it would return the '!' since you've got no value after the '+'.  Using the ph_getvar_? functions would either return an empty string (in the case of ph_getvar_s) or a 0 (in the case of ph_getvar_n).
           | Posted: May 12 2006 at 16:29 | IP Logged |   |  
           | 
 |  
 Dave.
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          Ah! OK.
           | Posted: May 12 2006 at 17:06 | IP Logged |   |  
           | 
 |  
 I forgot about the formula web page.
   
 Doing that works (as if you didn't know
  ). | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          I think I overcomplicated this!
           | Posted: May 12 2006 at 20:54 | IP Logged |   |  
           | 
 |    
 I can just work with the playlist file directly instead of pulling it into the database.
 
 But...
 
 What bad things could happen on the GV web page with a GV that is 180k?
   
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Tony,
           | Posted: May 12 2006 at 22:34 | IP Logged |   |  
           | 
 |  
 I was wondering about the overcomplication myself
  . 
 A GV has a max size of 1024 bytes so you won't be able to get it to fit.
 
 You could use a Global System Variable though ([GLOBAL1] thru [GLOBAL20]).  These arent in the database and only exist in memory so have basically unlimited size.  You could read the file in using the STARTUP macro and then probably just use ph_regex functions to do your lookups.
 
 Dave.
 
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          
           | Posted: May 12 2006 at 22:48 | IP Logged |   |  
           | 
 |   I got it working but then thought of a much simpler way! 
 More later...
 
 PS: Did anyone know that there is a scripting plugin for Winamp?
 
 Edited by TonyNo - May 12 2006 at 22:49
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          OK, what regex could I use on this...
           | Posted: May 12 2006 at 23:21 | IP Logged |   |  
           | 
 |  
 #EXTINF:359,Seal - Show Me
 Seal\Seal [1991]\Seal-Show Me.wma
 
 to end up with "Seal\Seal [1991]"?
 
 This...
 
 ph_regexdiff("Seal - Show Me~255^", "\\[^\]\.wma"
 
 Does not work as I expect it to.
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          I'm closer but no cigar with...
           | Posted: May 13 2006 at 09:17 | IP Logged |   |  
           | 
 |  
 ph_regexdiff("[LOCAL2]~255^","\\[^\\]+\.wma$"
 
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          Got it...
           | Posted: May 13 2006 at 12:00 | IP Logged |   |  
           | 
 |  
 ph_regexdiff("[LOCAL2]~255^","\\*[^\\]*\.wma$"
 
 What does it mean when ph_copyfile returns a 2?
   
 Edited by TonyNo - May 13 2006 at 12:06
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          To hold me over for a bit on other track info beyond what is currently exposed, I found this  thread at winamp.com that contains a command-line app to pull the extended song data from winamp. I'll run it and redirect the output to a file for parsing.
           | Posted: May 14 2006 at 15:23 | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          Whoa, boy! This project really changed direction from where I started! Pulling the playlist into the database was much too slow. Getting the playlist into a LOCAL variable is seriously faster, even at 180k.
           | Posted: May 14 2006 at 19:23 | IP Logged |   |  
           | 
 |  
 I now just read my (specified) playlist and scrape the artist and album info from the output generated by winampmagic. I could also use the output to find the path of the current song, but then I would never know the next song to be played (something I've grown fond of). I also want to implement displaying and paging through large playlists.
 
 I've linked a Zip file of the two macros below plus a batch file for a work-around I needed for ph_run. You'll need winampmagic placed in the ph folder, along with the batch file.
 
 Create three Global Variables that will be updated when the macros run: WINAMP ARTIST, WINAMP ALBUM, and WINAMP NEXT. The WINAMP ART macro will find the path to the current song, copy both art files to the PH web folder, and find the name of the next song. You should also update WINAMP ART to reflect your music setup. I was not able to use a regex alternation pattern for wma/mp3 files ("wma|mp3"), so I used what was there ("[wm][mp][a3]").
   
 I found a problem with ph_run (redirection seems to not be liked in the string), so you'll need to change the path specified, if necessary...
 
 ph_run( 'cmd.exe /c "c:\program files\powerhome\winampmagic.bat" ')
 
 Once the ph_copyfile problem mentioned previously is solved, missing art files will be replaced with the ones in the root music folder.
 
 Files
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Tony,
           | Posted: May 15 2006 at 16:19 | IP Logged |   |  
           | 
 |  
 Wow, you've been busy.  Hopefully I can help you out on a couple of issues.
 
 A 2 returned from ph_copyfile means that an error occurred while creating the targetfile.  The help documentation is wrong and the negative values should be positive values.
 
 Why this could happen could be a couple of different things.  The directory you're copying to may not exist, or if you're overwriting a file, the file may be locked or flagged "read only" and cant be overwritten.
 
 Also, Ive been able to eliminate the need for a batch file.  The proper format for the ph_run function with redirection is:
 
 
 
| Code: 
 
    
    | 
      
       | ph_run('cmd.exe /c "~"c:\program files\powerhome\winampmagic.exe~" > ~"c:\program files\powerhome\winampmagic.txt~""') |  |  |  
 Hope this helps a little.
 
 Dave.
 
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          Cool! Thanks dave!
           | Posted: May 15 2006 at 19:14 | IP Logged |   |  
           | 
 |    
 Could a hidden file cause the ph_copyfile error?
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          N/M. Deleting first fixed it.
           | Posted: May 15 2006 at 19:21 | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          ZIP file updated.
           | Posted: May 16 2006 at 07:15 | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |       | 
       
       
        |  | 
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          In a related project, I wanted to be able to list out and scroll through the current playlist. I have the code done, but speed is an issue again. Only about 16 songs per second.
           | Posted: May 21 2006 at 18:52 | IP Logged |   |  
           | 
 |  
 For anyone interested, here is the macro and a psp file.
 
 This uses ph_getwebparm, so usage is...
 
 /playlist.psp?pl=[path and playlist name]&start=[start position]&len=[list length].
 
 Winamp Playlist
 
 Edited by TonyNo - October 08 2006 at 12:06
 | 
       
        | Back to Top |       | 
       
       
        |  |