/** Sets the default {@link Caller}. * * @param string $caller A Caller class name. (Required) * @access public */ public function setDefaultCaller($class) { if (get_parent_class($class) == 'Caller') { self::$default = $class; } else { throw new Exception("Class '" . $class . "' does not extend 'Caller'!"); } }
/** Get the most popular tracks on last.fm by country. * * @param string country A country name, as defined by the ISO 3166-1 country names standard. (Required) * @param string location A metro name, to fetch the charts for (must be within the country specified). (Optional) * @return array An array of Track objects. * * @static * @access public * @throws Error */ public static function getTopTracks($country, $location = null) { $xml = CallerFactory::getDefaultCaller()->call('geo.getTopTracks', array('country' => $country, 'location' => $location)); $tracks = array(); foreach ($xml->children() as $track) { $tracks[] = Track::fromSimpleXMLElement($track); } return $tracks; }
/** Get a Tasteometer score from two inputs, along with a list of shared artists. If the input is a User or a Myspace URL, some additional information is returned. * * @param integer $type1 A Tasteometer comparison type. (Required) * @param integer $type2 A Tasteometer comparison type. (Required) * @param mixed $value1 A last.fm username, an array of artist names or a myspace profile URL. (Required) * @param mixed $value2 A last.fm username, an array of artist names or a myspace profile URL. (Required) * @param integer $limit How many shared artists to display (default = 5). (Optional) * @return array An array containing comparison results, input information and shared artists. * * @static * @access public * @throws Error */ public static function compare($type1, $type2, $value1, $value2, $limit = null) { /* Handle arrays of artist names. */ if (is_array($value1)) { $value1 = implode(',', $value1); } if (is_array($value2)) { $value2 = implode(',', $value2); } /* API call. */ $xml = CallerFactory::getDefaultCaller()->call('tasteometer.compare', array('type1' => $type1, 'type2' => $type2, 'value1' => $value1, 'value2' => $value2, 'limit' => $limit)); /* Get shared artists. */ $artists = array(); foreach ($xml->result->artists->children() as $artist) { $artists[] = Artist::fromSimpleXMLElement($artist); } /* Get input information. */ $inputs = array(); foreach ($xml->input->children() as $input) { $inputs[] = User::fromSimpleXMLElement($input); } return array('score' => Util::toFloat($xml->result->score), 'input' => $inputs, 'artists' => $artists); }
/** A paginated list of all the tracks in a user's library, with play counts and tag counts. * * @param string $user The user whose library you want to fetch. (Required) * @param integer $limit Limit the amount of tracks returned (maximum/default is 50). (Optional) * @param integer $page The page number you wish to scan to. (Optional) * @return PaginatedResult A PaginatedResult object. * * @static * @access public * @throws Error */ public static function getTracks($user, $limit, $page) { $xml = CallerFactory::getDefaultCaller()->call('library.getTracks', array('user' => $user, 'limit' => $limit, 'page' => $page)); $tracks = array(); foreach ($xml->children() as $track) { $tracks[] = Track::fromSimpleXMLElement($track); } $perPage = Util::toInteger($xml['perPage']); return new PaginatedResult(Util::toInteger($xml['totalPages']) * $perPage, (Util::toInteger($xml['page']) - 1) * $perPage, $perPage, $tracks); }
/** Get a track chart for a group, for a given date range. If no date range is supplied, it will return the most recent album chart for this group. * * @param string $group The last.fm group name to fetch the charts of. (Required) * @param integer $from The date at which the chart should start from. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional) * @param integer $to The date at which the chart should end on. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional) * @return array An array of Track objects. * * @static * @access public * @throws Error */ public static function getWeeklyTrackChart($group, $from = null, $to = null) { $xml = CallerFactory::getDefaultCaller()->call('group.getWeeklyTrackChart', array('group' => $group, 'from' => $from, 'to' => $to)); $tracks = array(); foreach ($xml->children() as $track) { $tracks[] = Track::fromSimpleXMLElement($track); } return $tracks; }
/** Get a track playlist for streaming. INOFFICIAL. * * @param string $artist An artist name. (Required) * @param string $track A track name. (Required) * @return mixed A Playlist object. * * @static * @access public * @throws Error */ public static function getPlaylist($artist, $track) { $xml = CallerFactory::getDefaultCaller()->call('track.getPlayerMenu', array('artist' => $artist, 'track' => $track)); return Playlist::fetch(Util::toString($xml->playlist->url), true, true); }
<?php require_once 'lib/php-last.fm-api/src/lastfm.api.php'; require_once 'lib/session.class.php'; require_once 'lib/scrobbler.class.php'; $oSession = new Session(); $oSession->createDb(); $oCall = CallerFactory::getDefaultCaller(); $oCall->setApiKey('feca1bb1c195dd2bcc6e331eca7696df'); $oCall->setApiSecret('42505d22eef1a217f3f184fed2be882a');
/** Get an event playlist for streaming.. INOFFICIAL. * * @param integer $event An event ID. (Required) * @return mixed A Playlist object. * * @static * @access public * @throws Error */ public static function getPlaylist($event) { $xml = CallerFactory::getDefaultCaller()->call('event.getPlayerMenu', array('event' => $event)); return Playlist::fetch(Util::toString($xml->playlist->url), true, true); }
/** Search for a tag by name. Returns matches sorted by relevance. * * @param string $tag The tag name in question. (Required) * @param integer $limit Limit the number of tags returned at one time. Default (maximum) is 30. (Optional) * @param integer $page Scan into the results by specifying a page number. Defaults to first page. (Optional) * @return array An array of Tag objects. * * @static * @access public * @throws Error */ public static function search($tag, $limit = null, $page = null) { $xml = CallerFactory::getDefaultCaller()->call('tag.search', array('tag' => $tag, 'limit' => $limit, 'page' => $page)); $tags = array(); foreach ($xml->tagmatches->children() as $tag) { $tags[] = Tag::fromSimpleXMLElement($tag); } return $tags; }
/** Fetch XSPF playlists using a last.fm playlist url. * * @param string $playlist A lastfm protocol playlist url ('lastfm://playlist/...'). (Required) * @param string $streaming Weather to fetch a playlist for streaming. (Optional) * @param string $fod Weather to fetch a playlist with free on demand tracks. (Optional) * @param Session $session A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Optional) * @return Playlist A Playlist object. * * @static * @access public * @throws Error */ public static function fetch($playlist, $streaming = null, $fod = null, $session = null) { if ($session == null) { $xml = CallerFactory::getDefaultCaller()->call('playlist.fetch', array_filter(array('playlistURL' => $playlist, 'streaming' => $streaming, 'fod' => $fod))); } else { $xml = CallerFactory::getDefaultCaller()->call('playlist.fetch', array_filter(array('playlistURL' => $playlist, 'streaming' => $streaming, 'fod' => $fod, 'sk' => $session->getKey()))); } return Playlist::fromSimpleXMLElement($xml); }
/** Search for a venue by venue name . * * @param string $venue The venue name you would like to search for. (Required) * @param integer $limit The number of results to fetch per page. Defaults to 50. (Optional) * @param integer $page The results page you would like to fetch. (Optional) * @param string $country Filter your results by country. Expressed as an ISO 3166-2 code. (Optional) * @return PaginatedResult A PaginatedResult object. * @see PaginatedResult * * @static * @access public * @throws Error */ public static function search($venue, $limit = null, $page = null, $country = null) { $xml = CallerFactory::getDefaultCaller()->call('venue.search', array('venue' => $venue, 'limit' => $limit, 'page' => $page, 'country' => $country)); $venues = array(); foreach ($xml->venuematches->children() as $venue) { $venues[] = Venue::fromSimpleXMLElement($venue); } $opensearch = $xml->children('http://a9.com/-/spec/opensearch/1.1/'); return new PaginatedResult(Util::toInteger($opensearch->totalResults), Util::toInteger($opensearch->startIndex), Util::toInteger($opensearch->itemsPerPage), $venues); }
/** * Get a list of a radio's playlists on last.fm. * * @param string $session sk (Required) : A session key generated by authenticating a user via the authentication protocol. * @param float $speed_multiplier speed_multiplier (Optional) : The rate at which to provide the stream (supported multipliers are 1.0 and 2.0) * @param int $bitrate bitrate (Optional) : What bitrate to stream content at, in kbps (supported bitrates are 64 and 128) * @param bool $discovery discovery (Optional) : Whether to request last.fm content with discovery mode switched on. * @param bool $rtp rtp (Optional) : Whether the user is scrobbling or not during this radio session (helps content generation) * * @static * @access public * @throws Error * * @return Playlist * */ public static function getPlaylists(Session $session, $speed_multiplier = null, $bitrate = null, $discovery = null, $rtp = null) { $xml = CallerFactory::getDefaultCaller()->signedCall('radio.getPlaylist', array('discovery' => $discovery, 'rtp' => $rtp, 'speed_multiplier' => $speed_multiplier, 'bitrate' => $bitrate), $session); return Playlist::fromSimpleXMLElement($xml); }
/** Used by our flash embeds (on trusted domains) to use a site session cookie to seed a ws session without requiring a password. Uses the site cookie so must be accessed over a *.last.fm domain. * * @return Session A Session object. * * @static * @access public * @throws Error */ public static function getWebSession() { $xml = CallerFactory::getDefaultCaller()->signedCall('auth.getWebSession'); return Session::fromSimpleXMLElement($xml); }