/**
  * Stream_Playlist constructor
  * If an ID is passed, it should be a stream session ID.
  */
 public function __construct($id = null)
 {
     if ($id != -1) {
         if ($id) {
             Stream::set_session($id);
         }
         $this->id = Stream::$session;
         if (!Session::exists('stream', $this->id)) {
             debug_event('stream_playlist', 'Session::exists failed', 2);
             return false;
         }
         $this->user = intval($GLOBALS['user']->id);
         $sql = 'SELECT * FROM `stream_playlist` WHERE `sid` = ? ORDER BY `id`';
         $db_results = Dba::read($sql, array($this->id));
         while ($row = Dba::fetch_assoc($db_results)) {
             $this->urls[] = new Stream_URL($row);
         }
     }
     return true;
 }
示例#2
0
 /**
  * songs
  *
  * This returns an xml document from an array of song ids.
  * (Spiffy isn't it!)
  */
 public static function songs($songs, $playlist_data = '')
 {
     if (count($songs) > self::$limit or self::$offset > 0) {
         $songs = array_slice($songs, self::$offset, self::$limit);
     }
     Song::build_cache($songs);
     Stream::set_session($_REQUEST['auth']);
     $string = "";
     // Foreach the ids!
     foreach ($songs as $song_id) {
         $song = new Song($song_id);
         // If the song id is invalid/null or disabled
         if (!$song->id || !$song->enabled) {
             continue;
         }
         $song->format();
         $playlist_track_string = self::playlist_song_tracks_string($song, $playlist_data);
         $tag_string = self::tags_string(Tag::get_top_tags('song', $song_id));
         $rating = new Rating($song_id, 'song');
         $art_url = Art::url($song->album, 'album', $_REQUEST['auth']);
         $string .= "<song id=\"" . $song->id . "\">\n" . "\t<title><![CDATA[" . $song->title . "]]></title>\n" . "\t<artist id=\"" . $song->artist . '"><![CDATA[' . $song->get_artist_name() . "]]></artist>\n" . "\t<album id=\"" . $song->album . '"><![CDATA[' . $song->get_album_name() . "]]></album>\n";
         if ($song->albumartist) {
             $string .= "\t<albumartist id=\"" . $song->albumartist . "\"><![CDATA[" . $song->get_album_artist_name() . "]]></albumartist>\n";
         }
         $string .= $tag_string . "\t<filename><![CDATA[" . $song->file . "]]></filename>\n" . "\t<track>" . $song->track . "</track>\n" . $playlist_track_string . "\t<time>" . $song->time . "</time>\n" . "\t<year>" . $song->year . "</year>\n" . "\t<bitrate>" . $song->bitrate . "</bitrate>\n" . "\t<rate>" . $song->rate . "</rate>\n" . "\t<mode>" . $song->mode . "</mode>\n" . "\t<mime>" . $song->mime . "</mime>\n" . "\t<url><![CDATA[" . Song::play_url($song->id, '', 'api') . "]]></url>\n" . "\t<size>" . $song->size . "</size>\n" . "\t<mbid>" . $song->mbid . "</mbid>\n" . "\t<album_mbid>" . $song->album_mbid . "</album_mbid>\n" . "\t<artist_mbid>" . $song->artist_mbid . "</artist_mbid>\n" . "\t<albumartist_mbid>" . $song->albumartist_mbid . "</albumartist_mbid>\n" . "\t<art><![CDATA[" . $art_url . "]]></art>\n" . "\t<preciserating>" . ($rating->get_user_rating() ?: 0) . "</preciserating>\n" . "\t<rating>" . ($rating->get_user_rating() ?: 0) . "</rating>\n" . "\t<averagerating>" . ($rating->get_average_rating() ?: 0) . "</averagerating>\n" . "\t<composer>" . $song->composer . "</composer>\n" . "\t<channels>" . $song->channels . "</channels>\n" . "\t<comment><![CDATA[" . $song->comment . "]]></comment>\n";
         $string .= "\t<publisher><![CDATA[" . $song->label . "]]></publisher>\n" . "\t<language>" . $song->language . "</language>\n" . "\t<replaygain_album_gain>" . $song->replaygain_album_gain . "</replaygain_album_gain>\n" . "\t<replaygain_album_peak>" . $song->replaygain_album_peak . "</replaygain_album_peak>\n" . "\t<replaygain_track_gain>" . $song->replaygain_track_gain . "</replaygain_track_gain>\n" . "\t<replaygain_track_peak>" . $song->replaygain_track_peak . "</replaygain_track_peak>\n";
         foreach ($song->tags as $tag) {
             $string .= "\t<genre><![CDATA[" . $tag['name'] . "]]></genre>\n";
         }
         $string .= "</song>\n";
     }
     // end foreach
     return self::_header() . $string . self::_footer();
 }
示例#3
0
 /**
  * songs
  *
  * This returns an xml document from an array of song ids.
  * (Spiffy isn't it!)
  */
 public static function songs($songs)
 {
     if (count($songs) > self::$limit or self::$offset > 0) {
         $songs = array_slice($songs, self::$offset, self::$limit);
     }
     Song::build_cache($songs);
     Stream::set_session($_REQUEST['auth']);
     $string = "";
     // Foreach the ids!
     foreach ($songs as $song_id) {
         $song = new Song($song_id);
         // If the song id is invalid/null
         if (!$song->id) {
             continue;
         }
         $tag_string = self::tags_string(Tag::get_top_tags('song', $song_id));
         $rating = new Rating($song_id, 'song');
         $art_url = Art::url($song->album, 'album', $_REQUEST['auth']);
         $string .= "<song id=\"" . $song->id . "\">\n" . "\t<title><![CDATA[" . $song->title . "]]></title>\n" . "\t<artist id=\"" . $song->artist . '"><![CDATA[' . $song->get_artist_name() . "]]></artist>\n" . "\t<album id=\"" . $song->album . '"><![CDATA[' . $song->get_album_name() . "]]></album>\n" . $tag_string . "\t<filename><![CDATA[" . $song->file . "]]></filename>\n" . "\t<track>" . $song->track . "</track>\n" . "\t<time>" . $song->time . "</time>\n" . "\t<year>" . $song->year . "</year>\n" . "\t<bitrate>" . $song->bitrate . "</bitrate>\n" . "\t<mode>" . $song->mode . "</mode>\n" . "\t<mime>" . $song->mime . "</mime>\n" . "\t<url><![CDATA[" . Song::play_url($song->id) . "]]></url>\n" . "\t<size>" . $song->size . "</size>\n" . "\t<mbid>" . $song->mbid . "</mbid>\n" . "\t<album_mbid>" . $song->album_mbid . "</album_mbid>\n" . "\t<artist_mbid>" . $song->artist_mbid . "</artist_mbid>\n" . "\t<art><![CDATA[" . $art_url . "]]></art>\n" . "\t<preciserating>" . $rating->get_user_rating() . "</preciserating>\n" . "\t<rating>" . $rating->get_user_rating() . "</rating>\n" . "\t<averagerating>" . $rating->get_average_rating() . "</averagerating>\n" . "</song>\n";
     }
     // end foreach
     return self::_header() . $string . self::_footer();
 }