Skip to content

Instantly share code, notes, and snippets.

@imlucas
Created May 18, 2009 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imlucas/113795 to your computer and use it in GitHub Desktop.
Save imlucas/113795 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
require_once dirname(__FILE__) . '/phpresolver/playdarresolver.php';
/**
* A resolver for MP3s from Amie Street
* @author Lucas Hrabovsky (lucas@amiestreet.com)
*/
class AmieStreetResolver extends PlaydarResolver
{
protected $name = 'AmieStreet Resolver';
protected $targetTime = 800;
protected $weight = 80;
public function resolve($request)
{
$results = json_decode(
self::doRequest('SearchApi', 'find', array(
'artists'=>urlencode($request->artist),
'songs'=>urlencode($request->track))
)
);
$firstSong = $results->songs[0];
if($firstSong->found){
$songMetaResult = json_decode(
self::doRequest('SongApi', 'getSongById', array(
'id'=>urlencode($firstSong->id))
)
);
$song = new stdClass;
$song->artist = $songMetaResult->artist->name;
$song->track = $songMetaResult->title;
$song->album = $songMetaResult->album->title;
$song->source = "Amiestreet.com";
$song->score = (float)1.00;
$song->url = 'http://amiestreet.com/stream/song/'.$songMetaResult->id.'.mp3';
return array($song);
}
}
private static function doRequest($service, $method, $params, $format='json'){
$url = 'http://amiestreet.com/api/v0.1/'.$service.'/'.$method.'.'.$format.'?'.http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Playdar 0.1');
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
$resolver = new AmieStreetResolver();
$resolver->sendResponse($resolver->getSettings());
$resolver->handleRequest(fopen("php://STDIN",'r'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment