示例#1
0
 /** Get the top tags used by this user.
  *
  * @param	string	$user	The user name to fetch top tags for. (Required)
  * @param	integer	$limit	Limit the number of tags returned. (Optional)
  * @return	array			An array of Tag objects.
  *
  * @static
  * @access	public
  * @throws	Error
  */
 public static function getTopTags($user, $limit = null)
 {
     $xml = CallerFactory::getDefaultCaller()->call('user.getTopTags', array('user' => $user, 'limit' => $limit));
     $tags = array();
     foreach ($xml->children() as $tag) {
         $tags[] = Tag::fromSimpleXMLElement($tag);
     }
     return $tags;
 }
示例#2
0
 /** Create a Track object from a SimpleXMLElement.
  *
  * @param	SimpleXMLElement	$xml	A SimpleXMLElement.
  * @return	Track						A Track object.
  *
  * @static
  * @access	public
  * @internal
  */
 public static function fromSimpleXMLElement(SimpleXMLElement $xml)
 {
     $images = array();
     $topTags = array();
     if (count($xml->image) > 1) {
         foreach ($xml->image as $image) {
             $images[Util::toImageType($image['size'])] = Util::toString($image);
         }
     } else {
         $images[Media::IMAGE_UNKNOWN] = Util::toString($xml->image);
     }
     if ($xml->toptags) {
         foreach ($xml->toptags->children() as $tag) {
             $topTags[] = Tag::fromSimpleXMLElement($tag);
         }
     }
     if ($xml->artist) {
         if ($xml->artist->name && $xml->artist->mbid && $xml->artist->url) {
             $artist = new Artist(Util::toString($xml->artist->name), Util::toString($xml->artist->mbid), Util::toString($xml->artist->url), array(), 0, 0, 0, array(), array(), '', 0.0);
         } else {
             $artist = Util::toString($xml->artist);
         }
     } else {
         if ($xml->creator) {
             $artist = Util::toString($xml->creator);
         } else {
             $artist = '';
         }
     }
     if ($xml->name) {
         $name = Util::toString($xml->name);
     } else {
         if ($xml->title) {
             $name = Util::toString($xml->title);
         } else {
             $name = '';
         }
     }
     // TODO: <extension application="http://www.last.fm">
     return new Track($artist, Util::toString($xml->album), $name, Util::toString($xml->mbid), Util::toString($xml->url), $images, Util::toInteger($xml->listeners), Util::toInteger($xml->playcount), Util::toInteger($xml->duration), $topTags, Util::toInteger($xml->id), Util::toString($xml->location), Util::toBoolean($xml->streamable), Util::toBoolean($xml->streamable['fulltrack']), $xml->wiki, Util::toTimestamp($xml->date));
 }
示例#3
0
 /** Create an Artist object from a SimpleXMLElement object.
  *
  * @param	SimpleXMLElement	$xml	A SimpleXMLElement object.
  * @return	Artist						An Artist object.
  *
  * @static
  * @access	public
  * @internal
  */
 public static function fromSimpleXMLElement(SimpleXMLElement $xml)
 {
     $images = array();
     $tags = array();
     $similar = array();
     /* NOTE: image, image_small... this sucks! */
     if ($xml->image) {
         if (count($xml->image) > 1) {
             foreach ($xml->image as $image) {
                 $images[Util::toImageType($image['size'])] = Util::toString($image);
             }
         } else {
             $images[Media::IMAGE_LARGE] = Util::toString($image);
         }
     }
     if ($xml->image_small) {
         $images[Media::IMAGE_SMALL] = Util::toString($xml->image_small);
     }
     if ($xml->tags) {
         foreach ($xml->tags->children() as $tag) {
             $tags[] = Tag::fromSimpleXMLElement($tag);
         }
     }
     if ($xml->similar) {
         foreach ($xml->similar->children() as $artist) {
             $similar[] = Artist::fromSimpleXMLElement($artist);
         }
     }
     return new Artist(Util::toString($xml->name), Util::toString($xml->mbid), Util::toString($xml->url), $images, Util::toBoolean($xml->streamable), Util::toInteger($xml->listeners), Util::toInteger($xml->playcount), $tags, $similar, $xml->bio ? Util::toString($xml->bio->summary) : "", Util::toFloat($xml->match));
 }
示例#4
0
 /** 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;
 }
示例#5
0
 /** Create an Album object from a SimpleXMLElement object.
  *
  * @param	SimpleXMLElement	$xml	A SimpleXMLElement object.
  * @return	Album						An Album object.
  *
  * @static
  * @access	public
  * @internal
  */
 public static function fromSimpleXMLElement(SimpleXMLElement $xml)
 {
     $images = array();
     $topTags = array();
     /* TODO: tagcount | library.getAlbums */
     if ($xml->mbid) {
         $mbid = Util::toString($xml->mbid);
     } else {
         if ($xml['mbid']) {
             $mbid = Util::toString($xml['mbid']);
         } else {
             $mbid = '';
         }
     }
     foreach ($xml->image as $image) {
         $images[Util::toImageType($image['size'])] = Util::toString($image);
     }
     if ($xml->toptags) {
         foreach ($xml->toptags->children() as $tag) {
             $topTags[] = Tag::fromSimpleXMLElement($tag);
         }
     }
     if ($xml->artist->name && $xml->artist->mbid && $xml->artist->url) {
         $artist = new Artist(Util::toString($xml->artist->name), Util::toString($xml->artist->mbid), Util::toString($xml->artist->url), array(), 0, 0, 0, array(), array(), '', 0.0);
     } else {
         if ($xml->artist && $xml->artist['mbid']) {
             $artist = new Artist(Util::toString($xml->artist), Util::toString($xml->artist['mbid']), '', array(), 0, 0, 0, array(), array(), '', 0.0);
         } else {
             $artist = Util::toString($xml->artist);
         }
     }
     return new Album($artist, Util::toString($xml->name), Util::toInteger($xml->id), $mbid, Util::toString($xml->url), $images, Util::toInteger($xml->listeners), Util::toInteger($xml->playcount), Util::toTimestamp($xml->releasedate), $topTags);
 }