fmTuner: A Last.fm Plugin for WordPress

fmTuner BannerThe result of the “Tunes” sidebar element on the Command-Tab homepage, fmTuner is a small WordPress plugin for retrieving song details from your Last.fm profile and publishing them anywhere in your WordPress theme. It provides options for choosing among your Recent, Loved, or Top tracks, as well as tools to adjust the update frequency and appearance:

Settings - fmTuner: A Last.fm Plugin for WordPress

Of particular note is the customizable Display Format option. Using simple tags like [::artist::] and [::image::] intermixed with regular HTML, you can tweak your Last.fm tracks exactly how you like, or however your WordPress theme requires. You have full control!

Download fmTuner Now

Requirements

  • WordPress 2.5 or later.
  • PHP 5 or later (fmTuner uses PHP 5’s SimpleXML for decoding Last.fm data).
  • Basic knowledge of PHP, HTML, and WordPress.

Installation

  • Upload “fmtuner.php” to a directory inside “/wp-content/plugins/” directory. For example: “/wp-content/plugins/fmtuner/fmtuner.php”
  • Ensure “/wp-content/plugins/fmtuner/” is writable by your webserver (chmod 755 fmtuner).
  • Activate the plugin through the “Plugins” menu in WordPress.
  • Set up options in the “Settings” menu in WordPress.
  • Place “if(function_exists(‘fmtuner’)) { fmtuner(); }” in your templates, between PHP tags.

Release History

  • fmTuner 1.1
    Released on Feb. 1, 2010
    Added a placeholder image field to the fmTuner Settings page, which will be substituted when tracks have no artwork.
    Tested under WordPress 2.9.1.
  • fmTuner 1.0.8
    Released on Nov. 3, 2009
    Fixed a bug with the [::url::] fmTuner tag that caused Last.fm links to appear incorrectly.
  • fmTuner 1.0.7
    Released on Apr. 23, 2009
    Tracks with foreign character sets now display more accurately.
  • fmTuner 1.0.6
    Released on Mar. 29, 2009
    You can now display more than 10 Recent Tracks, and you should get fewer tracks without artwork.
  • fmTuner 1.0.5
    Released on Mar. 22, 2009
    Track information is now properly escaped to handle $ signs, quotes, and other non-alphanumeric characters.
  • fmTuner 1.0.4
    Released on Dec. 14, 2008
    Made minor tweaks for fmTuner Settings page under WordPress 2.7.
  • fmTuner 1.0.3
    Released on Nov. 15, 2008
    By request, a [::number::] fmTuner tag has been added, which emits a sequential number for each track (starting at 1). This is particularly useful for CSS and JavaScript display purposes.
  • fmTuner 1.0.2
    Released on Oct. 5, 2008
    Added a cURL-based alternative to file_get_contents to hopefully resolve “URL file-access is disabled” issues. If allow_url_fopen is disabled in the php.ini, cURL will be used to fetch the Last.fm feed instead.
  • fmTuner 1.0.1
    Released on Sept. 9, 2008
    Added better failure checking and informational messages, removed development code, and updated instructions.
  • fmTuner 1.0
    Released on Sept. 6, 2008
    Initial release.

Released under the MIT License. Do with fmTuner whatever you wish. Mod it, mash it, hack it. Make it yours.

90 Responses to “fmTuner: A Last.fm Plugin for WordPress”

  1. [...] A Last.fm Plugin for WordPress No Comments Sep 06 at 9:51 pm by Rogie fmTuner is a small WordPress plugin for retrieving song details from your Last.fm profile and publishing [...]

  2. it would be much cooler if it would be made as a standalone application

  3. @neondragon: Do you mean a standalone php script?

  4. hi. Thanks for plugin

    perfect.

    Regards

  5. Can you please advice what should I check if fmtuner() function gives zero output?

    I have cache xml file downloaded correctly.

  6. @Mad Cat: How is your Display Format set up? Still the default? Also, can you open the cache with a text editor and ensure it’s what you expect? Hope that helps!

  7. Nice, altough it has the same problem as every other Last.fm-Plugin that i know: I have to choose what to display in the settings.

    Why not make this an parameter to fmtuner();?
    That way i could easily display everything i want using only one plugin.

    I have described it in more detail in the comments over there: http://leandrow.net/ilastfm-lastfm-wordpress-plugin/#comments

    Any chance you’ll be adding “top tracks”, “top artists”, “top albums” etc and giving us the opportunity to display multiple instances by using it like:

    ===

    My Top Tracks:
    fmtuner(‘tracks’);

    My Favorite Albums:
    fmtuner(‘albums’);

    I’m a fan of:
    fmtuner(‘artists’);

    ===

    That would easily make your Last.fm-Plugin THE outstanding one out there.

  8. @AgentSmith: That’s a good point! I had assumed it would only be used in one place, but with an added parameter, it could be used multiple times on a site, each with different options.

    You can currently choose Top Tracks, but not the other two.

    I’ll see what I can cook up :)

  9. I keep getting this error.
    Fatal error: Call to undefined function: file_put_contents() in /homepages/42/d161646578/htdocs/home/wp-content/plugins/fmtuner/fmtuner.php on line 237

  10. @Collin: “only tracks with artwork will be shown” is a dangerous option. My case was that no artwork-powered tracks were cached and thus zero output produced.

    Still thanks for a great plug.

  11. A FAQ for this might be nice. For example… i got an error message telling me:

    Settings Saved – syled nicely… then in plain text underneath >
    Call to undefined function: file_put_contents() in /homepages/15/d117163260/htdocs/wordpress/wp-content/plugins/fmtuner/fmtuner.php on line 237

    I put the php code in my sidebar include BEFORE any of the if statments for widgets — just to be safe.

  12. @Jake @Joel_: file_put_contents() is a PHP 5 function. Are you by chance running PHP < 5?

    The WordPress plugin page linked to above has a small FAQ that is due for some updating now that the plugin is in the wild :) I’ll be updating it soon with solutions and problems covered in comments here.

  13. Yeah just realized I have php 4 and have no idea how to upgrade with 1and1.com

  14. After some looking I have php5 but I am still getting the same error, but its on line 236 now.

  15. fmTuner: A Last.fm Plugin for WordPress…

    fmTuner is a small WordPress plugin for retrieving song details from your Last.fm profile and publishing them anywhere in your WordPress theme. It provides options for choosing among your Recent, Loved, or Top tracks, as well as tools to adjust the upd…

  16. WordPress 2.6.2 Update
    I just tested fmTuner with WordPress 2.6.2, and it appears to be working just fine, as seen here at Command-Tab.

  17. @Rogie King: yes, that’s what i meant

  18. Oh… I’m 1and1.com also… but I thought for sure they supported both php 4 and 5!

    shoot.

  19. Yo Collin,

    Any plan to release this for php4? What is the dependency? Is it the caching or is it the XML libs needed?

  20. I plan on porting it to PHP 4 for a future release, as the dependency on PHP 5 is solely for the XML parsing that comes built-in. It shouldn’t be terribly complicated to find (or write) a basic XML parser for PHP 4 and get things rolling :)

  21. thanks for the info. Everyones responses have been helpful as well.

  22. actually, i did find out how to activate php5 for 1and1 hosting… but it turns out the php init settings do not support that external URL call you make… (even though it might very well handle the xml parsing).

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /homepages/15/d117163260/htdocs/wordpress/wp-content/plugins/fmtuner/fmtuner.php on line 248

    somehow, I doubt there would be a work-around for this… I’m pretty much stuck with the PHP config my host gives me, right? Any thoughts?

  23. @Joel_: You might be able to drop in an ini_set() call before file_get_contents() is called: ini_set(‘allow_url_fopen’, ‘on’);

    Otherwise, you might have to get in touch with 1and1 to see if they can update your config…

  24. it was a great post. i am coming to know about wordpress recently only. great to know that wordpress has these features. will switch one day. thanks.

  25. The plugin does not work for me…
    Yes, I am running PHP5. Wordpress 2.6.2

    Nothing will show up in the template. I get this at the top of my fmTuner settings page:

    ==================

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /mnt/local/home/jomilla/jomilla.com/wp-content/plugins/fmtuner/fmtuner.php on line 248

    Warning: file_get_contents(http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=jomilla&api_key=ff0eaca3b7e2660755d6c652af7b0489) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /mnt/local/home/jomilla/jomilla.com/wp-content/plugins

    =====================

  26. @Jordan: It seems your web host has URL-based file access turned off for some reason. You can try the ini_set solution I gave to Joel (above), and if all else fails, your web host might be able to turn it on.

  27. I’m not sure if I’m that big of a noob, But could you give me some clearer directions? In the meantime I will contact my web-host. Oh, and thanks a ton! :)

  28. And I got this back from my hosting company for the record:
    Hello Jordan,

    The reason this is disabled is because there is a security issue with URL
    based file access specifically url_file_open.

    We can’t change the global PHP settings, but you’re more than welcome to
    install a custom PHP instance if you’d like:

    http://wiki.dreamhost.com/Custom_PHP.ini

    I apologize for the inconvenience.

  29. ’m not sure if I’m that big of a noob, But could you give me some clearer directions? In the meantime I will contact my web-host. Oh, and thanks a ton!

  30. Got it working! Thanks a lot! Is there any pre made templates for this? or suggestions on building a template??

  31. Hi,

    can’t get the plugin running! Cache correctly downloaded, but
    no output.

    I placed

    in my SIDEBAR.PHP. No output. Where do i have to place the
    function-phrase and how cant i customize the output?

    Sven

  32. I wrote an ASP.NET User Control that provides a similar functionality for any of those out there looking to do this on an ASP.NET page. Hop on over to http://www.dscoduc.com/post/2008/10/09/lastfm-ASPNET-User-Control.aspx for a look and your copy.

  33. Hey any chance on telling us how to style these like yours I want mine to look simelar but I can’t get it quite right. :P great plugin btw exactly what I needed

  34. fmTuner works great with my wordpress…. And I am also using it via OpenSocial on my ning network i have set up for my site!

  35. Thanks for the plugin. I’ll check it out.

  36. I’m not toooo familiar with php stuff. Do I put the code in the sidebar php?

  37. thank you

  38. Thank you . This is really great

  39. Great job. Thanks for the plugin.

  40. I am not familiar with PHP. Any step by step instructions for getting this into the sidebar? It doesn’t seem like it would be too difficult but I have yet to get anything to display. I do know it is installed correctly.

  41. @Scott @Dave: Once fmTuner is installed, activated, and set up (enter your Last.fm username in the fmTuner Settings page), open up /wp-content/themes/default/sidebar.php with a text editor like Notepad or TextMate. Around line 53, add in:
    <li><h2>Tunes</h2>
    <ul>
    <?php if(function_exists('fmtuner')) { fmtuner(); } ?>
    </ul>
    </li>

    Save the file, and reload your blog in a web browser. This will call up fmTuner within your sidebar!

  42. Hey Collin,

    have you looked into my comment/request from Sep 08 yet? Any chance you’ll be doing it?
    If not, would you mind if I used you plugin as a basis for doing it myself with possibly re-releasing it?

    Late happy new year to you! :)

  43. I love your plugin and as one of those “intermediate” designers out on the web, I wrote a tutorial to help those who would like to skin their album artwork to appear as something other than a basic square.

    Styling fmTuner plugin to Use Custom Album Artwork

    http://www.aunkor.com/?p=12

  44. @AgentSmith: I haven’t yet. If you’re feeling ambitious, go right ahead with your modifications. I’d appreciate a link anywhere on the finished version, but it’s not required :)

    @Violet: Cool — great writeup! Thanks for the links, too. I’m glad fmTuner is working out for you.

  45. [...] you are running wordpress (if not, you should be), go download the fmTuner plugin and install it in your plugins directory on your server.  Next, activate it.  Find the fmTuner [...]

  46. Does this work on pages or posts?

    If not, know of any Lastfm Wordpress plugin that does?

    Thanks,

  47. @boogieboa: fmTuner will work on pages, posts, etc. — just about any WordPress-handled template. Since song data is cached, it doesn’t hit Last.fm every time, keeping your site snappy.

  48. What’s the code used to show this as a list within a post? I thought the tags would work within a post but they didn’t.

  49. I’m unable to get the tuner to work on my website… I’m using the code supplied and it doesn’t display anything! please advise

    I am using the latest version of wordpress

  50. @boogieboa: The tags won’t work within a post; They only work with fmTuner’s settings. In the fmTuner settings screen, you use the tags among HTML to build the layout for each displayed track.

    Then, wherever you insert if(function_exists('fmtuner')) { fmtuner(); } (between PHP tags), the list of tracks will get displayed. You can even use this call inside index.php or single.php to display your tracks in every post.

    @Nate: Any idea which version of PHP you’re using?

  51. I’ve noticed that alot of the songs that i listen to won’t show. I’m not sure why they don’t show though, since the song and artwork gets scrobbled by my last.fm-app. And since the app recognize the artwork, shouldn’t the plugin show it as well?

  52. @Erik: Not necessarily. fmTuner only shows tracks with artwork supplied by Last.fm, which may not be every song you listen to. Your player is likely showing artwork embedded in the music file, whereas Last.fm has its own set of images. If you’re using the [::image::] tag and Last.fm has no artwork for that particular track, it won’t be shown. Basically, fmTuner errs on the side of “making your site look good” versus “show every single song”.

  53. I tried installing your plugin on my Wordpress 2.7 installation. Unfortunately I get zero output, as MadCat already described. My XML file is being correctly updated every 15 minutes and the content looks correct for me. Here a snippet from my XML file:

    Eisbrecher
    Herzdieb

    But nevertheless no output in my sidebar (that’s why it’s not active at the moment). What else could be the cause? I tried using your defaults and copied the code to several locations in my theme.

  54. Hey,
    I am having the same problem as Ulf using Wordpress 2.7.1. I do have to admit I am deficient for web-coding but it seems simple enough to add this to sidebar.php as part of a list. I am using
    Tunes

    mayble the ul is supposed to go before the li? Any help would be greatly appreciated.

  55. All fixed, sorry about the confusion. Works great! There isn’t a way to shrink the image size though is there?

  56. So, Ryan, how did you fix it?

  57. I’m still attmpting to replicate the no-output issues. One possibility is that you’ve listened to a bunch of tracks with no images and you are using the [::image::] tags, thus there are no tracks with “worthy” data. I could potentially add a placeholder message or HTML for when this occurs.

    @Ryan: The best way to shrink the images would probably be to inster them inside an IMG tag with a defined size, say width=”32″ height=”32″. Then, the user’s browser will scale them as instructed.

  58. Ulf, I am not sure this is correct in any way as far as coding style goes…..but, I have to place this outside of the “if” for the dynamic side bar in sidebar.php.

    <?php endif; // end primary sidebar widgets ?>

    </ul>
    <hr size=1>
    <h3>What I am Listening To</h3>
    <em>via <a href=”http://www.last.fm/listen/user/rfrankel/personal” target=”_blank”>My Radio Station</a></em>
    <?php if(function_exists(‘fmtuner’)) { fmtuner(); } ?>

    </div><!– #primary .aside –>

    Hopefully, this shows up.

  59. Hi, Love the plugin. Quick note, track name seems to break if it includes (or starts with, in my case) a ‘$’ symbol.

    Other than that, loving it :)

  60. [...] Last.fm Plugin for WordPress [...]

  61. I can’t seem to even find mine in the plugins list when I’ve uploaded it. I’m not that technical unfortunately so I’ll have to try something else… :(

  62. hi,

    I installed the pluggin, it displays on homepage but I cannot select or get music. The only thing you see is the image of the artists album
    Can anyone help me?
    irene

  63. Love the plugin and will be using it on my new theme i’m working on for my personal blog. But i seem to have stumbled on a little problem as i’m trying to display the last 20 recent tracks but it seems to only return 10.

    Its fine on Loved and Top Tracks but Recent just returns 10. If you want any debug info please just drop me a mail.

  64. @Phunky: Last I checked, Recent Tracks from Last.fm only returns 10. Do you know of any tools that return more than 10? If so, I could figure out how they get more than 10 and do the same.

  65. @Phunky: I did some more research, and found out that Recent Tracks can in fact show more than 10; you just have to ask Last.fm for more. I’ve updated fmTuner to 1.0.6 to do just that. This should take care of it!

  66. @Collin: Fantastic :D makes my funky little disk shelve look much better now! Great stuff!

  67. This is a very nice plug in, great work! Unfortunately, you need some basic HTML / CSS skills to make it work properly. Is there a way that you can make a basic widget based template?

  68. @N1kname: I’m working on widget support for an upcoming release. However, I’ve never actually used WordPress widgets before, so it’s entirely new territory for me :-)

  69. Collin: If you would like a hand with it i’d be more than happy to help out. I had planned on making the CD Shelf on my blog into a widget anyway.

  70. fmTuner: A Last.fm Plugin for WordPress | Command-Tab great article thank you.

  71. what’s the info on the 1.0.7 build?

  72. Hey Collin,

    I’ve been having this issue where fmTuner will randomly decide to display some random number of tracks less than what I have it set for (6). I just looked at my site to find it displaying 1 track… previously it happened and displayed 3 tracks. Any ideas?

  73. @Brian: I’ve seen this happen when using the [::image::] tag, as fmTuner runs out of tracks supplied with album art before reaching the limit. I’ve increased the “buffer” range that gets pulled from Last.fm in the 1.0.6 release, but it wouldn’t be hard to do this by listening to songs in sequential mode (e.g. you listen to a few songs with artwork, then start a new album which has track info but no artwork, pushing the ones with artwork further and further “out of view”). I tried to work this into the design a little bit, by calling that number a “limit” instead of a hard “show me X number of tracks”.

    The alternatives are:
    - Fetch even more tracks in the hope of hitting ones with artwork, or…
    - Employ a placeholder album art image as opposed to skipping the track entirely

  74. Thanks Collin. I thought of doing the blank artwork deal but was initially against it. That’s actually the route I’ve gone for now. You said “fetch even more tracks” which I knew to do, but it was kind of causing me to panic because my tracks were displaying in an area of my site layout that’s not flexible. Still haven’t made a final decision, but for those folks who are having the same dilemma, Collin is right, you need to fetch more tracks. The catch is if you don’t want the number of tracks displayed to be random, fetch a high number, define height/width for each in css, and then set the containing to “overflow: hidden”. So there’s my solution, though now I don’t know if I want to get rid of blank artwork or not.

  75. hey there,
    i’m having the dreaded ‘failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden’ issue.

    i’ve tested for curl, got this;

    array(9) {
    ["version_number"]=>
    int(463620)
    ["age"]=>
    int(3)
    ["features"]=>
    int(1565)
    ["ssl_version_number"]=>
    int(0)
    ["version"]=>
    string(6) “7.19.4″
    ["host"]=>
    string(17) “i686-pc-linux-gnu”
    ["ssl_version"]=>
    string(14) “OpenSSL/0.9.8b”
    ["libz_version"]=>
    string(5) “1.2.3″
    ["protocols"]=>
    array(8) {
    [0]=>
    string(4) “tftp”
    [1]=>
    string(3) “ftp”
    [2]=>
    string(6) “telnet”
    [3]=>
    string(4) “dict”
    [4]=>
    string(4) “http”
    [5]=>
    string(4) “file”
    [6]=>
    string(5) “https”
    [7]=>
    string(4) “ftps”
    }
    }

    so, sent my webhost an email re;

    allow_url_fopen`=”On”

    and got this;

    Hi,
    The only access you have to turn on server based applications like that would be the .htaccess file in the public_html folder.

    am i even ‘able’ to run that command(?) in something like an .htaccess file???

    i’d REALLY like to get this up and running, so any help you can give would be very much appreciated.
    thanks in advance….
    Jas

  76. Good plugin, but lastfm work only for PAY in Italy :-(

  77. Well…I have it installed & would like to use the overlays from komodomedia.com but I absolutely cannot figure out how to make it work. Nor can I figure out how to make a nice looking display. The alt tag is not working to display the name of the song that I’ve listened to for me, either.

    http://www.sogroovynow.com/music/

    I placed it here so I could work on tweaking it & seeing if I could figure out the album overlays but as you can see…not much happening.

  78. [...] fmTuner Next up we have fmTuner, which retrieves song inform­a­tion from your Last.fm pro­file and pub­lishes them to your Word­Press theme. In much the same way as FlickrRSS, you only have to enter your user­name and options to dis­play. For those won­der­ing, the dis­play format I’m using to show the tracks to the very right of this post is <li class="lastfm-item"><a href="[::url::]">[::artist::] – [::title::]</a></li> [...]

  79. Ok,

    I’ve downloaded the plugin and I have a Last fm account, but I’m finally ready to admit that I’m in way over my head. Can some one walk me through “what” I put “where” and in what order. I can’t actually figure out how to make the player show up anywhere on my page. Just assume I don’t have any idea what I’m doing. Because I don’t. Thanks – I’m getting desperate.

  80. Am getting this error

    Warning: file_get_contents(http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=bigbrova&api_key=ff0eaca3b7e2660755d6c652af7b0489&limit=19) [function.file-get-contents]: failed to open stream: Permission denied in /home/www/myhost/wordpress/wp-content/plugins/fmtuner/fmtuner.php on line 198

    what am I doing wrong .. i tried changing the permission of fmtuner.php to 755 still no show

  81. Hey
    anyone know how to resolve my problem?
    Look here
    http://daysofsophia.zxq.net/?p=315

    Thanks in advance

  82. Hi–great plugin–I love the ease of use and customability, though I don’t understand why there’s the limitation of displaying track info only for songs that have last.fm artwork. I’ll play around with this to see if I can work around that so that every track is displayed (I don’t use the images since the ones last.fm chooses to display are usually not the right ones).

    Also–is there any way to have the plugin auto-update without the page having to be refreshed?

    Thanks again for your work!

  83. @Chris: fmTuner will display all tracks if you’re not using the [::image::] tag. Only when you’re using it does it skip the ones without artwork. It assumes that if you’re using the [::image::] tag, you intend to show off artwork, so it leaves out ones that don’t have something worth showing. Otherwise, it will display everything, uncut.

  84. Verry nice plugin!
    I would love to be able to click on the poictures and get to the page on last fm, so people dont have to copy and pste names.

    But as for that its nice work, thanks for sharing!

    Droid Boy

  85. Forgive me, i actually read the description and found out how it works :-)

    THanks again :-)

  86. Loving this plugin!

    My query was about styling it as I notice on your homepage you’re able to keep each album in it’s own li class? How do you do this to align the albums vertically rather than horizontally?

    Thanks! (And apologies if I’m just not being very clever!)

  87. I had 9 albums with no art work in a row. is there no way to load a default album image if no album image is available? this plugin is a pretty big part of the design of the footer on our site. so it looked like our site was broken when the 9 albums had no covers.

  88. @Daniel: Right now, there’s no official way to do that, but it’s been requested enough that I’m working on v1.1 which will do just that :)

  89. [...] are closed on this entry — any bugs or other issues should be reported on the original fmTuner page. Thanks!) This entry was posted on Monday, February 1st, 2010 at 2:09 pm and is filed under [...]

  90. Hey, great plugin! Very fun and easy to style with some nice CSS.

    I am however experiencing a little problem.. It works fine and everything, but as of now it refuses to show my recent tracks and only 1 of my loved ones, while i have plenty.
    I cleared my cache multiple times and even viewed it on another computer. It does show a couple of recent tracks, thought yesterday this was 5 and today it is 2. Very odd.

    All my settings still seem to be set correctly. With 8 showing max. Checked my username like 10 times, and its supposed to update every 30 minutes.

    Any idea what might be wrong?
    Joey

    PS: I’m sorry if this is not the correct place to post this.

Leave a Reply