Tuesday, December 7, 2010

How to upload to Freebase part I: domains and types and properties, oh my!

I've been admiring the Wikipedia of databases, Freebase, from afar for a long time. I've kept my distance because if you think learning wiki syntax is a challenge, try figuring out where to even put factoids about your favorite books or musicians on Freebase. If you want your data to be useful to more people than just yourself, though, it is critical that you get the organization right. In honor of Open Data Day last weekend, I've decided to finally figure out how to upload data to Freebase (instead of adding three things by hand and giving up when the knowledge that I could add 1000 with a little PHP gets too unbearable).

The first step when you'd like to add data to Freebase is pretty easy: determine if your data would be useful to other people, and if you have a right to upload it. If the answer to both is yes, proceed!

But then we're on to step 2 -- where does your data belong? You need to determine your data's structure. My first through tenth passes at adding to Freebase probably went through the Basic Concepts wiki, which falls prey to the downfall of many a wiki page -- really bad organization. (It looks like someone played a hand of Yahtzee with all the abstract concepts you need to understand to put your data in the right place on Freebase, then wrote it up in wiki form. I'd re-organize, but every attempt to cut down redundant information and leave things in reasonable order on Wikipedia has left me reversed, scolded, and frustrated.)

So let me try to clarify here (feel free, Freebase wiki editors, to grab any content that's useful, but please don't just sprinkle it hither and thither within the page).

My first hope that I might make sense of Freebase yet came from the Freebase Schema Explorer app.

Just the name gave me hope. The schema is the structure of the data, so a schema viewer is just what I was in the market for.

Right away, I saw that Freebase data is organized in domains, like Books (accessed at http://www.freebase.com/view/book).



Domains (like Books) have types, like Poem, Short Story, and Book (accessed at http://www.freebase.com/view/book/book). This could be confusing, because other users, probably baffled by the wiki like me, have added things like ISBN and Book Character as types of books. I know we're in data hippie land and everyone is a special flower, but that's frankly wrong. "Book Character" is not a type of book.



Types (like Poem, Short Story, or Book) can have both instances and properties, accessed at http://www.freebase.com/view/book/book. For the domain Books of type Book, an instance would be something like The Catcher in the Rye. (It seems that Freebase calls instances "topics", but the Schema Viewer nails it better with "instance," I think.) Examples of book properties include Characters and Genre.



For the data I'll probably add to Freebase first -- podcasts -- the domain is Broadcast (/broadcast), with the type Podcast Feed (http://www.freebase.com/view/broadcast/podcast_feed).

As of this writing, there are 2,584 Podcast Feed instances/topics. Their properties include Name (example: Wired's Alt Text), Image, and Average Media Length. Already I see a flaw, which I'll need to correct if I'm going to use this data for my Podcast Finder -- there's no podcast creator (or Podcaster) property listed. And the Freebase wiki noted that one can't edit a schema created by another Freebase user -- I'd have to duplicate all 2,584 instances/topics and set up my own schema.

Will I figure out how to add the Podcaster property? Will I duplicate the Podcast Feed type? Will I lose my Internet connection because I stayed up too late blogging, slept through a WebEx, and lost my job?

Find out in the next installment of this exciting series, wherein I shall explore yet another query language, MQL, and hopefully start adding all information ever to an easily-queried free online database.

(Or I'll take another two years off blogging and come back in 2012 blogging about how excited I am about our new lady President. Or arsenic-based space aliens. Stay tuned!)

Sunday, May 24, 2009

Comparing Amarok and Songbird

I love the tremendously uncool Windows Media Player (WMP), primarily because it has portable smart playlists. A WMP smart playlist can go with you to a new computer and still find music by the artist(s) of your choice, whereas an iTunes Smart Playlist(TM) will be looking for specific file locations. That makes a huge difference in what you can do with your music.

I've hoped for a while that open source music players for Linux like Amarok and Songbird would implement smart, XML based playlists instead of playlists that save file locations. Unfortunately, neither does yet. But while I was checking out their playlists, I decided to compare Songbird and Amarok on a few other criteria.

In addition to XML playlists, both players lacked a couple of other important features. Neither Amarok nor Songbird showed any interest in syncing music to my SD card, and neither deleted a file from my computer when I deleted it from my library.

After an initially more difficult install, Songbird edged out Amarok for usability. Amarok had too many "little" bugs (like not playing mp3s or scrobbling to last.fm). Sure, you can probably fix the problems, but they worked out of the box with Songbird. Amarok wins handily in terms of podcast support, but it wasn't enough to put it over the edge as the media player I'll keep.

Songbird
Pros: Plays mp3s right after install. Scrobbles to last.fm right after install.
Cons: Not easy to install. Podcast support not as strong as Amarok's. Doesn't play wav files.

The installation process was not as easy as Amarok's (in fairness, I didn't have to tweak Songbird afterward to get mp3s and scrobbling to work).

I had a brief flash of hope that I'd get my SD card synced by installing the FolderSync add-on. But after installation, I couldn't find any evidence of FolderSync's existence, and I couldn't understand the directions.

Songbird kind of has podcast integration through subscriptions, but nothing showed up with updated Onion or Buzz Out Loud subscriptions. Apparently not all feed formats work.

There are other cool things I haven't explored about Songbird: web pages as playlists, love and ban for last.fm right in the player, Flickr pics related to music you're listening to, Twitter integration.

Songbird Summary
Plays mp3s after install? Yes
Last.fm scrobble? Yes, by default
Truly smart playlists? No, just iTunes-style dropdown playlists
Sync SD card? Nothing obvious there by default
Integrated podcasts? Kind of
Rip CDs? No
Delete file when removing from library? No
Plays wav files? No
Apt-get install? No

Amarok
Pros: Easy install with package manager. Podcast integration better than Songbird's. Plays wav files.
Cons: Doesn't play mp3s right after install; you have to install an extra package. Last.fm scrobbling requires work.

To get mp3s to play (!), I had to install libxine1-ffmpeg. That's a number 1 after libxine, not a letter l.

Though it is integrated, I never got last.fm scrobbling to work. Apparently on Ubuntu 9.04, you have to upgrade Amarok, but after an hour hacking at it, I gave up.

Amarok added The Onion podcast using its integrated OPML database and Buzz Out Loud via pasting in the RSS feed. Both had updated and showed files within an hour.

Amarok Summary
Plays mp3s after install? No!
Last.fm scrobble? In theory
Truly smart playlists? No, just iTunes-style dropdown playlists
Sync SD card? Nothing obvious there by default
Integrated podcasts? Yes
Rip CDs? No (but maybe with a hack)
Delete file when removing from library? I think no
Plays wav files? Yes
Apt-get install? Yes

Saturday, May 16, 2009

Tools of the Twitter famous

I enjoy Twitter, but I'm looking to improve a few things. The worst flaw I've found is that when people write me directly using my username or a direct message, I don't see it for days. I don't click the individual links to show me those messages. So through sheer bad design, I miss the parts of the Twitter conversation that are most important to me.

Another flaw is keeping track of followers. If someone is hitting me with a lot of sandwich tweets or a wall of twenty automated tweets in a row, I want to weed them out. If they're following me back, though, I'll think twice about unfollowing, as it might insult them and I'd probably lose a follower out of it. Unfortunately, there's no integrated way to see if people follow you back.

And then there's design. I like the simplicity of the Twitter interface, but I'd like to at least try something besides a single, static, tiled image.

Perhaps the many, many Twitter tools available could solve my problems. I decided to look first at tools used by Twitterers I like with more than a thousand follows.

This is unscientific, of course. Lance Armstrong, Rainn Wilson, and Martha Stewart could tweet using stone tablets and they'd get thousands of followers. But tools used by busy people probably at least provide efficiency.

In the end, none of the tools I tried solved the three main problems I set out to correct. But one tool, TweetDeck, at least shows replies and direct messages on a single page by default.

Here is a list of tools used by twitterers I follow who have more than 1000 followers.

TwitterBerry
The most popular Tweeter I follow is Lance Armstrong, with 860,957 followers. As of this writing, he had recently used both TwitterBerry and Tweetie. TwitterBerry, as suggested by the name, is a tool for BlackBerry mobile devices. If you have a BlackBerry, TwitterBerry is good enough for Lance Armstrong, so you should probably check it out. I don't have a BlackBerry and don't want one, so I won't review TwitterBerry. Other tweeters who use TwitterBerry: GarinKilpatrick (18,097 followers), SistersTalk (5,276 followers), and PGHolyfield (1,048 followers).

Tweetie
Tweetie is like TwitterBerry, but for iPhones. Popular users of Tweetie include Lance Armstrong (860,957 followers), Rainn Wilson (665,607 followers), Trent Reznor (515,302 followers), Stephen Fry (500,730 followers), ElijahManor (25,048 followers), GeekyGirlDawn (2,274 followers), Verso (2065 followers), TheSuicideKing(1,480 followers), and EvilSpinmeister (1,400 followers).

As with the BlackBerry, I don't have an iPhone and don't want one, so I didn't check this out, but if you have an iPhone, this app seems to very popular with quality tweeters.

Mobile web
Martha Stewart (620,374 followers) is the third most popular twitterer I follow. She posts frequently using "mobile web", which just increases my fondness for her that much more. She's, what, late sixties? and instead of thinking she needs a separate tool to "do this Twitter whatsit" like most intentionally-obtuse older celebrities, she just fires up IE or Opera on her phone and does it. Bravo! Wildly popular feline twitterer Sockington (506,681 followers) also uses the mobile web interface.

TweetDeck
In addition to Tweetie, Trent Reznor uses TweetDeck. TweetDeck is a tool for any major platform (that is, Windows, Mac, or Linux). Other popular users of TweetDeck are The_GMan (68,246 followers), StyleTime (20,683 followers), DataDirt (10,277 followers), Mur Lafferty (3,290 followers), SawHtoo (3,086 followers), SWhitley (2,292 followers),

The three-column design in TweetDeck solved my number one problem right away. Within five minutes of finishing my install, I got an @reply from an IRL friend I wouldn't have wanted to miss.

You can also create groups, so you see your most important followers (i.e., your real friends) first.

I need to change my profile pic, though. I used a full-size giant creepy photo of my face, to embarrassing effect in TweetDeck. It's amazing I've ever gotten a followback from a TweetDeck user.

TweetDeck Summary
Clicks required to see replies and direct messages: Zero
Easily see if someone you're following follows you back? No
Works on PC? Yes
Works on Linux? Yes
Send to Twitter, Facebook, or both? Yes
Easily add people to groups? Yes
Easily add RSS feeds? No
Have to install Adobe Air? Yes
Easily manage multiple accounts (not necessarily a good thing)?

Web
In addition to using the mobile web, Sockington is my most popular Twitter follow who frequently uses the plain old web to update. Good to know I haven't been hobbling myself by loading up twitter.com in Firefox to tweet. Other folks who hit the web to tweet: GeraldWeber, BreakingNewz (28,689 followers), Garin Kilpatrick (18,097 followers), Paste Magazine (18,039 followers), Timothy Adam (17,489 followers), Dana Willhoit (17,051 followers), and Steph Agrestra (11,294 followers), DataDirt (10,277 followers), Cloaker (10,205 followers), Alexandre Gervais (8348 followers), SistersTalk (5,276 followers), Jesse Thorn (5,270 followers), PlayTwivia (4,647 followers), Bitch Magazine (4,575 followers), GraphicRiver (3,518 followers), John Roderick (3,446 followers), ApeLad (3,221 followers), SawHtoo (3086 followers), TweetDr (2,610 followers), Go_GetIt (2,470 followers>, TechMemeFH (2,087 followers), BikePortland (1,597 followers), WomanistMusings (1,469 followers), Dave Hill (1,243 followers), WebChick (1,102 followers).

Web Summary
Clicks required to see replies and direct messages: Two
Easily see if someone you're following follows you back? No
Works on PC? Yes
Works on Linux? Yes
Send to Twitter, Facebook, or both? Yes, with work
Easily add people to groups? No
Easily add RSS feeds? No
Have to install Adobe Air? No
Easily manage multiple accounts (not necessarily a good thing)? Yes

Seesmic Desktop
The next most popular Twitterer I follow is Ustream (453,327 followers). Ustream uses Seesmic Desktop, which works on Mac and PC, but apparently not Linux, and looks similar to TweetDeck.

Seesmic's most obvious advantage looks like its ability to manage multiple accounts. That seems spammy and yucky to me, but one person's spammy and yucky is another person's livelihood, I guess.

Though it is not the default setting to show replies and DMs, there are two links to show those, and you can probably set it up to show those without clicking. I never figured out how to add a friend to a friend group.

Seesmic Summary
Clicks required to see replies and direct messages: Two
Easily see if someone you're following follows you back? No
Works on PC? Yes
Works on Linux? No?
Send to Twitter, Facebook, or both? Yes
Easily add people to groups? No
Easily add RSS feeds? No
Have to install Adobe Air? Yes
Easily manage multiple accounts (not necessarily a good thing)? Yes

Twitli
In addition to the web interface, GeraldWeber also uses Twitli, a Twitter tool for Android phones. Now, unlike BlackBerry and iPhone, I do want an Android phone, but as I'm stuck with Windows Mobile until I strike oil or find gold, I can't yet review Twitli.

Ping.fm
My next most popular Twitter follow, ChrisPirillo (61,885 followers), updates using Ping.fm. Ping.fm is an awesome tool that links one social network to another, and you should check it out whether you want to use it for Twitter or not. Someone posting to Twitter using Ping.fm may be using his Facebook status or FriendFeed or blog to post to Twitter. Ping.fm is a little dangerous, as you can end up spamming people you like with multiple links to the same thing, so if you use it, try to keep track of what's going where. And of course, if you want to keep parts of your online life separated, be very careful with Ping.fm.

Ping.fm Summary
Clicks required to see replies and direct messages? N/A
Has easy way to see if someone you're following follows you back? N/A
Works on PC? Yes
Works on Linux? Yes
Has way to send to Twitter, Facebook, or both? Yes
Easy to add people to groups? N/A
Easily add RSS feeds? Yes
Have to install Adobe Air? No
Easily manage multiple accounts (not necessarily a good thing)? N/A

Twitter Tools
After ChrisPirillo, the next most popular twitterer in this "study" is SitePoint (32,918 follows). SitePoint uses Twitter Tools, a WordPress plugin to tweet. This may be very useful for folks with WordPress blogs, but it's somewhat specific to those users. BikePortland (1,597 followers) also uses Twitter Tools.

bit.ly
In addition to TweetDeck, Styletime posts using bit.ly's bookmarklet. You put the bookmarklet in your browser toolbar, then click when you find an interesting link you'd like to share on Twitter.

Nambu
In addition to the web, PasteMagazine (18,039 followers) uses Nambu, a desktop Twitter application for Macs. Meh. Rasmus (2345 followers) also uses Nambu.

Twitterfeed
PasteMagazine also uses twitterfeed, which, like Ping.fm, will pipe the RSS feed of your choice to Twitter. Twitterfeed looks more versatile than Ping.fm, in that it seems to take any RSS feed, not just pre-approved ones as on Ping.fm. Such services can be used well with care, but it can also lead to the second most annoying Twitter behavior (after spam follows) -- posting an entire page of tweets at the same time. Like PasteMagazine, Alexandre Gervais (8,322 followers), SistersTalk (5,276 followers), and BitchMagazine (4,575 followers) use twitterfeed so I never noticed until I wrote this blog post. SciSolutions (2,051 followers) uses twitterfeed badly, posting ten updates at a time.

Txt
The most popular twitterer I follow who recently used a text message to update was Cloaker (10,205 followers).

ShareThis.com
In addition to the web and twitterfeed, AlexGervais (8,322 followers) used a ShareThis button at the bottom of a blog post to post to Twitter.

Digg
AlexGervais (8,322 followers) also used the Digg toolbar to post something he saw on Digg to Twitter.

CoTweet
In addition to the web interface, GraphicRiver (3,518 followers) uses CoTweet, a business-oriented tool currently in private beta testing.

Twitterific
In addition to Tweetie, Verso (2,065 followers) uses the iPhone app Twitterific. BikePortland (1,597 followers) also uses Twitterific.

HootSuite
IHeartBrunch (1,586 followers) uses HootSuite.

HootSuite's unique feature seems to be that multiple people with different passwords can post to a single Twitter account.

HootSuite Summary
Clicks required to see replies and direct messages? Two
Has easy way to see if someone you're following follows you back? No
Works on PC? Yes
Works on Linux? Yes
Has way to send to Twitter, Facebook, or both? Yes
Easily add people to groups? No
Easily add RSS feeds? Yes
Have to install Adobe Air? No
Easily manage multiple accounts (not necessarily a good thing)? Yes

Twhirl
Sarah Conner (1,282 followers) uses Twhirl, similar to TweetDeck and Seesmic, but very compact. PGHolyfield (1,048 followers) also uses Twhirl.

Twhirl Summary
Clicks required to see replies and direct messages? Two
Has easy way to see if someone you're following follows you back? No
Works on PC? Yes
Works on Linux?
Has way to send to Twitter, Facebook, or both? No (need Ping.fm)
Easily add people to groups? No
Easily add RSS feeds? No (need Ping.fm)
Have to install Adobe Air? Yes
Easily manage multiple accounts (not necessarily a good thing)? Yes

Twitterfon
TheBuzzByBrian (1,154 followers) uses Twitterfon, an iPhone app.


I'd love to hear about your favorite Twitter tools in the comments.

Monday, February 23, 2009

Blog status update

I'm deciding how best to separate code posts from music posts from angry political rants. Appreciator will return to its originally-scheduled cultural programming soon. Hope to see any readers who've encountered this tumbleweed of a blog then!

Saturday, December 27, 2008

My first Drupal module(s)!

I'd nearly given up learning the Drupal content management system, after it took me two hours to change a font on a static web page. But I needed to procrastinate something even more difficult than changing fonts in Drupal, so I decided to try, try again.

The first interesting thing I wanted to try in Drupal was feed aggregation. I love the idea of feed aggregators like Tumblr, FriendFeed, and Swurl, but I'm unsatisfied with the limitations on what or how many feeds you can use. The output (from Tumblr in particular) can also be rough-looking. Why oh why can't they handle quotation marks in titles right. I'm no regex champion, but I suspect even I, PHP fledgling, could write the fix to that. Surely they've noticed that posts titled "Barack Obama - "Yes We Can"" aren't very appealing? (I had to go out of my way for Blogger to let me make it that ugly.) Finally, I'd like to enhance the output of at least one feed with additional content from my own database, which is completely impossible with Tumblr, Swurl, or FriendFeed.

So I've been checking out Drupal's feed aggregators. I tried Aggregator and FeedAPI my first day using Drupal, so I doubt I assessed their usability fairly. I'll try them again when (if) I understand CCK and Views. But when I tried the ActivityStream module, my enthusiasm for Drupal was restored! Not only did it do significant portions of what I want done (Flickr, last.fm, and delicious feeds), but it looked dead easy to add new feeds by making new sub-modules.

It was indeed dead easy. To add a Goodreads sub-module, I copied and pasted the delicious sub-module. I opened the two delicious files and replaced the word "delicious" with "goodreads". I opened my module list and saw my new module. I turned it on, entered my Goodreads info, and holy shit it worked! My recent Goodreads activity was interspersed with the Twitter, delicious, last.fm, and Flickr info I'd already added. I decided sleep could wait until I made five modules like my Goodreads modules, for Blogger, StumbleUpon, YouTube videos, YouTube favorites, and Hulu.

My new modules are far from perfect. I have a list a page long of improvements I want to make (like handling quotation marks in titles...). But the beauty of Drupal, and open source in general, is that I have access to the code to make those improvements. All I can do with Tumblr is gripe and hope they fix it.

Thus far, it seems to me that in Drupal, it's much more fun doing hard things like feed aggregation than doing easy things like changing fonts. I think this explains why people hate Drupal, then love it. To beginners doing something "easy" like trying to change fonts and put files where they want them, Drupal seems like a ridiculous thing to be excited about. To people who've just done something "hard" that they've wanted to do for years in the space of ten minutes (that's what she said), Drupal seems pretty awesome.

Thursday, December 25, 2008

A very Hulu Christmas

A white Christmas is very nice, but an extremely snowy week-before-Christmas meant my Christmas plans changed to staying in with the cats. We may order Thai food later to honor my husband's Christmas traditions. To honor mine, there must be cornflake cookies, bean dip, and television. The food is achieved, but the t.v. was harder. For starters, I have no television set. Fortunately, the Internet is almost a satisfactory video-watching alternative. Here's what I've tracked down so far.

How The Grinch Stole Christmas
A classic. I haven't watched it all the way through yet, but it was choppy. I paused it to let the whole thing load in hopes of improvement.

Rudolph the Red-Nosed Reindeer
Another classic. Might be choppy.

Bing Crosby - White Christmas
One of my favorite Christmas songs.

John Lennon - Happy Xmas (War is Over)

Trey Parker and Matt Stone - The Spirit Of Christmas
What would Brian Boitano do?

American Dad - Best Christmas Story Never Told
The "War on Christmas" hilariously embodied. On Hulu, so shouldn't be choppy.

American Dad - Most Adequate Christmas Ever
Stan learns a Christmas lesson. On Hulu, so shouldn't be choppy.

santa claus on cribs
Not for children, though they probably won't catch the double entendre.

Elmo & Patsy - Grandma Got Run Over By A Reindeer
There was nothing funnier than this song to a certain ten-year-old in December 1985.

The Simpsons - Christmas Epidsode

Alfred Hitchcock Presents - Back for Christmas
Christmas is about giving.

The Madagascar Penguins - A Christmas Caper

Santa Beats Up Guy In Mall

Tom And Jerry - The Night Before Christmas
I was never that enthusiastic about the super-violent Itchy and Scratchy style Warner Brothers cartoons, but I think this one's okay.

NewsRadio - X-Mas Story
On Hulu, so shouldn't be choppy. I haven't watched it yet, but I'd bet money this is at least 4 out of 5 stars, as all NewsRadios are.

NewsRadio - Stupid Holiday Charity Talent Show
On Hulu, so shouldn't be choppy. I haven't watched it yet, but I'd bet money this is at least 4 out of 5 stars, as all NewsRadios are.

Saturday Night Live - Two A-holes Buying a Christmas Tree

Saturday Night Live - Christmas For The Jews Song

Saturday Night Live - Hanukkah Harry

Saturday Night Live- Two A-holes In A Live Nativity Scene

The Twilight Zone - The Night Of The Meek

Alfred Hitchcock Presents - The Festive Season
Bleak, quality entertainment. On Hulu, so shouldn't be choppy.

Jay Leno - Bizarre Christmas Musicians

The Colbert Report - December 11, 2008

Bones - The Santa In The Slush
I haven't checked out this show yet. Perhaps I'll start with this one. On Hulu, so it shouldn't be choppy.

The Office - Moroccan Christmas
Haven't watched yet. On Hulu, so shouldn't be choppy.

30 Rock - Christmas Special

MadTV- Best of Christmas Sketches
Hit and miss, but worth it just for The Reinfather.

Do They Know It's Christmas?

Full Metal Christmas

Sketchy's Super-Happy Christmas Film
I haven't watched it yet, but stop-motion and Christmas do go together.

Three's Company Christmas

Space Ghost Christmas

Santa Claus Conquers The Martians, Part I
Santa Claus Conquers The Martians, Part II
Santa Claus Conquers The Martians, Part III
Santa Claus Conquers The Martians, Part IV
Santa Claus Conquers The Martians, Part V

The A-Team - Holiday In The Hills

Nestor The Long-Eared Christmas Donkey

William S. Burroughs - The Junky's Christmas

I've only included videos that interest me, but here are links to searches so you can see what I've left out:
Hulu
GUBA
StumbleVideo
YouTube
Dailymotion
FunnyorDie
CBS

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.