My Recent Tunes Code

Here is the code that I use to power my Recent Tunes list seen at right. It’s a little messy, but at least commented so you have some clue what each part is doing. The cover_update.php script is what does most of the work. You shouldn’t have to change anything in the amazon folder – that’s all there to talk to the Amazon.com API, which you will need access to. I also recommend Recent Tunes for updating your tracks from iTunes. Note that I use the current tune, not the list of recent tunes, as it makes managing the MySQL database easier and lessens the load put on Amazon’s API (which I imagine has a ~1000 query per day limit). If you have questions about using it, post a comment so that others can benefit from the conversation as well.

Advertisements
My Recent Tunes Code

12 thoughts on “My Recent Tunes Code

  1. I’m looking forward to using this, but as a non php programmer I just have a couple of requests to make this a bit easier for me and others. Geez, we want it on a plate don’t we! :)

    Would you be able to export the structure of your mysql table as I assume the php file requires this to exist before it works?

    Secondly, could you post your recent tunes template for the current track? This is because I’m not sure if the php script expects the artist, title, album, time and rating to be in a specific order.

    After playing with this a little bit, am I correct in assuming that this is how it works:
    1. Export the recent tune html file to web server using recent tunes inbuilt export function
    2. Set up a cron job to periodically run cover_update.php to insert the song details as well as the urls from amazon and itunes music store into the mysql database
    3. When someone visits my website a php include will call the display.php to read the data from the database and make my tunes list look extremely pretty.

    Therefore, the things I need to do to get it to work is:
    1. create mysql table
    2. edit dbconnect.php to add user,password,database and host details
    3. edit cover_update.php with my amazon associates id
    4. fill the database with at least 10 songs before putting it up on the website???

    Have I missed anything?

    This has to be the best looking tunes tool I have seen and would love to get it working.

    Like

  2. Wow! That was an impressively quick reply!

    Thanks for that last tip about Word Press, it would have really stumped me for a while. I’ve now got it working thanks to those extra hints, just a couple of things I did that weren’t mentioned that might help someone else:

    1. Told Recent tunes to export current track as track.html
    2. Changed the urls in display.php and coverupdate.php to my website and path.
    3. Changed the references from wp-content/themes/command-tab/ to where I had put the files on my webserver.
    4. And the usual make sure your permissions are set on your mysql database. :)

    Now I just have to integrate it in to my blog and I will be promoting music like there is no tomorrow. Thanks for your work Collin, I’ll be clicking quite a few google ads for this!

    Like

  3. I exported the table structure, which you can get here. And yes, it is required before any code is run. Eventually, I’d like to make a quick little “5-minute” installer that can create the database and/or table, much like the WordPress installation.

    Your steps are all correct except for #4, somewhat. It will fill up on it’s own, and limit itself to the value set for $cleanLimit in cover_update.php. It’s safe to include it right away, as it won’t print out anything until there is at least one song in the database.

    My Recent Tunes template for the Current Track is:
    ^p&&&&&^a&&&&&^t&&&&&^r
    I know that using 5 ampersands is a janky way to accomplish it, and that things would be better off formatting it using XML if possible (Recent Tunes does allow for a header and footer, so it might be doable, thought maybe not UTF-8…) Consider this a beta release :-)

    One last thing… the big if block, if(!is_search() && !is_single() && !is_day() && !is_month()) shouldn’t be in display.php unless you’re copying the code into your WordPress sidebar. Functions like is_search() don’t exist outside of WordPress. So you can either use display.php however you want and remove that if block, or keep it and paste everything inside into your WordPress sidebar code. I just didn’t want five tunes showing up on the sidebar if the content of the page might be rather short compared to the sidebar. It’s totally up to you, though.

    Like

  4. I’d like to work in CSS “sprite” rollovers for the link buttons so they don’t flash really quick when you hover over them for the first time (while the image draws in once). A List Apart’s method seems to work better than just swapping the background image for that div tag.

    Like

  5. I’m having trouble with this step:

    2. Set up a cron job to periodically run cover_update.php to insert the song details as well as the urls from amazon and itunes music store into the mysql database

    I can get the db to update if I add to display a ‘require’ on cover_update, but that’s clearly not the right way (display doesn’t work)…how do I set up a cron job to update the cover? (yes, I’m a noob)

    thanks – this is really awesome (and it’ll be more awesome once I get it working)

    Like

  6. I can get the db to update if I add to display a ‘require’ on cover_update, but that’s clearly not the right way (display doesn’t work)…how do I set up a cron job to update the cover? (yes, I’m a noob)

    What I did was to set up a cron job that calls ‘curl’ to retrieve cover_update.php from the server. Not really the best way – it is possible to call a script from the command line.

    Like

  7. thanks for the quick reply – but I think this is all a bit over my head..might just have to stick to the standard output from RecentTunes for now ’til there’s an installer for this (or I learn more).

    Like

  8. Hmmm. I wonder if I can get this to work at .mac :-

    Unfortunately, no. Apple’s .Mac doesn’t provide PHP or MySQL. I really wish they would, but $100 per year only works out to $8.30 per month – about the cheapest you’ll find a web host that supports both. I hear that Apple is planning some .Mac enhancements for the Tiger release, though it’s likely it won’t be what you’re looking for to run this code.

    Like

Comments are closed.