Showing posts with label music. Show all posts
Showing posts with label music. Show all posts

Wednesday, December 17, 2008

How to write a playlist maker script

I got an email asking for tips on writing a playlist maker script.

Using PHP, my process was this:
1. Choose a playlist format. My favorite playlists are Windows Media Player WPL files, which use the SMIL subtype of XML. There are tons of other types of playlists. Songbird and Winamp both use M3U, for example. Unfortunately, most playlist file types, including M3U, are not as "smart" as WPL files, in that they want the exact path to a single song on a user's computer, rather than just an artist name or song title. WPL files will take an artist or song name and give you a playlist of everything in your library that matches. I don't understand why Songbird and Winamp don't handle WPL or SMIL files (yet?). After I figured out which playlist format I wanted, I right-clicked a WPL file I'd made, opened it in Notepad, and used it to cut and paste the top, bottom, and repeating bits of the playlist code where needed in the following steps.

2. Find a source of artists or song names you want in your playlist. The best way was to use an RSS feed, but for my iLike and last.fm tag playlist makers, I scraped the source code of some web pages, which is messy, but it works. You can also offer a way to paste in or upload a list of artists.

3. Write an HTML form (called, for example, input.html) that takes user input (like a last.fm username) to get the source you want. The "Submit" button on the form will take you to your playlist making code (playlistmaker.php, for example).

4. Write code to convert your input (such as a last.fm username) into a URL to an XML or HTML file and get that file ready to be used. For example:
$handle = fopen("http://ws.audioscrobbler.com/1.0/user/".$username."/topartists.txt?type=overall", "r");

5. Write code to make an array of only artists or song names using your source. The exact code will vary depending on the source of artists or song names. This is the trickiest part, and I'd give examples of how I've done it, but it's different nearly every time, and I'm sure my ways are not especially elegant. One thing I'd like to do better is parsing the actual XML instead of finding where the artists turn up in the array and using numeric indices to grab the artists or song names.

6. Create a variable that will contain the entire text you want in the playlist file ($wpl, for example). Paste in the top bit of the playlist text. For a WPL file:
$wpl = "<?wpl version=\"1.0\"?>
<smil>
<head>
<meta name="\" content="\">
<title>".$username."</title>
</head>
<body>
<seq>
<smartplaylist version="\">";

7. Write a loop that adds the section of the playlist that repeats for each artist or song name to your playlist variable ($wpl., for example). Concatenate in the artist or song name variable. Make sure you convert HTML characters, as ampersands will render your playlist utterly worthless. For example, where the artist names are in $data[2]:
while ($data = fgetcsv($handle, 1000, ",")) {
$wpl.="<querySet>
<sourceFilter id=\"{4202947A-A563-4B05-A754-A1B4B5989849}\" name=\"Music in my library\">
<fragment name=\"Album Artist\">
<argument name=\"condition\"<Contains>/argument>
<argument name=\"value\">" . htmlspecialchars($data[2]) . "</argument>
</fragment>
</sourceFilter>
</querySet>";
}

8. Finish off your playlist text variable by pasting in the end text of the playlist variable (again, $wpl.). For a WPL file:
$wpl.="
</smartPlaylist>
</seq>
</body>
</smil>";

9. Create a new file containing your playlist variable text as follows:
$handle = fopen("filename.wpl","w");

10. Offer a link to download the new file.

11. Try it out!

Optional tweaks:
12. WPL playlist files offer you the option of finding an artist name that "Contains" the word "Bell" (for example), or finding an artist that "Is" the word "Bell." After the band "Bell" made Belle and Sebastian turn up in a festival playlist I made (oh, the brief crushing excitement), I added a conditional so that if the artist name is 5 characters or shorter, I use "Is", and if it's longer, I use "Contains". It's still inexact, and it's an area I'd like to improve. Handling "The" (Pixies, Beatles, Raveonettes) is another thing I'd like to work out at some point. Here's an example of one of my conditionals where the artist names are in $data[2]:
while ($data = fgetcsv($handle, 1000, ",")) {
$limit=6;
$num=count($data[2]);
for ($i=0;$i<$num;$i++) {
$len[$i]=strlen($data[2]);
if ($len[$i]<$limit) {
$wpl.="<querySet>
<sourceFilter id=\"{4202947A-A563-4B05-A754-A1B4B5989849}\" name=\"Music in my library\">
<fragment name=\"Album Artist\">
<argument name=\"condition\">Is</argument>
<argument name=\"value\">" . htmlspecialchars($data[2]) . "</argument>
</fragment>
</sourceFilter>
</querySet>";
}
else {
$wpl.="<querySet>
<sourceFilter id=\"{4202947A-A563-4B05-A754-A1B4B5989849}\" name=\"Music in my library\">
<fragment name=\"Album Artist\">
<argument name=\"condition\"<Contains>/argument>
<argument name=\"value\">" . htmlspecialchars($data[2]) . "</argument>
</fragment>
</sourceFilter>
</querySet>";
}
}
}

13. Greasemonkey! Using a tiny bit of Javascript, you can put a link to your playlist making code on relevant source pages. Clicking this link will give you the option to look at one of my Greasemonkey scripts. You'll especially want to change:
  • @include to reference the page you'd like to put a link on.
  • The link to the script that makes your playlist.
  • @name
  • @namespace
  • Colors (I'm using last.fm grey. Meh.)

You can grab the username for the last.fm URL they came from by putting this at the top of your playlist maker script (playlistmaker.php, for example):
$url = getenv("HTTP_REFERER");
$elements=explode("/", $url);
unset($url);
$username=$elements[4];
unset($elements);

Here's a zip folder with code for the input form and playlist maker, as well as a Greasemonkey playlist maker for a last.fm listener's most-played artists. This was one of the first things I did when I was learning PHP, so it's far, far, far from perfect. But feel free to use any bits of it you like. I'm not litigious.


I am crawling up a learning curve (Drupal) myself right now, but if you have questions or suggestions, comments are open.

For anyone more interested in making playlists than playlist-maker scripts, my playlist makers are here.

Monday, October 27, 2008

25 Wedding songs



Jonathan Coulton


Ben Gibbard of Death Cab for Cutie- Sasquatch Music Festival, The Gorge, WAspacehindu
The Pipettes
DSC_0095caloomba
Avett Brothers - Matrimony

Blitzen Trapper - Crazy On You [Buy mp3!!!]

Jonathan Coulton - Skullcrusher Mountain [ Buy mp3!!!]

The Boy Least Likely To - Rock Upon A Porch With You
Nada Surf - Always Love [Buy mp3!!!]

Elvis Perkins - While You Were Sleeping [YouTube][Buy mp3!!!]
The Brunettes - If You Were Alien [Buy mp3!!!]

Death Cab For Cutie - All Is Full Of Love

The Brunettes - Mars Loves Venus

Sufjan Stevens - To Be Alone With You

Feist - I Feel It All
Feist - It's Cool To Love Your Family [last.fm]

The Bees - I Love You [last.fm]

Wendy O. Williams and Lemmy Kilmister - Stand By Your Man

Matt Costa - Sunshine
Matt Costa - Sweet Rose [Lyrics]

Foo Fighters - Everlong

Of Montreal - Spoonful Of Sugar

The Pipettes - I Love You [Live][Live][Buy]

Cowboy Junkies - Sweet Jane [Live][Buy Album]

Crosby, Stills & Nash - Teach Your Children

The Velvet Underground - I'm Sticking With You

Gothic Archies - Shipwrecked

Holly Golightly - Your Love Is Mine

The Cure - Love Song

Saturday, May 31, 2008

Why no Sasquatch next year*

I went to the Sasquatch music festival this weekend. As usual, the location is beautiful and the music ranged from good to mind-blowing (another post on the music later). But unless the organizers manage to resurrect John Lennon, I don't plan to go next year. At one point, waiting in some annoying line or other, I said, "I can't wait until next year, when we're NOT going to Sasquatch."

First of all, the price is too high. Usually for festivals, I do a little calculation of how much I'd pay to see each band individually and that decides whether I go. This year, I was so excited about The Cure that I'd bought two (non-refundable Ticketbastard) tickets for all three days before I did the calculation and realized that I wouldn't have paid $75 for any of the days. So again Sasquatch, next year it'd better be zombie Lennon. And if you're messing with necromancy, why not Cobain, too.

The ongoing frat-guy-ization of Sasquatch reached fever pitch this year with some annoying morning-zoo types blaring music and trying to get people to humiliate themselves for free ad t-shirts next to a pitching cage, a corporate SUV (hott!), and a semi truck parked on the lawn where only two years ago, a guy dressed as a banana had done quiet interpretive dance. I missed Banana Man.

And holy shit is the alcohol situation bad. Of course you can't bring your own, and they charge through the nose. PBR was $11. For those prices, I decided to keep my self-respect and stay sober. But having been wildly envious of people who stayed dry in the bar during the hailstorm a few years back, I decided to go into the bar as soon as the crowd started cheering on the rain.

Sure enough, rain started to fall, the crowd started to cheer, and we rushed over to the bar. I was surprised by how short the line to get in was. And yet, we were in line for ten minutes while one gal looked at every ID as though it were an Israeli checkpoint. Then she spent two minutes each putting on a wristband just so.

When I got inside, the gal at the bar carded me again for my $9 mini-Sutter Home. So the hard-won wristband was useless. At that point, I was okay with it. She was nice, and it's a little flattering to be carded when you're 33 years old**. That is, it's flattering every now and then.

We left the tent ASAP (they had the concert showing on little tiny TVs, but no sound on), wherein I got yelled at for carrying out my empty mini-wine for later label use in my wine journal. The Fiance said he understood -- I might get wild and start smashing people over the head with my empty plastic miniature wine bottle.

We came back to the bar when the skies got threatening again. Longer line, even with two additional people on ID duty. One guy waved his bracelet and zipped through. I waved my bracelet at ID Dude #1, he spied my myriad gray hairs, and waved me through. But as I tried to move forward, ID Dude #2 said, in full authoritarian mode, "Your ID! Where's your ID!"

Now, nothing pulls my trigger faster than a mean person.

"This is ridiculous!" I said. "I've been checked!" I said, waving my wristband. "YOU checked me!" I said to the gal who was studiously ignoring the scene I was making. By this time, I'd pulled out my ID (after 12 years, I've no doubt I can do this in my sleep) and been waved through by ID Dude #2. "I'm 33!" I said as I stalked into the bar. "Then act like it," I heard the sheepy obviously-old fattened multitudes who haven't been carded since they were 15 behind me think. Still, I swear to God my tantrum (or probably dozens like it) had an effect. The next day, ID Dudes were circulating in the crowd, giving out wristbands at people's leisure. That'd be fantastic, if the wristbands weren't utterly useless to anyone under forty and 200 pounds.

I decided it'd take a Biblical flood to get me back in the bar, so we just stuck out the brief little rain showers for the rest of the festival. Much more pleasant than the Kafka-esque bar. But more beverage-related hassle awaited! In addition to either cheap or high-quality beer, I enjoy a good cup of coffee. That is, an afternoon without any coffee is an afternoon with a bad headache. On Sunday, they were out of coffee. On Monday, they were out of coffee cups. How do they not want the all-profit $4 they were charging badly enough to ensure they have coffee and cups to serve it in? Market forces. Pfff.

How the Gorge management treats its guests was embodied perfectly in signs on various beverage vendors. "As requested by the artists, all bottle caps must be removed and confiscated upon purchase." Now, people who throw bottle caps should be banned from attending any concert ever, but I am fucking certain Chris Walla did not request that all of his fans be treated like criminal infants (with giant trust funds). But that's exactly the way the Gorge did treat us, every step of the way.

Though nothing, not even the jaw-dropping Battles, was "too loud," I guess this all amounts to: I'm too old to be treated this way (though apparently I don't look it).


*Barring zombie Lennon.

**Thanks for the youthfulness, fat Irish cheeks! I've seen what gravity will do to you come age 50 though. Must mentally prepare.

Wednesday, May 7, 2008

Useful last.fm tools

Last.fm is doing right what Facebook did right -- letting developers use its data to make new applications as they see fit.

I've blogged, ad nauseam, my last.fm Podcast Finder and last.fm Windows Media Player playlist makers (by most-played artists, calendar, and tag).

In the last few days, I've come across a couple cool last.fm tools made by other folks (each causing me brief bouts of crushing envy and despair). One tool improves the mp3 recommendation process, allowing you to subscribe to last.fm mp3 recommendations like they were a blog. And now there's lasttube, which finds videos from artists you play most on last.fm.

These new tools have me curious what other useful gems are hidden in the graphs-and-pretty-pictures mess at build.last.fm.

I'll let you know what I find.

Saturday, April 19, 2008

My obsession with WMP playlists

For programming practice, I've been writing PHP scripts that will turn various lists of musicians into playlists for Windows Media Player.* Basically, you find a list of musicians that you'd like to listen to as a set, put that list in the appropriate script (see below), and out comes a playlist you can open with Windows Media Player to listen to your list of artists. For long lists of artists, this saves a lot of time over the usual method of putting them in one at a time.

The musician lists you can use for this purpose so far with my little tools are:
  • Last.fm Tagged Artists
    *Playlist maker
    *Example data source
    *Example playlist (rock.wpl)
    *Greasemonkey script (for users of Firefox with Greasemonkey installed)
  • Last.fm Calendar
    *Playlist maker
    *Example data source
    *Example playlist (portland408to808.wpl)
    *Greasemonkey script (for users of Firefox with Greasemonkey installed)
  • Last.fm User's Most-Listened Artists
    *Playlist maker
    *Example data source
    *Example playlist (jamidwyer.wpl)
    *Greasemonkey script (for users of Firefox with Greasemonkey installed)
  • iLike User Most-Played Artists
    *Playlist maker
    *Example data source
    *Example playlist (jami.wpl)
    *Greasemonkey script (for users of Firefox with Greasemonkey installed)
  • Eventful Calendar
    *Playlist maker
    *Example data source
  • Comma-Separated Values File
    *Playlist maker
    *Data source is a list of artists only saved as a CSV in Excel or OpenOffice Calc.
    *Example playlist (sasquatch.wpl)

    *I know Windows Media Player is not hip. But unbeknownst to even the tech-savviest, music-lovingest people I talk to, Windows Media Player's playlists will dynamically add and sort music by criteria you set. Instant mix tape! This was far more powerful than the playlists iTunes had back in 2004, when I took my first faltering steps to quit stealing the mp3 files I wanted, I discovered that iTunes had indeed sold me intentionally-crippled aac files that indeed wouldn't play on my phone's mp3 player, and I quit using iTunes in fury.

    So no, I will not be writing anything, ever, for intentionally over-priced, intentionally under-compatible Mac software. I would, however, like to write playlist makers for Songbird or Amarok, when I feel a little more bored of learning more PHP and MySQL and want to learn whatever it is I need to learn to write real programs.


    (Updated to fix links. Check for new playlist makers and updates on my code page.)
  • Wednesday, April 16, 2008

    Good political songs

    Inspired by this cry for help, here are some political songs I've been enjoying lately.

    Apples in Stereo - Stephen, Stephen [YouTube][Buy mp3!!!]
    Don't tell me you've forgotten how brave Stephen Colbert is already.

    Elvis Perkins - While You Were Sleeping [YouTube][Buy mp3!!!]
    Cursory Googling didn't yield a clear answer on whether this song means to Elvis Perkins what it does to me. The song I hear when I listen to this is indeed partly about Perkins' mother's death on 9/11. It's also about the sleeping country awakened that day. Sad, but hopeful, I think.

    But what do I know. It could be about his girlfriend taking a long nap.

    Winterpills - Broken Arm [Buy mp3!!!]
    The lyrics are all over the map, but there's politics in 'em.

    The Chemical Brothers - The Salmon Dance [Buy mp3!!!]
    This is just a fun song about salmon, but up here in the PNW, that's political, innit?

    Nellie McKay - Mother of Pearl [Buy mp3!!!]
    According to Ms. McKay, I'm doubly blessed with no sense of humor, as both a feminist and a vegetarian. Heh heh heh heh heh heh.

    Cocorosie - Rainbowarriors [YouTube][Buy mp3!!!]
    This makes me hippy-dippy freak-folk happy.

    Smog - I Feel Like the Mother of the World [YouTube][Buy mp3!!!]
    This song always reminds me of how my mom used to make us warring sisters sit in the same chair and hold hands as punishment. I think Bush could benefit from closer exposure to Middle Eastern people who are not outlandishly rich sheiks.

    The Thermals - Here's Your Future [Buy mp3!!!]
    More about religion than politics, but then in the "God Bless America (or else)" Bush years, they're not so different.

    Ted Leo - Loyal to My Sorrowful Country [Buy mp3!!!]
    No explanation needed.

    Tokyo Police Club - Your English is Good [YouTube][Buy mp3!!!][Lyrics]
    One this is clear: this song pertains to the future. Because the shocking youthfulness of Tokyo Police Club freaked me the hell out when I first discovered it a couple years ago, I always thought this song was about young people taking over with their kinder, gentler values. Reading the lyrics, it seems like it's more of an indictment of the current people in power.

    Photo strip made by Bordr.

    Tuesday, February 12, 2008

    CSV to WPL

    Here's my first PHP and SQL program, called CSV to WPL. It creates Windows Media Player playlists from comma-separated lists of bands.

    It's a niche program that has football stadiums worth of room for improvement (it's not a beta -- it's an alpha), but I know I'll use it a lot just as it is.

    Update: I did use it a lot, but I've written various improved playlist maker scripts, including a version that allows you to cut and paste a list of artists instead of making a spreadsheet of them.

    Friday, February 8, 2008

    SXSW 2008

    I've been writing a program to take a list of artists and generate a playlist for Windows Media Player that will search your library for songs by those artists.

    My little program works pretty well for me, since I know all its little bugaboos, but it's not ready to share yet. So for now, I can only share the playlists.

    Here's my 2008 South by Southwest playlist (right-click and Save As... to download to "My Documents/My Music/My Playlists", then open with Windows Media Player). Because there are so many artists, if you have a massive library full of mp3s from good blogs like I do, it'll take a while to load. Watch out, though: Windows Media Player sees that, for example, Bell is playing and thinks Belle & Sebastian are playing. Sadly, they're not.

    If your library doesn't include many of the bands playing this year, here's where you can find some mp3s from my favorite bands playing this year. I'll add more when I get time, but I really need to get to work to finish up that playlist program. I have playlists for each day of Coachella, too, but again. Time.


    photo by john vanderslice.
    Blitzen Trapper - Crazy On You [Buy mp3!!!]
    Blitzen Trapper - Wild Mountain Nation [Buy mp3!!!]
    Blitzen Trapper - 40 Stripes [Buy mp3!!!]

    Jens Lekman - Washing Machine
    Jens Lekman - Your Beat Kicks Back Like Death
    Jens Lekman - Black Cab [Buy mp3!!!]


    photo by chromewaves.
    Nada Surf - Always Love [Buy mp3!!!]
    Nada Surf - Where Is My Mind? [Buy mp3!!!]
    Nada Surf - Popular [Buy mp3!!!]

    Vampire Weekend - Oxford Comma [Buy mp3!!!]
    Vampire Weekend - A-Punk

    Menomena - Cough Coughing [Buy mp3!!!]
    Menomena - Wet and Rusting [Buy mp3!!!]
    Menomena - Rotten Hell


    photo by Pupkin.
    Yeasayer - Sunrise [Buy mp3!!!]
    Yeasayer - Wait for the Summer [Buy mp3!!!]
    Yeasayer - Germs [Buy mp3!!!]

    Tokyo Police Club - Citizens of Tomorrow (Space Ballad Version)
    Tokyo Police Club - Nature of the Experiment [Buy mp3!!!]
    Tokyo Police Club - Your English is Good [Buy mp3!!!]

    kexp bbq
    photo by chona kasinger.
    The Blakes - Two Times [Buy mp3!!!]
    The Blakes - Pistol Grip [Buy mp3!!!]
    The Blakes - Don't Bother Me [Buy mp3!!!]

    White Denim - ShakeShakeShake

    The Presidents of the United States of America - Kitty [Buy mp3!!!]
    The Presidents of the United States of America - Peaches


    photo by imjustincognito.
    Clap Your Hands Say Yeah - Some Loud Thunder [Buy mp3!!!]
    Clap Your Hands Say Yeah - Underwater (You and Me) [Buy mp3!!!]
    Clap Your Hands Say Yeah - Love Song No. 7 [Buy mp3!!!]

    Yo La Tengo - Nuclear War

    The Clutters - Oh [Buy mp3!!!]

    Basia Bulat - I Was a Daughter [Buy mp3!!!]
    Basia Bulat - Snakes and Ladders [Buy mp3!!!]

    Diplo - Work Is Never Over

    the black lips
    photo by johnnyalive.
    The Black Lips - Not A Problem [Buy mp3!!!]
    The Black Lips - Buried Alive
    The Black Lips - Dirty Hands [Buy mp3!!!]


    Laura Gibson - Hands in Pockets [Buy mp3!!!]
    Laura Gibson - Come by Storm


    photo by jessicalea.
    Greg Laswell - Girls Just Want To Have Fun [Buy mp3!!!]
    Greg Laswell - Sing, Theresa Says [Buy mp3!!!]
    Greg Laswell - Days Go On

    The Kills - Love Is A Deserter (Simian Mobile Disco Mix)
    The Kills - Fuck The People
    The Kills - No Wow


    photo by 'Lil.
    Mark Kozelek - What's Next To The Moon [Buy mp3!!!]

    The Raveonettes - Love in a Trashcan [Buy mp3!!!]
    The Raveonettes - The Christmas Song
    The Raveonettes - Here Comes Mary

    White Williams - New Violence


    photo by savemejebus.
    The Little Ones - Lovers Who Uncover [Buy mp3!!!]

    Capgun Coup - My Tears Cure Cancer [Buy mp3!!!]
    Capgun Coup - Bobby Chops and the Do-Gooders


    photo by vern.
    The Cribs - Men's Needs [YouTube][Buy mp3!!!]
    The Cribs - Hey Scenesters! [Buy mp3!!!]
    The Cribs - Another Number [Buy mp3!!!]

    Division Day - Enjoy the Silence
    Division Day - Every Shining Time You Arrive


    photo by mediaeater.
    British Sea Power - Tugboat

    Asylum Street Spankers - You're a Mean One Mr. Grinch [Buy mp3!!!]
    Asylum Street Spanker - Beer

    Bodies of Water - These Are The Eyes [Buy mp3!!!]


    photo by akmal-naim.
    Foreign Born - Union Hall [Buy mp3!!!]
    Foreign Born - The Nights Tall
    Foreign Born - Don't Take Back Your Time

    Cloud Cult - Alien Christ
    Cloud Cult - Car Crash
    Cloud Cult - Living On The Outside Of Your Skin

    Zookeeper - Tax Collector
    Zookeeper - I Live In The Mess You Are

    Richard Thompson - Dad's Gonna Kill Me


    photo by bumpershine.
    The Weakerthans - Virtute The Cat Explains Her Departure [Buy mp3!!!]
    The Weakerthans - Plea From A Cat Named Virtute [Buy mp3!!!]
    The Weakerthans - Night Windows [Buy mp3!!!]

    Simian Mobile Disco - It's the Beat

    Black Mountain - Tyrants [Buy mp3!!!]

    Handsome Furs - What We Had
    Handsome Furs - Dead + Rural
    Handsome Furs - Snakes on the Ladder

    The Low Budgets - Caveman

    The Album Leaf - Always for You
    The Album Leaf - Writings on the Wall
    The Album Leaf - On Your Way

    An Albatross - The Revolutionary Politics of Dance

    The Cave Singers - Seeds of Night

    The Two Man Gentlemen Band - William Howard Taft

    The Stills - Still In Love Song
    The Stills - In The Beginning

    Throw Me The Statue - Yucatan Gold
    Throw Me The Statue - Conquering Kids
    Throw Me The Statue - About to Walk

    Passengers - Miss Sarajevo

    Man Man - Black Mission Goggles
    Man Man - Van Helsing Boombox

    The Minutemen - History Lesson - part II

    The Swell Season - Cactus

    The Strugglers - The Cascade Range

    Holy Fuck - Lovely Allen

    Sean Hayes - Same God

    Born Ruffians - Knife
    Born Ruffians - I'm One of Those Girls

    Jenny Owen Youngs - Fuck Was I