public function notifyNowPlaying(SSLTrack $track = null) { $nicecastOutput = <<<EOF Title: {$track->getTitle()} Artist: {$track->getArtist()} Album: {$track->getAlbum()} Time: {$track->getLength()} EOF; file_put_contents($this->getFilename(), $nicecastOutput); }
public function getBuyLink(SSLTrack $track) { $en_api_key = trim(file_get_contents('SevenDigital.key')); $en_url = "http://developer.echonest.com/api/v4/song/search?api_key=%s&format=json&results=1&artist=%s&title=%s&bucket=id:7digital&bucket=id:7digital&limit=true&bucket=tracks"; $real_en_url = sprintf($en_url, $en_api_key, rawurlencode($track->getArtist()), rawurlencode($track->getTitle())); //var_dump($real_en_url); $en_result = file_get_contents($real_en_url); $en_result = json_decode($en_result, true); // var_dump( // levenshtein(mb_strtolower($en_result['response']['songs'][0]['title']), mb_strtolower($track->getTitle())), // $en_result['response'], // $track->getTitle() // ); if (levenshtein(mb_strtolower($en_result['response']['songs'][0]['title']), mb_strtolower($track->getTitle())) < 5) { foreach ($en_result['response']['songs'][0]['tracks'] as $track) { if ($track['catalog'] == '7digital') { $id_parts = explode(':', $track['foreign_id']); $seven_digital_id = $id_parts[2]; break; } } } if (!isset($seven_digital_id)) { return false; } $sd_url = 'http://api.7digital.com/1.2/track/details?trackid=%d&oauth_consumer_key=%s&country=GB'; $real_sd_url = sprintf($sd_url, $seven_digital_id, 'musichackday'); $sd_result = @file_get_contents($real_sd_url); if (empty($sd_result)) { return ''; } //var_dump($sd_result); $xml = new DOMDocument(); $xml->loadXML($sd_result); $xpath = new DOMXpath($xml); $urls = $xpath->query('//track/url/text()'); /* @var $urls DomNodeList */ return @$urls->item(0)->textContent; // $api = new SevenDigitalApi(); // $api->OutputType = 'json'; // $api->ConsumerId = 'musichackday'; // var_dump($track->getArtist() . ' ' . $track->getTitle()); // $results = $api->GetTracksByTitle($track->getArtist() . ' ' . $track->getTitle()); // $resultsObj = json_decode($results); // var_dump($results); // if(isset($resultsObj->response->searchResults->searchResult[0])) // { // return $resultsObj->response->searchResults->searchResult[0]->release->url; // } // return false; }
public function notifyScrobble(SSLTrack $track) { $length = $track->getLengthInSeconds(SSLTrack::TRY_HARD); if ($length == 0) { // Perhaps this entry was added manually. L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Could not guess length. Last.fm will silently ignore the scrobble.', array()); } try { $this->scrobbler->add($track->getArtist(), $track->getTitle(), $track->getAlbum(), $length, $track->getStartTime()); L::level(L::DEBUG) && L::log(L::DEBUG, __CLASS__, 'Sending %d scrobble(s) to Last.fm', array($this->scrobbler->getQueueSize())); $this->scrobbler->submit(); // TODO: caching if scrobbling's down whilst playing. } catch (Exception $e) { L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Could not send %d scrobble(s) to Last.fm: %s', array($this->scrobbler->getQueueSize(), $e->getMessage())); } }
protected function getBeatportURL(SSLTrack $track) { $url = ''; $bp = $this->newBeatportAPIClient(); $artistName = $track->getArtist(); $trackName = $track->getTitle(); $bp_track = $bp->getTrackByArtist($artistName, $trackName); if ($bp_track) { $bp_artist_names = $bp_track->getArtistNames(); $bp_track_title = $bp_track->getName(); $bp_url = $bp_track->getURL(); $bp_track_string = implode(', ', $bp_artist_names) . ' - ' . $bp_track_title; $ssl_track_string = $track->getFullTitle(); L::level(L::INFO) && L::log(L::INFO, __CLASS__, "Found %s at %s", array($bp_track_string, $bp_url)); if ($this->checkMatch($ssl_track_string, $bp_track_string)) { $url = $bp_track->getURL(); } else { L::level(L::INFO) && L::log(L::INFO, __CLASS__, "Rejected %s as a match for %s", array($bp_track_string, $ssl_track_string)); } } else { L::level(L::INFO) && L::log(L::INFO, __CLASS__, "No track found.", array()); } return $url; }
/** * It's an SQL error to provide the wrong number variable bindings to a prepared * statement, so we must trim down the number we pass based on which actually * appeared in the SQL statement. */ protected function getPlaceholdersFromTrack(SSLTrack $track, array $placeholder_map) { $placeholders = array(); if ($placeholder_map[':track']) { $placeholders[':track'] = $track->getFullTitle(); } if ($placeholder_map[':artist']) { $placeholders[':artist'] = $track->getArtist(); } if ($placeholder_map[':title']) { $placeholders[':title'] = $track->getTitle(); } if ($placeholder_map[':album']) { $placeholders[':album'] = $track->getAlbum(); } if ($placeholder_map[':key']) { $placeholders[':key'] = $this->key; } return $placeholders; }
public function __toString() { return 'Track started: ' . $this->track->getArtist() . ' - ' . $this->track->getTitle(); }
public function allTimePlays(SSLTrack $track) { $statement = $this->dbo->prepare("SELECT COUNT(*) FROM history WHERE title=:title AND artist=:artist AND played=1"); $statement->bindValue('title', $track->getTitle()); $statement->bindValue('artist', $track->getArtist()); $results = $statement->execute()->fetchArray(); if ($results === false) { return 0; } return $results[0]; }
protected function getBestTrack(SSLTrack $track) { $search = $this->doMixcloudCall('best track', 'http://api.mixcloud.com/search/?q=%s+%s&type=track', array(urlencode($track->getArtist()), urlencode($track->getTitle()))); if (isset($search['error'])) { throw new Exception('Error from Mixcloud: ' . $search['error']['message']); } $potential_tracks = array(); foreach ($search['data'] as $result) { $potential_track = array('artist' => $result['artist']['name'], 'title' => $result['name'], 'key' => $result['key']); $score = levenshtein($track->getArtist() . ' ' . $track->getTitle(), $result['artist']['name'] . ' ' . $result['name']); $potential_tracks[$score] = $result['key']; } if ($potential_tracks) { ksort($potential_tracks); $best_track = array_shift($potential_tracks); L::level(L::INFO) && L::log(L::INFO, __CLASS__, 'Best track match: %s', array($best_track)); return $best_track; } throw new Exception('no track match for ' . $track->getFullTitle()); }
public function getInfo(SSLTrack $track) { $vars = array(); $vars['apiKey'] = $this->config['api_key']; $vars['secret'] = $this->config['api_secret']; $auth = new lastfmApiAuth('setsession', $vars); $lfm = new lastfmApi(); /* @var $trackP lastfmApiTrack */ /* @var $artistP lastfmApiArtist */ $trackP = $lfm->getPackage($auth, 'track'); $artistP = $lfm->getPackage($auth, 'artist'); //$track_info = $trackP->getInfo(array('artist' => $track->getArtist(), 'title' => $track->getTitle())); $artist_info = $artistP->getInfo(array('artist' => $track->getArtist())); $artist_images = $artistP->getImages(array('artist' => $track->getArtist())); $all = array('artist' => $artist_info, 'images' => $artist_images); return $all; }