/** * update_tag_list * Update the tags list based on commated list (ex. tag1,tag2,tag3,..) */ public static function update_tag_list($tags_comma, $type, $object_id, $overwrite) { debug_event('tag.class', 'Updating tags for values {' . $tags_comma . '} type {' . $type . '} object_id {' . $object_id . '}', '5'); $ctags = Tag::get_top_tags($type, $object_id); $editedTags = explode(",", $tags_comma); if (is_array($ctags)) { foreach ($ctags as $ctid => $ctv) { if ($ctv['id'] != '') { $ctag = new Tag($ctv['id']); debug_event('tag.class', 'Processing tag {' . $ctag->name . '}...', '5'); $found = false; foreach ($editedTags as $tk => $tv) { if ($ctag->name == $tv) { $found = true; break; } } if ($found) { debug_event('tag.class', 'Already found. Do nothing.', '5'); unset($editedTags[$tk]); } else { if ($overwrite) { debug_event('tag.class', 'Not found in the new list. Delete it.', '5'); $ctag->remove_map($type, $object_id); } } } } } // Look if we need to add some new tags foreach ($editedTags as $tk => $tv) { if ($tv != '') { debug_event('tag.class', 'Adding new tag {' . $tv . '}', '5'); Tag::add($type, $object_id, $tv, false); } } }
public function format($details = true) { $this->f_name = $this->name; $this->f_link = '<a href="' . AmpConfig::get('web_path') . '/broadcast.php?id=' . $this->id . '">' . scrub_out($this->f_name) . '</a>'; if ($details) { $this->tags = Tag::get_top_tags('broadcast', $this->id); $this->f_tags = Tag::get_display($this->tags, true, 'broadcast'); } }
/** * format * this function takes the object and reformats some values */ public function format($details = true) { $this->f_name = trim($this->prefix . " " . $this->name); $this->link = AmpConfig::get('web_path') . '/tvshows.php?action=show&tvshow=' . $this->id; $this->f_link = '<a href="' . $this->link . '" title="' . $this->f_name . '">' . $this->f_name . '</a>'; if ($details) { $this->_get_extra_info(); $this->tags = Tag::get_top_tags('tvshow', $this->id); $this->f_tags = Tag::get_display($this->tags, true, 'tvshow'); } return true; }
public function format($details = true) { if ($details) { $this->tags = Tag::get_top_tags('channel', $this->id); $this->f_tags = Tag::get_display($this->tags, true, 'channel'); } }
/** * format * this function takes an array of artist * information and reformats the relevent values * so they can be displayed in a table for example * it changes the title into a full link. */ public function format() { /* Combine prefix and name, trim then add ... if needed */ $name = trim($this->prefix . " " . $this->name); $this->f_name = $name; $this->f_full_name = trim(trim($this->prefix) . ' ' . trim($this->name)); // If this is a fake object, we're done here if ($this->_fake) { return true; } if ($this->catalog_id) { $this->f_link = AmpConfig::get('web_path') . '/artists.php?action=show&catalog=' . $this->catalog_id . '&artist=' . $this->id; $this->f_name_link = "<a href=\"" . $this->f_link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>"; } else { $this->f_link = AmpConfig::get('web_path') . '/artists.php?action=show&artist=' . $this->id; $this->f_name_link = "<a href=\"" . $this->f_link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>"; } // Get the counts $extra_info = $this->_get_extra_info($this->catalog_id); //Format the new time thingy that we just got $min = sprintf("%02d", floor($extra_info['time'] / 60) % 60); $sec = sprintf("%02d", $extra_info['time'] % 60); $hours = floor($extra_info['time'] / 3600); $this->f_time = ltrim($hours . ':' . $min . ':' . $sec, '0:'); $this->tags = Tag::get_top_tags('artist', $this->id); $this->f_tags = Tag::get_display($this->tags); $this->object_cnt = $extra_info['object_cnt']; return true; }
/** * format * This is the format function for this object. It sets cleaned up * album information with the base required * f_link, f_name */ public function format() { $web_path = AmpConfig::get('web_path'); /* Pull the advanced information */ $data = $this->_get_extra_info(); foreach ($data as $key => $value) { $this->{$key} = $value; } /* Truncate the string if it's to long */ $this->f_name = $this->full_name; $this->f_link_src = $web_path . '/albums.php?action=show&album=' . scrub_out($this->id); $this->f_name_link = "<a href=\"" . $this->f_link_src . "\" title=\"" . scrub_out($this->full_name) . "\">" . scrub_out($this->f_name); // Looking if we need to combine or display disks if ($this->disk && (!$this->allow_group_disks || $this->allow_group_disks && !AmpConfig::get('album_group'))) { $this->f_name_link .= " <span class=\"discnb\">[" . T_('Disk') . " " . $this->disk . "]</span>"; } $this->f_name_link .= "</a>"; $this->f_link = $this->f_name_link; $this->f_title = $this->full_name; if ($this->artist_count == '1') { $artist = trim(trim($this->artist_prefix) . ' ' . trim($this->artist_name)); $this->f_artist_name = $artist; $this->f_artist_link = "<a href=\"{$web_path}/artists.php?action=show&artist=" . $this->artist_id . "\" title=\"" . scrub_out($this->artist_name) . "\">" . $artist . "</a>"; $this->f_artist = $artist; } else { $this->f_artist_link = "<span title=\"{$this->artist_count} " . T_('Artists') . "\">" . T_('Various') . "</span>"; $this->f_artist = T_('Various'); $this->f_artist_name = $this->f_artist; } if ($this->year == '0') { $this->year = "N/A"; } $this->tags = Tag::get_top_tags('album', $this->id); $this->f_tags = Tag::get_display($this->tags); }
private static function addVideo(SimpleXMLElement $xml, Video $video, $details = false) { $id = self::getVideoId($video->id); $xvid = $xml->addChild('Video'); $xvid->addAttribute('ratingKey', $id); $xvid->addAttribute('key', self::getMetadataUri($id)); $xvid->addAttribute('title', $video->f_title); if ($video->release_date) { $year = date('Y', $video->release_date); if ($year) { $xvid->addAttribute('year', $year); } $xvid->addAttribute('originallyAvailableAt', $video->f_release_date); } $rating = new Rating($video->id, "video"); $rating_value = $rating->get_average_rating(); if ($rating_value > 0) { $xvid->addAttribute('rating', intval($rating_value * 2)); } $time = $video->time * 1000; $xvid->addAttribute('duration', $time); $xvid->addAttribute('addedAt', ''); $xvid->addAttribute('updatedAt', ''); $xvid->addAttribute('thumb', self::getMetadataUri($id) . '/thumb/' . $id); $xmedia = $xvid->addChild('Media'); $xmedia->addAttribute('id', $id); // Same ID that video => OK? $xmedia->addAttribute('duration', $time); $xmedia->addAttribute('bitrate', intval($video->bitrate / 1000)); $xmedia->addAttribute('audioChannels', $video->channels); // Type != Codec != Container, but that's how Ampache works today... $xmedia->addAttribute('audioCodec', $video->audio_codec); $xmedia->addAttribute('videoCodec', $video->video_codec); $xmedia->addAttribute('container', $video->type); $xmedia->addAttribute('width', $video->resolution_x); $xmedia->addAttribute('height', $video->resolution_y); //$xmedia->addAttribute('videoResolution', 'sd'); // TODO //$xmedia->addAttribute('aspectRatio', '1.78'); // TODO $xmedia->addAttribute('videoFrameRate', intval(ceil($video->frame_rate)) . 'p'); $xpart = $xmedia->addChild('Part'); $partid = self::getPartId($id); $xpart->addAttribute('id', $partid); $xpart->addAttribute('key', self::getPartUri($partid, $video->type)); $xpart->addAttribute('duration', $time); $xpart->addAttribute('file', $video->file); $xpart->addAttribute('size', $video->size); $xpart->addAttribute('container', $video->type); // TODO: support Writer/Director tags here as part of Video/ /* <Writer tag="Grant Scharbo" /> <Writer tag="Richard Hatem" /> <Director tag="Terry McDonough" /> */ $tags = Tag::get_top_tags('video', $video->id); if (is_array($tags)) { foreach ($tags as $tag_id => $tag) { $xgenre = $xvid->addChild('Genre'); $xgenre->addAttribute('id', $tag['id']); $xgenre->addAttribute('tag', $tag['name']); } } if ($details) { // Subtitles $subtitles = $video->get_subtitles(); foreach ($subtitles as $subtitle) { $streamid = hexdec(bin2hex($subtitle['lang_code'])) . $partid; $xstream = $xpart->addChild('Stream'); $xstream->addAttribute('id', $streamid); $xstream->addAttribute('key', '/library/streams/' . $streamid); $xstream->addAttribute('streamType', '3'); $xstream->addAttribute('codec', 'srt'); $xstream->addAttribute('language', $subtitle['lang_name']); $xstream->addAttribute('languageCode', $subtitle['lang_code']); $xstream->addAttribute('format', 'srt'); } // TODO: support real audio/video streams! /* <Stream id="93" streamType="1" codec="mpeg4" index="0" bitrate="833" bitDepth="8" chromaSubsampling="4:2:0" colorSpace="yuv" duration="2989528" frameRate="23,976" gmc="0" height="352" level="5" profile="asp" qpel="0" scanType="progressive" width="624" /> <Stream id="94" streamType="2" selected="1" codec="mp3" index="1" channels="2" bitrate="135" bitrateMode="vbr" duration="2989488" samplingRate="48000" /> */ } return $xvid; }
/** * 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(); }
/** * 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(); }
public function format() { $this->tags = Tag::get_top_tags('channel', $this->id); $this->f_tags = Tag::get_display($this->tags); }
/** * format * This formats a video object so that it is human readable */ public function format($details = true) { $this->f_title = scrub_out($this->title); $this->f_full_title = $this->f_title; $this->link = AmpConfig::get('web_path') . "/video.php?action=show_video&video_id=" . $this->id; $this->f_link = "<a href=\"" . $this->link . "\" title=\"" . scrub_out($this->f_title) . "\"> " . scrub_out($this->f_title) . "</a>"; $this->f_codec = $this->video_codec . ' / ' . $this->audio_codec; if ($this->resolution_x || $this->resolution_y) { $this->f_resolution = $this->resolution_x . 'x' . $this->resolution_y; } if ($this->display_x || $this->display_y) { $this->f_display = $this->display_x . 'x' . $this->display_y; } // Format the Bitrate $this->f_bitrate = intval($this->bitrate / 1000) . "-" . strtoupper($this->mode); $this->f_video_bitrate = (string) intval($this->video_bitrate / 1000); if ($this->frame_rate) { $this->f_frame_rate = $this->frame_rate . ' fps'; } // Format the Time $min = floor($this->time / 60); $sec = sprintf("%02d", $this->time % 60); $this->f_time = $min . ":" . $sec; $hour = sprintf("%02d", floor($min / 60)); $min_h = sprintf("%02d", $min % 60); $this->f_time_h = $hour . ":" . $min_h . ":" . $sec; if ($details) { // Get the top tags $this->tags = Tag::get_top_tags('video', $this->id); $this->f_tags = Tag::get_display($this->tags, true, 'video'); } $this->f_length = floor($this->time / 60) . ' ' . T_('minutes'); $this->f_file = $this->f_title . '.' . $this->type; if ($this->release_date) { $this->f_release_date = date('Y-m-d', $this->release_date); } }
/** * format * This takes the current song object * and does a ton of formating on it creating f_??? variables on the current * object */ public function format($details = true) { if ($details) { $this->fill_ext_info(); // Get the top tags $this->tags = Tag::get_top_tags('song', $this->id); $this->f_tags = Tag::get_display($this->tags, true, 'song'); } // Format the album name $this->f_album_full = $this->get_album_name(); $this->f_album = $this->f_album_full; // Format the artist name $this->f_artist_full = $this->get_artist_name(); $this->f_artist = $this->f_artist_full; // Format the album_artist name $this->f_albumartist_full = $this->get_album_artist_name(); // Format the title $this->f_title_full = $this->title; $this->f_title = $this->title; // Create Links for the different objects $this->link = AmpConfig::get('web_path') . "/song.php?action=show_song&song_id=" . $this->id; $this->f_link = "<a href=\"" . scrub_out($this->link) . "\" title=\"" . scrub_out($this->f_artist) . " - " . scrub_out($this->title) . "\"> " . scrub_out($this->f_title) . "</a>"; $this->f_album_link = "<a href=\"" . AmpConfig::get('web_path') . "/albums.php?action=show&album=" . $this->album . "\" title=\"" . scrub_out($this->f_album_full) . "\"> " . scrub_out($this->f_album) . "</a>"; $this->f_artist_link = "<a href=\"" . AmpConfig::get('web_path') . "/artists.php?action=show&artist=" . $this->artist . "\" title=\"" . scrub_out($this->f_artist_full) . "\"> " . scrub_out($this->f_artist) . "</a>"; if (!empty($this->albumartist)) { $this->f_albumartist_link = "<a href=\"" . AmpConfig::get('web_path') . "/artists.php?action=show&artist=" . $this->albumartist . "\" title=\"" . scrub_out($this->f_albumartist_full) . "\"> " . scrub_out($this->f_albumartist_full) . "</a>"; } // Format the Bitrate $this->f_bitrate = intval($this->bitrate / 1000) . "-" . strtoupper($this->mode); // Format the Time $min = floor($this->time / 60); $sec = sprintf("%02d", $this->time % 60); $this->f_time = $min . ":" . $sec; $hour = sprintf("%02d", floor($min / 60)); $min_h = sprintf("%02d", $min % 60); $this->f_time_h = $hour . ":" . $min_h . ":" . $sec; // Format the track (there isn't really anything to do here) $this->f_track = (string) $this->track; // Format the size $this->f_size = UI::format_bytes($this->size); $this->f_lyrics = "<a title=\"" . scrub_out($this->title) . "\" href=\"" . AmpConfig::get('web_path') . "/song.php?action=show_lyrics&song_id=" . $this->id . "\">" . T_('Show Lyrics') . "</a>"; $this->f_file = $this->f_artist . ' - '; if ($this->track) { $this->f_file .= $this->track . ' - '; } $this->f_file .= $this->f_title . '.' . $this->type; $this->f_publisher = $this->label; $this->f_composer = $this->composer; }
/** * format * This takes the current song object * and does a ton of formating on it creating f_??? variables on the current * object */ public function format() { $this->fill_ext_info(); // Format the filename preg_match("/^.*\\/(.*?)\$/", $this->file, $short); if (is_array($short) && isset($short[1])) { $this->f_file = htmlspecialchars($short[1]); } // Format the album name $this->f_album_full = $this->get_album_name(); $this->f_album = $this->f_album_full; // Format the artist name $this->f_artist_full = $this->get_artist_name(); $this->f_artist = $this->f_artist_full; // Format the title $this->f_title_full = $this->title; $this->f_title = $this->title; // Create Links for the different objects $this->link = AmpConfig::get('web_path') . "/song.php?action=show_song&song_id=" . $this->id; $this->f_link = "<a href=\"" . scrub_out($this->link) . "\" title=\"" . scrub_out($this->f_artist) . " - " . scrub_out($this->title) . "\"> " . scrub_out($this->f_title) . "</a>"; $this->f_album_link = "<a href=\"" . AmpConfig::get('web_path') . "/albums.php?action=show&album=" . $this->album . "\" title=\"" . scrub_out($this->f_album_full) . "\"> " . scrub_out($this->f_album) . "</a>"; $this->f_artist_link = "<a href=\"" . AmpConfig::get('web_path') . "/artists.php?action=show&artist=" . $this->artist . "\" title=\"" . scrub_out($this->f_artist_full) . "\"> " . scrub_out($this->f_artist) . "</a>"; // Format the Bitrate $this->f_bitrate = intval($this->bitrate / 1000) . "-" . strtoupper($this->mode); // Format the Time $min = floor($this->time / 60); $sec = sprintf("%02d", $this->time % 60); $this->f_time = $min . ":" . $sec; // Format the track (there isn't really anything to do here) $this->f_track = $this->track; // Get the top tags $this->tags = Tag::get_top_tags('song', $this->id); $this->f_tags = Tag::get_display($this->tags); // Format the size $this->f_size = UI::format_bytes($this->size); $this->f_lyrics = "<a title=\"" . scrub_out($this->title) . "\" href=\"" . AmpConfig::get('web_path') . "/song.php?action=show_lyrics&song_id=" . $this->id . "\">" . T_('Show Lyrics') . "</a>"; return true; }
public static function addAlbum($xml, $album) { $id = self::getAlbumId($album->id); $xdir = $xml->addChild('Directory'); self::addAlbumMeta($xdir, $album); $xdir->addAttribute('ratingKey', $id); $xdir->addAttribute('key', self::getMetadataUri($id) . '/children'); $xdir->addAttribute('title', $album->f_title); $artistid = self::getArtistId($album->artist_id); $xdir->addAttribute('parentRatingKey', $artistid); $xdir->addAttribute('parentKey', self::getMetadataUri($artistid)); $xdir->addAttribute('parentTitle', $album->f_artist); $xdir->addAttribute('leafCount', $album->song_count); if ($album->year != 0 && $album->year != 'N/A') { $xdir->addAttribute('year', $album->year); } $rating = new Rating($album->id, "album"); $rating_value = $rating->get_average_rating(); if ($rating_value > 0) { $xdir->addAttribute('rating', intval($rating_value * 2)); } $tags = Tag::get_top_tags('album', $album->id); if (is_array($tags)) { foreach ($tags as $tag_id => $value) { $tag = new Tag($tag_id); $xgenre = $xdir->addChild('Genre'); $xgenre->addAttribute('tag', $tag->name); } } }