Let Slack tell you what songs are currently playing in the office

At Earth People, there’s always music in the air (and the birds sing a pretty song).
Most of the stuff we play is fairly unknown to most of us, and in many cases only played once, ever.

To get rid of all the “Hey what’s this song”-chatter or Slack, I made a litte script which we run as a Slack Command.
The script just checks all the Last.fm-feeds of the people usually playing music, and returns what’s on.

Screenshot 2014-10-15 16.51.02

By no means magic, but adds another bit of homey feeling to Slack.
Here’s the Gist, be our guest.

<?php

date_default_timezone_set("Europe/Stockholm");

require 'vendor/autoload.php';

use GuzzleHttp\Pool;
use GuzzleHttp\Client;

$client = new Client();

$users = array('suprape','musikmarskinen','dafeather','brunobrandstrom','Algoritm','mjelle','hjalle','johannagrip','tumde');

$requests = array();
foreach($users as $user){
	$requests[] = $client->createRequest('GET', 'http://ws.audioscrobbler.com/2.0/', [
		'query' => array(
			'method' => 'user.getrecenttracks',
			'limit' => '5',
			'api_key' => 'GetThisFromLastFm',
			'format' => 'json',
			'nowplaying' => 'true',
			'user' => $user
		)
	]);	
}

$results = Pool::batch($client, $requests);
$nowplaying = array();
foreach ($results->getSuccessful() as $response) {
	$recenttracks = json_decode($response->getBody()->getContents());
	if(isset($recenttracks->recenttracks->track)){
		foreach($recenttracks->recenttracks->track as $track){
			if(isset($track->{"@attr"})){
				$temp = new StdClass();
				$temp->artist = $track->artist->{"#text"};
				$temp->title = $track->name;
				$temp->album = $track->album->{"#text"};
				$temp->image = $track->image[3]->{"#text"};
				$nowplaying[] = $temp;
				unset($temp);
			};
		}
	}
}

header('Content-type: text/plain;charset=utf-8');
echo "Verkar som att ".count($nowplaying)." låtar spelas på kontoret just nu:\n";
foreach($nowplaying as $track){
	echo '- "'.$track->artist.' - '. $track->title.'"';
	if($track->album){
		echo ' från skivan "'.$track->album.'"';
	}
	echo "\n";
}

SXSW lineup helper

We’re going to Austin again in March, for SXSW. It’s beyond great when it comes to live music. And tacos. But their official schedule is impossible to use due to the shear amount of gigs.

Two years ago we created a little tool for ourselves and our friends called LASTSX.WS which mashed the lineup with their last.fm account. This got shut down by the SXSW lawyers due to brand infringement in the URL. So when setting it up this year we removed any references to SXSW in the URL.

The end product is far from perfect, but it was a quick hack and it works on our machines™. Enjoy!

http://artistsyoumightlikeinaustinmarch2014.earthpeople.se

(Ok this is a tech blog so here’s what we used: PHP5.5, Nginx, Memcached, Curl.)

Line-out scrobbler – when DJ’ing

When DJ’ing at Debaser Slussen yesterday, we decided to hook up the Line out scrobbler to the DJ mixer. I knew that Echonest wouldn’t be able to resolve all weird stuff we play, but was hoping for at least 70% success rate. Unfortunately we had a resolve rate of about 20%, which make our little hack project quite a disappointment. We also had 3 incorrect resolves under the 7 hour long DJ set.

According to Echonest, the catalogue is only about 150 000 songs, and until this grows substantially, this project will be put on hold.

Here’s a clip of us in action last night:

Here’s the last.fm feed we scrobbled to:
http://www.last.fm/user/fredagsbiten

 

Line-out scrobbler

for years i’ve been trying to hijack music recognition services like shahzam to be able to recognize music. i’ve finally got this working thanks to the fine guys at echonest, who kindly provide a proper api for this. my proof of concept is running on a spare macbook.

here’s how it works on the mac atm:
1. the os x automator runs in a 90 second loop, recording audio with quicktime and then running a cli php script.
2. the php script first converts the recorded .mov file to .mp3 with ffmpeg/lame
3. the php script then runs the echonest binary for music fingerprinting, which generates a json string
4. part of the json string is sent via curl to the echonest service and (hopefully) resolved
5. echonest returns artist, title and a unique id. this id is saved i a recent-log so that the php script can skip a run if it runs 2 times during the same song
6. artist and title are curled back to our lamp-server, where we save all plays in a database (mongodb atm)
7. artist and title can then be sent to any service you wish to interact with

making this projekt was pretty straight forward, except for a minor obstacle which took me a few hours to figure out. it turns out that the echonest binary calls ffmpeg internally, and for some reason automator couldn’t find ffmpeg in it’s $PATH. when i realized this the fix was done in a second, i just needed to make a symlink from the $PATH automator used to where i had ffmpeg locally.

next step: will try this a few days and see how well it performs. if it’s good enough i’ll buy a tiny linux box and give it a pair of rca jacks.

links:
the earth people account on last.fm which we scrobble vinyl to atm
the awesome echonest service