/** * Constructor * * Song Preview class */ public function __construct($id = null) { if (!$id) { return false; } $this->id = intval($id); if ($info = $this->_get_info()) { foreach ($info as $key => $value) { $this->{$key} = $value; } $data = pathinfo($this->file); $this->type = strtolower($data['extension']) ?: 'mp3'; $this->mime = Song::type_to_mime($this->type); } else { $this->id = null; return false; } return true; }
public static function createSong($xml, $song, $elementName = 'song') { $xsong = $xml->addChild(htmlspecialchars($elementName)); $xsong->addAttribute('id', self::getSongId($song->id)); $xsong->addAttribute('parent', self::getAlbumId($song->album)); //$xsong->addAttribute('created', ); $xsong->addAttribute('title', $song->title); $xsong->addAttribute('isDir', 'false'); $xsong->addAttribute('isVideo', 'false'); $xsong->addAttribute('type', 'music'); $album = new Album($song->album); $xsong->addAttribute('albumId', self::getAlbumId($album->id)); $xsong->addAttribute('album', $album->name); $artist = new Artist($song->artist); $xsong->addAttribute('artistId', self::getArtistId($song->artist)); $xsong->addAttribute('artist', $artist->name); $xsong->addAttribute('coverArt', self::getAlbumId($album->id)); $xsong->addAttribute('duration', $song->time); $xsong->addAttribute('bitRate', intval($song->bitrate / 1000)); $rating = new Rating($song->id, "song"); $user_rating = $rating->get_user_rating(); if ($user_rating > 0) { $xsong->addAttribute('userRating', ceil($user_rating)); } $avg_rating = $rating->get_average_rating(); if ($avg_rating > 0) { $xsong->addAttribute('averageRating', ceil($avg_rating)); } if ($song->track > 0) { $xsong->addAttribute('track', $song->track); } if ($song->year > 0) { $xsong->addAttribute('year', $song->year); } $tags = Tag::get_object_tags('song', $song->id); if (count($tags) > 0) { $xsong->addAttribute('genre', $tags[0]['name']); } $xsong->addAttribute('size', $song->size); if ($album->disk > 0) { $xsong->addAttribute('discNumber', $album->disk); } $xsong->addAttribute('suffix', $song->type); $xsong->addAttribute('contentType', $song->mime); // Create a clean fake path instead of song real file path to have better offline mode storage on Subsonic clients $path = $artist->name . '/' . $album->name . '/' . basename($song->file); $xsong->addAttribute('path', $path); // Set transcoding information if required $transcode_cfg = AmpConfig::get('transcode'); $valid_types = Song::get_stream_types_for_type($song->type, 'api'); if ($transcode_cfg == 'always' || $transcode_cfg != 'never' && !in_array('native', $valid_types)) { $transcode_settings = $song->get_transcode_settings(null, 'api'); if ($transcode_settings) { $transcode_type = $transcode_settings['format']; $xsong->addAttribute('transcodedSuffix', $transcode_type); $xsong->addAttribute('transcodedContentType', Song::type_to_mime($transcode_type)); } } return $xsong; }