public function getName() { if ($this->catalog_id > 0) { $catalog = Catalog::create_from_id($this->catalog_id); return $catalog->name; } return AmpConfig::get('site_title'); }
/** * Get a song waveform. * @param int $song_id * @return binary|string|null */ public static function get($song_id) { $song = new Song($song_id); $waveform = null; if ($song->id) { $song->format(); $waveform = $song->waveform; if (!$waveform) { $catalog = Catalog::create_from_id($song->catalog); if ($catalog->get_type() == 'local') { $transcode_to = 'wav'; $transcode_cfg = AmpConfig::get('transcode'); $valid_types = $song->get_stream_types(); if ($song->type != $transcode_to) { $basedir = AmpConfig::get('tmp_dir_path'); if ($basedir) { if ($transcode_cfg != 'never' && in_array('transcode', $valid_types)) { $tmpfile = tempnam($basedir, $transcode_to); $tfp = fopen($tmpfile, 'wb'); if (!is_resource($tfp)) { debug_event('waveform', "Failed to open " . $tmpfile, 3); return null; } $transcoder = Stream::start_transcode($song, $transcode_to); $fp = $transcoder['handle']; if (!is_resource($fp)) { debug_event('waveform', "Failed to open " . $song->file . " for waveform.", 3); return null; } do { $buf = fread($fp, 2048); fwrite($tfp, $buf); } while (!feof($fp)); fclose($fp); fclose($tfp); Stream::kill_process($transcoder); $waveform = self::create_waveform($tmpfile); //$waveform = self::create_waveform("C:\\tmp\\test.wav"); @unlink($tmpfile); } else { debug_event('waveform', 'transcode setting to wav required for waveform.', '3'); } } else { debug_event('waveform', 'tmp_dir_path setting required for waveform.', '3'); } } else { $waveform = self::create_waveform($song->file); } } if ($waveform) { self::save_to_db($song_id, $waveform); } } } return $waveform; }
public function get() { debug_event('webdav', 'File get', 5); // Only media associated to a local catalog is supported if ($this->libitem->catalog) { $catalog = Catalog::create_from_id($this->libitem->catalog); if ($catalog->get_type() === 'local') { return fopen($this->libitem->file, 'r'); } else { debug_event('webdav', 'Catalog associated to the media is not local. This is currently unsupported.', 3); } } else { debug_event('webdav', 'No catalog associated to the media.', 3); } return null; }
public static function setSections(SimpleXMLElement $xml, $catalogs) { foreach ($catalogs as $id) { $catalog = Catalog::create_from_id($id); if ($catalog) { $catalog->format(); $dir = $xml->addChild('Directory'); $dir->addAttribute('filters', '1'); $dir->addAttribute('refreshing', '0'); $dir->addAttribute('key', $id); $gtypes = $catalog->get_gather_types(); switch ($gtypes[0]) { case 'movie': $stype = 'movie'; $dir->addAttribute('type', 'movie'); $dir->addAttribute('agent', 'com.plexapp.agents.imdb'); $dir->addAttribute('scanner', 'Ampache Movie Scanner'); break; case 'tvshow': $stype = 'show'; $dir->addAttribute('type', 'show'); $dir->addAttribute('agent', 'com.plexapp.agents.thetvdb'); $dir->addAttribute('scanner', 'Ampache Series Scanner'); break; case 'music': default: $stype = 'artist'; $dir->addAttribute('type', 'artist'); $dir->addAttribute('agent', 'com.plexapp.agents.none'); // com.plexapp.agents.lastfm $dir->addAttribute('scanner', 'Ampache Music Scanner'); break; } $dir->addAttribute('language', 'en'); $dir->addAttribute('uuid', self::uuidFromSubKey($id)); $dir->addAttribute('updatedAt', Catalog::getLastUpdate($catalogs)); self::setSectionXContent($dir, $catalog, $stype, 'title'); //$date = new DateTime("2013-01-01"); //$dir->addAttribute('createdAt', $date->getTimestamp()); $location = $dir->addChild('Location'); $location->addAttribute('id', $id); $location->addAttribute('path', $catalog->f_name); } } $xml->addAttribute('allowSync', '0'); self::setContainerTitle($xml, 'Plex Library'); }
/** * @function get_rel_path * @discussion returns the path of the song file stripped of the catalog path * used for mpd playback * @param string $file_path * @param int $catalog_id * @return string */ public function get_rel_path($file_path = null, $catalog_id = 0) { $info = null; if (!$file_path) { $info = $this->_get_info(); $file_path = $info['file']; } if (!$catalog_id) { if (!is_array($info)) { $info = $this->_get_info(); } $catalog_id = $info['catalog']; } $catalog = Catalog::create_from_id($catalog_id); return $catalog->get_rel_path($file_path); }
/** * constructor */ public function __construct($id = null, $searchtype = 'song') { $this->searchtype = $searchtype; if ($id) { $info = $this->get_info($id); foreach ($info as $key => $value) { $this->{$key} = $value; } $this->rules = unserialize($this->rules); } // Define our basetypes $this->basetypes['numeric'][] = array('name' => 'gte', 'description' => T_('is greater than or equal to'), 'sql' => '>='); $this->basetypes['numeric'][] = array('name' => 'lte', 'description' => T_('is less than or equal to'), 'sql' => '<='); $this->basetypes['numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>'); $this->basetypes['numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>'); $this->basetypes['numeric'][] = array('name' => 'gt', 'description' => T_('is greater than'), 'sql' => '>'); $this->basetypes['numeric'][] = array('name' => 'lt', 'description' => T_('is less than'), 'sql' => '<'); $this->basetypes['boolean'][] = array('name' => 'true', 'description' => T_('is true')); $this->basetypes['boolean'][] = array('name' => 'false', 'description' => T_('is false')); $this->basetypes['text'][] = array('name' => 'contain', 'description' => T_('contains'), 'sql' => 'LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%')); $this->basetypes['text'][] = array('name' => 'notcontain', 'description' => T_('does not contain'), 'sql' => 'NOT LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%')); $this->basetypes['text'][] = array('name' => 'start', 'description' => T_('starts with'), 'sql' => 'LIKE', 'preg_match' => '/$/', 'preg_replace' => '%'); $this->basetypes['text'][] = array('name' => 'end', 'description' => T_('ends with'), 'sql' => 'LIKE', 'preg_match' => '/^/', 'preg_replace' => '%'); $this->basetypes['text'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '='); $this->basetypes['text'][] = array('name' => 'sounds', 'description' => T_('sounds like'), 'sql' => 'SOUNDS LIKE'); $this->basetypes['text'][] = array('name' => 'notsounds', 'description' => T_('does not sound like'), 'sql' => 'NOT SOUNDS LIKE'); $this->basetypes['boolean_numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>'); $this->basetypes['boolean_numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>'); $this->basetypes['boolean_subsearch'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => ''); $this->basetypes['boolean_subsearch'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => 'NOT'); $this->basetypes['date'][] = array('name' => 'lt', 'description' => T_('before'), 'sql' => '<'); $this->basetypes['date'][] = array('name' => 'gt', 'description' => T_('after'), 'sql' => '>'); $this->basetypes['multiple'] = array_merge($this->basetypes['text'], $this->basetypes['numeric']); switch ($searchtype) { case 'song': $this->types[] = array('name' => 'anywhere', 'label' => T_('Any searchable text'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'album', 'label' => T_('Album'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'composer', 'label' => T_('Composer'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'comment', 'label' => T_('Comment'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'label', 'label' => T_('Label'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'album_tag', 'label' => T_('Album tag'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'file', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'time', 'label' => T_('Length (in minutes)'), 'type' => 'numeric', 'widget' => array('input', 'text')); if (AmpConfig::get('ratings')) { $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars'))); } if (AmpConfig::get('show_played_times')) { $this->types[] = array('name' => 'played_times', 'label' => T_('# Played'), 'type' => 'numeric', 'widget' => array('input', 'text')); } $this->types[] = array('name' => 'bitrate', 'label' => T_('Bitrate'), 'type' => 'numeric', 'widget' => array('select', array('32', '40', '48', '56', '64', '80', '96', '112', '128', '160', '192', '224', '256', '320'))); $this->types[] = array('name' => 'played', 'label' => T_('Played'), 'type' => 'boolean', 'widget' => array('input', 'hidden')); $this->types[] = array('name' => 'added', 'label' => T_('Added'), 'type' => 'date', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'updated', 'label' => T_('Updated'), 'type' => 'date', 'widget' => array('input', 'text')); $catalogs = array(); foreach (Catalog::get_catalogs() as $catid) { $catalog = Catalog::create_from_id($catid); $catalog->format(); $catalogs[$catid] = $catalog->f_name; } $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs)); $playlists = array(); foreach (Playlist::get_playlists() as $playlistid) { $playlist = new Playlist($playlistid); $playlist->format(); $playlists[$playlistid] = $playlist->f_name; } $this->types[] = array('name' => 'playlist', 'label' => T_('Playlist'), 'type' => 'boolean_numeric', 'widget' => array('select', $playlists)); $this->types[] = array('name' => 'playlist_name', 'label' => T_('Playlist Name'), 'type' => 'text', 'widget' => array('input', 'text')); $playlists = array(); foreach (Search::get_searches() as $playlistid) { // Slightly different from the above so we don't instigate // a vicious loop. $playlists[$playlistid] = Search::get_name_byid($playlistid); } $this->types[] = array('name' => 'smartplaylist', 'label' => T_('Smart Playlist'), 'type' => 'boolean_subsearch', 'widget' => array('select', $playlists)); $metadataFields = array(); $metadataFieldRepository = new \Lib\Metadata\Repository\MetadataField(); foreach ($metadataFieldRepository->findAll() as $metadata) { $metadataFields[$metadata->getId()] = $metadata->getName(); } $this->types[] = array('name' => 'metadata', 'label' => T_('Metadata'), 'type' => 'multiple', 'subtypes' => $metadataFields, 'widget' => array('subtypes', array('input', 'text'))); $licenses = array(); foreach (License::get_licenses() as $license_id) { $license = new License($license_id); $licenses[$license_id] = $license->name; } if (AmpConfig::get('licensing')) { $this->types[] = array('name' => 'license', 'label' => T_('Music License'), 'type' => 'boolean_numeric', 'widget' => array('select', $licenses)); } break; case 'album': $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'image width', 'label' => T_('Image Width'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'image height', 'label' => T_('Image Height'), 'type' => 'numeric', 'widget' => array('input', 'text')); if (AmpConfig::get('ratings')) { $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars'))); } $catalogs = array(); foreach (Catalog::get_catalogs() as $catid) { $catalog = Catalog::create_from_id($catid); $catalog->format(); $catalogs[$catid] = $catalog->f_name; } $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs)); $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'video': $this->types[] = array('name' => 'filename', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'artist': $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'yearformed', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'placeformed', 'label' => T_('Place'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'playlist': $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'label': $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'category', 'label' => T_('Category'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'user': $this->types[] = array('name' => 'username', 'label' => T_('Username'), 'type' => 'text', 'widget' => array('input', 'text')); break; } // end switch on searchtype }
<table class="tableform" cellspacing="0" cellpadding="3"> <tr> <td valign="top"><strong><?php echo T_('Catalog'); ?> :</strong></td> <td> <select id="export_catalog" name="export_catalog"> <option value=""><?php echo T_('All'); ?> </option> <?php $catalog_ids = Catalog::get_catalogs(); foreach ($catalog_ids as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); $current_name = 'catalog_' . $catalog->id; ?> <option value="<?php echo $catalog->id; ?> "<?php echo ${$current_name}; ?> ><?php echo scrub_out($catalog->name); ?> </option> <?php } ?>
public static function library_metadata($params) { $r = Plex_XML_Data::createLibContainer(); $n = count($params); $litem = null; $createMode = $_SERVER['REQUEST_METHOD'] == 'POST'; $editMode = $_SERVER['REQUEST_METHOD'] == 'PUT'; if ($n > 0) { $key = $params[0]; $id = Plex_XML_Data::getAmpacheId($key); if ($editMode) { self::check_access(50); } if ($n == 1) { // Should we check that files still exists here? $checkFiles = $_REQUEST['checkFiles']; $extra = $_REQUEST['includeExtra']; if (Plex_XML_Data::isArtist($key)) { $litem = new Artist($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name', 'summary' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addArtist($r, $litem); } elseif (Plex_XML_Data::isAlbum($key)) { $litem = new Album($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name', 'year' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addAlbum($r, $litem); } elseif (Plex_XML_Data::isTrack($key)) { $litem = new Song($id); $litem->format(); if ($editMode) { $dmap = array('title' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addSong($r, $litem); } elseif (Plex_XML_Data::isTVShow($key)) { $litem = new TVShow($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name', 'year' => null, 'summary' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addTVShow($r, $litem); } elseif (Plex_XML_Data::isTVShowSeason($key)) { $litem = new TVShow_Season($id); $litem->format(); Plex_XML_Data::addTVShowSeason($r, $litem); } elseif (Plex_XML_Data::isVideo($key)) { $litem = Video::create_from_id($id); if ($editMode) { $dmap = array('title' => null, 'year' => null, 'originallyAvailableAt' => 'release_date', 'originalTitle' => 'original_name', 'summary' => null); $litem->update(self::get_data_from_map($dmap)); } $litem->format(); $subtype = strtolower(get_class($litem)); if ($subtype == 'tvshow_episode') { Plex_XML_Data::addEpisode($r, $litem, true); } elseif ($subtype == 'movie') { Plex_XML_Data::addMovie($r, $litem, true); } } elseif (Plex_XML_Data::isPlaylist($key)) { $litem = new Playlist($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name'); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addPlaylist($r, $litem); } } else { $subact = $params[1]; if ($subact == "children") { if (Plex_XML_Data::isArtist($key)) { $litem = new Artist($id); $litem->format(); Plex_XML_Data::setArtistRoot($r, $litem); } else { if (Plex_XML_Data::isAlbum($key)) { $litem = new Album($id); $litem->format(); Plex_XML_Data::setAlbumRoot($r, $litem); } else { if (Plex_XML_Data::isTVShow($key)) { $litem = new TVShow($id); $litem->format(); Plex_XML_Data::setTVShowRoot($r, $litem); } else { if (Plex_XML_Data::isTVShowSeason($key)) { $litem = new TVShow_Season($id); $litem->format(); Plex_XML_Data::setTVShowSeasonRoot($r, $litem); } } } } } elseif ($subact == "thumbs" || $subact == "posters" || $subact == "arts" || $subact == 'backgrounds') { $kind = Plex_XML_Data::getPhotoKind($subact); if ($createMode) { // Upload art $litem = Plex_XML_Data::createLibraryItem($key); if ($litem != null) { $uri = Plex_XML_Data::getMetadataUri($key) . '/' . Plex_XML_Data::getPhotoPlexKind($kind) . '/' . $key; if (is_a($litem, 'video')) { $type = 'video'; } else { $type = get_class($litem); } $art = new Art($litem->id, $type, $kind); $raw = file_get_contents("php://input"); $art->insert($raw); header('Content-Type: text/html'); echo $uri; exit; } } Plex_XML_Data::addPhotos($r, $key, $kind); } elseif ($subact == "thumb" || $subact == "poster" || $subact == "art" || $subact == "background") { if ($n == 3) { $kind = Plex_XML_Data::getPhotoKind($subact); // Ignore art id as we can only have 1 thumb $art = null; if (Plex_XML_Data::isArtist($key)) { $art = new Art($id, "artist", $kind); } else { if (Plex_XML_Data::isAlbum($key)) { $art = new Art($id, "album", $kind); } else { if (Plex_XML_Data::isTrack($key)) { $art = new Art($id, "song", $kind); } else { if (Plex_XML_Data::isTVShow($key)) { $art = new Art($id, "tvshow", $kind); } else { if (Plex_XML_Data::isTVShowSeason($key)) { $art = new Art($id, "tvshow_season", $kind); } else { if (Plex_XML_Data::isVideo($key)) { $art = new Art($id, "video", $kind); } } } } } } if ($art != null) { $art->get_db(); ob_clean(); if (!isset($size)) { self::setHeader($art->raw_mime); echo $art->raw; } else { $dim = array(); $dim['width'] = $size; $dim['height'] = $size; $thumb = $art->get_thumb($dim); self::setHeader($art->thumb_mime); echo $thumb['thumb']; } exit; } } } } } if ($litem != null) { $catalog_ids = $litem->get_catalogs(); if (count($catalog_ids) > 0) { $catalog = Catalog::create_from_id($catalog_ids[0]); Plex_XML_Data::addCatalogIdentity($r, $catalog); } } Plex_XML_Data::setContainerSize($r); self::apiOutputXml($r->asXML()); }
public static function process_action($action, $catalogs, $options = null) { if (!$options || !is_array($options)) { $options = array(); } switch ($action) { case 'add_to_all_catalogs': $catalogs = Catalog::get_catalogs(); case 'add_to_catalog': if ($catalogs) { foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); if ($catalog !== null) { $catalog->add_to_catalog($options); } } if (!defined('SSE_OUTPUT')) { AmpError::display('catalog_add'); } } break; case 'update_all_catalogs': $catalogs = Catalog::get_catalogs(); case 'update_catalog': if ($catalogs) { foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); if ($catalog !== null) { $catalog->verify_catalog(); } } } break; case 'full_service': if (!$catalogs) { $catalogs = Catalog::get_catalogs(); } /* This runs the clean/verify/add in that order */ foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); if ($catalog !== null) { $catalog->clean_catalog(); $catalog->verify_catalog(); $catalog->add_to_catalog(); } } Dba::optimize_tables(); break; case 'clean_all_catalogs': $catalogs = Catalog::get_catalogs(); case 'clean_catalog': if ($catalogs) { foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); if ($catalog !== null) { $catalog->clean_catalog(); } } // end foreach catalogs Dba::optimize_tables(); } break; case 'update_from': $catalog_id = 0; // First see if we need to do an add if ($options['add_path'] != '/' && strlen($options['add_path'])) { if ($catalog_id = Catalog_local::get_from_path($options['add_path'])) { $catalog = Catalog::create_from_id($catalog_id); if ($catalog !== null) { $catalog->add_to_catalog(array('subdirectory' => $options['add_path'])); } } } // end if add // Now check for an update if ($options['update_path'] != '/' && strlen($options['update_path'])) { if ($catalog_id = Catalog_local::get_from_path($options['update_path'])) { $songs = Song::get_from_path($options['update_path']); foreach ($songs as $song_id) { Catalog::update_single_item('song', $song_id); } } } // end if update if ($catalog_id <= 0) { AmpError::add('general', T_("This subdirectory is not part of an existing catalog. Update cannot be processed.")); } break; case 'gather_media_art': if (!$catalogs) { $catalogs = Catalog::get_catalogs(); } // Iterate throught the catalogs and gather as needed foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); if ($catalog !== null) { require AmpConfig::get('prefix') . UI::find_template('show_gather_art.inc.php'); flush(); $catalog->gather_art(); } } break; } }
public static function get_root($catalog = null, $username = null) { if ($catalog == null) { $catalog_id = AmpConfig::get('upload_catalog'); if ($catalog_id > 0) { $catalog = Catalog::create_from_id($catalog_id); } } if (is_null($username)) { $username = $GLOBALS['user']->username; } $rootdir = ""; if ($catalog != null && $catalog->id) { $rootdir = realpath($catalog->path); if (!empty($rootdir)) { if (AmpConfig::get('upload_subdir')) { $rootdir .= DIRECTORY_SEPARATOR . $username; if (!Core::is_readable($rootdir)) { debug_event('upload', 'Target user directory `' . $rootdir . '` doesn\'t exists. Creating it...', '5'); mkdir($rootdir); } } } } return $rootdir; }
public static function library_sections($params) { $r = Plex_XML_Data::createLibContainer(); $n = count($params); if ($n == 0) { Plex_XML_Data::setSections($r, Catalog::get_catalogs()); } else { $key = $params[0]; $catalog = Catalog::create_from_id($key); if (!$catalog) { self::createError(404); } if ($n == 1) { Plex_XML_Data::setSectionContent($r, $catalog); } elseif ($n == 2) { $view = $params[1]; if ($view == "all") { Plex_XML_Data::setSectionAll($r, $catalog); } elseif ($view == "albums") { Plex_XML_Data::setSectionAlbums($r, $catalog); } elseif ($view == "recentlyadded") { Plex_XML_Data::setCustomSectionView($r, $catalog, Stats::get_recent('album', 25, $key)); } } } Plex_XML_Data::setContainerSize($r); self::apiOutput($r->asXML()); }
private static function catalog_songs() { // $type = $_GET['type']; $meta = explode(',', strtolower($_GET['meta'])); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $songs = array(); $catalogs = Catalog::get_catalogs(); foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); $songs = array_merge($songs, $catalog->get_songs()); } $o .= self::tlv('dmap.specifiedtotalcount', count($songs)); $o .= self::tlv('dmap.returnedcount', count($songs)); $o .= self::tlv('dmap.listing', self::tlv_songs($songs, $meta)); return $o; }
public static function _musicChilds($prmPath, $prmQuery, $start, $count) { $mediaItems = array(); $maxCount = 0; $queryData = array(); parse_str($prmQuery, $queryData); $parent = 'amp://music' . $prmPath; $pathreq = explode('/', $prmPath); if ($pathreq[0] == '' && count($pathreq) > 0) { array_shift($pathreq); } switch ($pathreq[0]) { case 'artists': switch (count($pathreq)) { case 1: // Get artists list //$artists = Catalog::get_artists(); //list($maxCount, $artists) = self::_slice($artists, $start, $count); $artists = Catalog::get_artists(null, $count, $start); list($maxCount, $artists) = array(999999, $artists); foreach ($artists as $artist) { $artist->format(); $mediaItems[] = self::_itemArtist($artist, $parent); } break; case 2: // Get artist's albums list $artist = new Artist($pathreq[1]); if ($artist->id) { $album_ids = $artist->get_albums(); list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count); foreach ($album_ids as $album_id) { $album = new Album($album_id); $album->format(); $mediaItems[] = self::_itemAlbum($album, $parent); } } break; } break; case 'albums': switch (count($pathreq)) { case 1: // Get albums list //!!$album_ids = Catalog::get_albums(); //!!list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count); $album_ids = Catalog::get_albums($count, $start); list($maxCount, $album_ids) = array(999999, $album_ids); foreach ($album_ids as $album_id) { $album = new Album($album_id); $album->format(); $mediaItems[] = self::_itemAlbum($album, $parent); } break; case 2: // Get album's songs list $album = new Album($pathreq[1]); if ($album->id) { $song_ids = $album->get_songs(); list($maxCount, $song_ids) = self::_slice($song_ids, $start, $count); foreach ($song_ids as $song_id) { $song = new Song($song_id); $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } break; } break; case 'songs': switch (count($pathreq)) { case 1: // Get songs list $catalogs = Catalog::get_catalogs(); foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); $songs = $catalog->get_songs(); list($maxCount, $songs) = self::_slice($songs, $start, $count); foreach ($songs as $song) { $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } break; } break; case 'playlists': switch (count($pathreq)) { case 1: // Get playlists list $pl_ids = Playlist::get_playlists(); list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count); foreach ($pl_ids as $pl_id) { $playlist = new Playlist($pl_id); $playlist->format(); $mediaItems[] = self::_itemPlaylist($playlist, $parent); } break; case 2: // Get playlist's songs list $playlist = new Playlist($pathreq[1]); if ($playlist->id) { $items = $playlist->get_items(); list($maxCount, $items) = self::_slice($items, $start, $count); foreach ($items as $item) { if ($item['object_type'] == 'song') { $song = new Song($item['object_id']); $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } } break; } break; case 'smartplaylists': switch (count($pathreq)) { case 1: // Get playlists list $pl_ids = Search::get_searches(); list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count); foreach ($pl_ids as $pl_id) { $playlist = new Search($pl_id, 'song'); $playlist->format(); $mediaItems[] = self::_itemPlaylist($playlist, $parent); } break; case 2: // Get playlist's songs list $playlist = new Search($pathreq[1], 'song'); if ($playlist->id) { $items = $playlist->get_items(); list($maxCount, $items) = self::_slice($items, $start, $count); foreach ($items as $item) { if ($item['object_type'] == 'song') { $song = new Song($item['object_id']); $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } } break; } break; default: $mediaItems[] = self::_musicMetadata('artists'); $mediaItems[] = self::_musicMetadata('albums'); $mediaItems[] = self::_musicMetadata('songs'); $mediaItems[] = self::_musicMetadata('playlists'); $mediaItems[] = self::_musicMetadata('smartplaylists'); break; } if ($maxCount == 0) { $maxCount = count($mediaItems); } return array($maxCount, $mediaItems); }
/** * update * */ public static function databases($input) { //$revision = $_GET['revision-number']; $o = ''; // Database list if (count($input) == 0) { self::check_session('daap.serverdatabases'); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $o .= self::tlv('dmap.specifiedtotalcount', 1); $o .= self::tlv('dmap.returnedcount', 1); $r = self::tlv('dmap.itemid', 1); $r .= self::tlv('dmap.itemname', 'Ampache'); $counts = Catalog::count_medias(); $r .= self::tlv('dmap.itemcount', $counts['songs']); $r .= self::tlv('dmap.containercount', count(Playlist::get_playlists())); $r = self::tlv('dmap.listingitem', $r); $o .= self::tlv('dmap.listing', $r); $o = self::tlv('daap.serverdatabases', $o); } elseif (count($input) == 2) { if ($input[1] == 'items') { // Songs list self::check_session('daap.playlistsongs'); //$type = $_GET['type']; $meta = explode(',', strtolower($_GET['meta'])); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $songs = array(); $catalogs = Catalog::get_catalogs(); foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); $songs = array_merge($songs, $catalog->get_songs()); } $o .= self::tlv('dmap.specifiedtotalcount', count($songs)); $o .= self::tlv('dmap.returnedcount', count($songs)); $o .= self::tlv('dmap.listing', self::tlv_songs($songs, $meta)); $o = self::tlv('daap.playlistsongs', $o); } elseif ($input[1] == 'containers') { // Playlist list self::check_session('daap.databaseplaylists'); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $playlists = Playlist::get_playlists(); $searches = Search::get_searches(); $o .= self::tlv('dmap.specifiedtotalcount', count($playlists) + count($searches)); $o .= self::tlv('dmap.returnedcount', count($playlists) + count($searches)); $l = ''; foreach ($playlists as $playlist_id) { $playlist = new Playlist($playlist_id); $playlist->format(); $l .= self::tlv_playlist($playlist); } foreach ($searches as $search_id) { $playlist = new Search($search_id, 'song'); $playlist->format(); $l .= self::tlv_playlist($playlist); } $o .= self::tlv('dmap.listing', $l); $o = self::tlv('daap.databaseplaylists', $o); } } elseif (count($input) == 3) { // Stream if ($input[1] == 'items') { $finfo = explode('.', $input[2]); if (count($finfo) == 2) { $id = intval($finfo[0]); $type = $finfo[1]; $params = ''; $headers = apache_request_headers(); $client = $headers['User-Agent']; if (!empty($client)) { $params .= '&client=' . $client; } $params .= '&transcode_to=' . $type; $url = Song::play_url($id, $params, 'api', true); self::follow_stream($url); exit; } } } elseif (count($input) == 4) { // Playlist if ($input[1] == 'containers' && $input[3] == 'items') { $id = intval($input[2]); self::check_session('daap.playlistsongs'); if ($id > Daap_Api::AMPACHEID_SMARTPL) { $id -= Daap_Api::AMPACHEID_SMARTPL; $playlist = new Search($id, 'song'); } else { $playlist = new Playlist($id); } if ($playlist->id) { $meta = explode(',', strtolower($_GET['meta'])); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $items = $playlist->get_items(); $song_ids = array(); foreach ($items as $item) { if ($item['object_type'] == 'song') { $song_ids[] = $item['object_id']; } } if (AmpConfig::get('memory_cache')) { Song::build_cache($song_ids); } $songs = array(); foreach ($song_ids as $song_id) { $songs[] = new Song($song_id); } $o .= self::tlv('dmap.specifiedtotalcount', count($songs)); $o .= self::tlv('dmap.returnedcount', count($songs)); $o .= self::tlv('dmap.listing', self::tlv_songs($songs, $meta)); $o = self::tlv('daap.databaseplaylists', $o); } else { self::createApiError('daap.playlistsongs', 500, 'Invalid playlist id: ' . $id); } } } self::apiOutput($o); }
public function get_chunk() { $chunk = null; if (!$this->is_init) { $this->init_channel_songs(); } if ($this->is_init) { // Move to next song while ($this->media == null && ($this->random || $this->song_pos < count($this->songs))) { if ($this->random) { $randsongs = $this->playlist->get_random_items(1); $this->media = new Song($randsongs[0]['object_id']); } else { $this->media = new Song($this->songs[$this->song_pos]); } $this->media->format(); if ($this->media->catalog) { $catalog = Catalog::create_from_id($this->media->catalog); if (make_bool($this->media->enabled)) { if (AmpConfig::get('lock_songs')) { if (!Stream::check_lock_media($this->media->id, 'song')) { debug_event('channel', 'Media ' . $this->media->id . ' locked, skipped.', '3'); $this->media = null; } } } if ($this->media != null) { $this->media = $catalog->prepare_media($this->media); if (!$this->media->file || !Core::is_readable(Core::conv_lc_file($this->media->file))) { debug_event('channel', 'Cannot read media ' . $this->media->id . ' file, skipped.', '3'); $this->media = null; } else { $valid_types = $this->media->get_stream_types(); if (!in_array('transcode', $valid_types)) { debug_event('channel', 'Missing settings to transcode ' . $this->media->file . ', skipped.', '3'); $this->media = null; } else { debug_event('channel', 'Now listening to ' . $this->media->file . '.', '5'); } } } } else { debug_event('channel', 'Media ' . $this->media->id . ' doesn\'t have catalog, skipped.', '3'); $this->media = null; } $this->song_pos++; // Restart from beginning for next song if the channel is 'loop' enabled // and load fresh data from database if ($this->media != null && $this->song_pos == count($this->songs) && $this->loop) { $this->init_channel_songs(); } } if ($this->media != null) { // Stream not yet initialized for this media, start it if (!$this->transcoder) { $this->transcoder = Stream::start_transcode($this->media, $this->stream_type, $this->bitrate); $this->media_bytes_streamed = 0; } if (is_resource($this->transcoder['handle'])) { $chunk = fread($this->transcoder['handle'], 4096); $this->media_bytes_streamed += strlen($chunk); // End of file, prepare to move on for next call if (feof($this->transcoder['handle'])) { $this->media->set_played(); if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { fread($this->transcoder['stderr'], 4096); fclose($this->transcoder['stderr']); } fclose($this->transcoder['handle']); proc_close($this->transcoder['process']); $this->media = null; $this->transcoder = null; } } else { $this->media = null; $this->transcoder = null; } if (!strlen($chunk)) { $chunk = $this->get_chunk(); } } } return $chunk; }
public function get_chunk() { $chunk = null; if (!$this->is_init) { $this->init_channel_songs(); } if ($this->is_init) { // Move to next song while ($this->media == null && ($this->random || $this->song_pos < count($this->songs))) { if ($this->random) { $randsongs = $this->playlist->get_random_items(1); $this->media = new Song($randsongs[0]['object_id']); } else { $this->media = new Song($this->songs[$this->song_pos]); } $this->media->format(); if ($this->media->catalog) { $catalog = Catalog::create_from_id($this->media->catalog); if (make_bool($this->media->enabled)) { if (AmpConfig::get('lock_songs')) { if (!Stream::check_lock_media($this->media->id, 'song')) { debug_event('channel', 'Media ' . $this->media->id . ' locked, skipped.', '3'); $this->media = null; } } } if ($this->media != null) { $this->media = $catalog->prepare_media($this->media); if (!$this->media->file || !Core::is_readable(Core::conv_lc_file($this->media->file))) { debug_event('channel', 'Cannot read media ' . $this->media->id . ' file, skipped.', '3'); $this->media = null; } else { $valid_types = $this->media->get_stream_types(); if (!in_array('transcode', $valid_types)) { debug_event('channel', 'Missing settings to transcode ' . $this->media->file . ', skipped.', '3'); $this->media = null; } else { debug_event('channel', 'Now listening to ' . $this->media->file . '.', '5'); } } } } else { debug_event('channel', 'Media ' . $this->media->id . ' doesn\'t have catalog, skipped.', '3'); $this->media = null; } $this->song_pos++; // Restart from beginning for next song if the channel is 'loop' enabled // and load fresh data from database if ($this->media != null && $this->song_pos == count($this->songs) && $this->loop) { $this->init_channel_songs(); } } if ($this->media != null) { // Stream not yet initialized for this media, start it if (!$this->transcoder) { $options = array('bitrate' => $this->bitrate); $this->transcoder = Stream::start_transcode($this->media, $this->stream_type, null, $options); $this->media_bytes_streamed = 0; } if (is_resource($this->transcoder['handle'])) { if (ftell($this->transcoder['handle']) == 0) { $this->header_chunk = ''; } $chunk = fread($this->transcoder['handle'], $this->chunk_size); $this->media_bytes_streamed += strlen($chunk); if (ftell($this->transcoder['handle']) < 10000 && strtolower($this->stream_type) == "ogg" || $this->header_chunk_remainder) { //debug_event('channel', 'File handle pointer: ' . ftell($this->transcoder['handle']) ,'5'); $clchunk = $chunk; if ($this->header_chunk_remainder) { $this->header_chunk .= substr($clchunk, 0, $this->header_chunk_remainder); if (strlen($clchunk) >= $this->header_chunk_remainder) { $clchunk = substr($clchunk, $this->header_chunk_remainder); $this->header_chunk_remainder = 0; } else { $this->header_chunk_remainder = $this->header_chunk_remainder - strlen($clchunk); $clchunk = ''; } } // see bin/channel_run.inc for explanation what's happening here while ($this->strtohex(substr($clchunk, 0, 4)) == "4F676753") { $hex = $this->strtohex(substr($clchunk, 0, 27)); $ogg_nr_of_segments = hexdec(substr($hex, 26 * 2, 2)); if (substr($clchunk, 27 + $ogg_nr_of_segments + 1, 6) == "vorbis" || substr($clchunk, 27 + $ogg_nr_of_segments, 4) == "Opus") { $hex .= $this->strtohex(substr($clchunk, 27, $ogg_nr_of_segments)); $ogg_sum_segm_laces = 0; for ($segm = 0; $segm < $ogg_nr_of_segments; $segm++) { $ogg_sum_segm_laces += hexdec(substr($hex, 27 * 2 + $segm * 2, 2)); } $this->header_chunk .= substr($clchunk, 0, 27 + $ogg_nr_of_segments + $ogg_sum_segm_laces); if (strlen($clchunk) < 27 + $ogg_nr_of_segments + $ogg_sum_segm_laces) { $this->header_chunk_remainder = (int) (27 + $ogg_nr_of_segments + $ogg_sum_segm_laces - strlen($clchunk)); } $clchunk = substr($clchunk, 27 + $ogg_nr_of_segments + $ogg_sum_segm_laces); } else { //no more interesting headers $clchunk = ''; } } } //debug_event('channel', 'File handle pointer: ' . ftell($this->transcoder['handle']) ,'5'); //debug_event('channel', 'CHUNK : ' . $chunk, '5'); //debug_event('channel', 'Chunk size: ' . strlen($chunk) ,'5'); // End of file, prepare to move on for next call if (feof($this->transcoder['handle'])) { $this->media->set_played(-1, 'Ampache', array()); if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { fread($this->transcoder['stderr'], 4096); fclose($this->transcoder['stderr']); } fclose($this->transcoder['handle']); Stream::kill_process($this->transcoder); $this->media = null; $this->transcoder = null; } } else { $this->media = null; $this->transcoder = null; } if (!strlen($chunk)) { $chunk = $this->get_chunk(); } } } return $chunk; }
protected function get_catalog_all_pts($fct, pData $MyData, $catalog = 0, $object_type = null, $object_id = 0, $start_date = null, $end_date = null, $zoom = 'day') { $values = $this->get_all_pts($fct, $MyData, $catalog, $object_type, $object_id, $start_date, $end_date, $zoom, false); // Only display other users if the graph is not for a specific catalog if (!$catalog) { $catalog_ids = Catalog::get_catalogs(); foreach ($catalog_ids as $catalog_id) { $c = Catalog::create_from_id($catalog_id); $catalog_values = $this->get_all_type_pts($fct, $catalog_id, $object_type, $object_id, $start_date, $end_date, $zoom); $pv = 0; foreach ($values as $date => $value) { if (array_key_exists($date, $catalog_values)) { $value = $catalog_values[$date]; $pv = $value; } else { $value = $pv; } $MyData->addPoints($value, $c->name); } } } }
public static function addMusicFolders($xml, $catalogs) { $xfolders = $xml->addChild('musicFolders'); foreach ($catalogs as $id) { $catalog = Catalog::create_from_id($id); $xfolder = $xfolders->addChild('musicFolder'); $xfolder->addAttribute('id', $id); $xfolder->addAttribute('name', $catalog->name); } }
$type = 'video'; $media = new Video($oid); if (isset($_REQUEST['subtitle'])) { $subtitle = $media->get_subtitle_file($_REQUEST['subtitle']); } $media->format(); } } if (!User::stream_control(array(array('object_type' => $type, 'object_id' => $media->id)))) { debug_event('UI::access_denied', 'Stream control failed for user ' . $GLOBALS['user']->username . ' on ' . $media->get_stream_name(), 3); UI::access_denied(); exit; } if ($media->catalog) { // Build up the catalog for our current object $catalog = Catalog::create_from_id($media->catalog); /* If the media is disabled */ if (!make_bool($media->enabled)) { debug_event('Play', "Error: {$media->file} is currently disabled, song skipped", '5'); // Check to see if this is a democratic playlist, if so remove it completely if ($demo_id && isset($democratic)) { $democratic->delete_from_oid($oid, $type); } header('HTTP/1.1 404 File Disabled'); exit; } // If we are running in Legalize mode, don't play medias already playing if (AmpConfig::get('lock_songs')) { if (!Stream::check_lock_media($media->id, $type)) { exit; }
/** * show_objects * This takes an array of objects * and requires the correct template based on the * type that we are currently browsing */ public function show_objects($object_ids = null, $argument = null) { if ($this->is_simple() || !is_array($object_ids)) { $object_ids = $this->get_saved(); } else { $this->save_objects($object_ids); } // Limit is based on the user's preferences if this is not a // simple browse because we've got too much here if (count($object_ids) > $this->get_start() && !$this->is_simple() && !$this->is_static_content()) { $object_ids = array_slice($object_ids, $this->get_start(), $this->get_offset(), true); } else { if (!count($object_ids)) { $this->set_total(0); } } // Load any additional object we need for this $extra_objects = $this->get_supplemental_objects(); $browse = $this; foreach ($extra_objects as $class_name => $id) { ${$class_name} = new $class_name($id); } $match = ''; // Format any matches we have so we can show them to the masses if ($filter_value = $this->get_filter('alpha_match')) { $match = ' (' . $filter_value . ')'; } elseif ($filter_value = $this->get_filter('starts_with')) { $match = ' (' . $filter_value . ')'; /*} elseif ($filter_value = $this->get_filter('regex_match')) { $match = ' (' . $filter_value . ')'; } elseif ($filter_value = $this->get_filter('regex_not_match')) { $match = ' (' . $filter_value . ')';*/ } elseif ($filter_value = $this->get_filter('catalog')) { // Get the catalog title $catalog = Catalog::create_from_id($filter_value); $match = ' (' . $catalog->name . ')'; } $type = $this->get_type(); // Set the correct classes based on type $class = "box browse_" . $type; debug_event('browse', 'Called for type {' . $type . '}', '5'); // Switch on the type of browsing we're doing switch ($type) { case 'song': $box_title = T_('Songs') . $match; Song::build_cache($object_ids); $box_req = AmpConfig::get('prefix') . '/templates/show_songs.inc.php'; break; case 'album': $box_title = T_('Albums') . $match; Album::build_cache($object_ids); $allow_group_disks = $argument; $box_req = AmpConfig::get('prefix') . '/templates/show_albums.inc.php'; break; case 'user': $box_title = T_('Manage Users') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_users.inc.php'; break; case 'artist': $box_title = T_('Artists') . $match; Artist::build_cache($object_ids, 'extra'); $box_req = AmpConfig::get('prefix') . '/templates/show_artists.inc.php'; break; case 'live_stream': require_once AmpConfig::get('prefix') . '/templates/show_live_stream.inc.php'; $box_title = T_('Radio Stations') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_live_streams.inc.php'; break; case 'playlist': Playlist::build_cache($object_ids); $box_title = T_('Playlists') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_playlists.inc.php'; break; case 'playlist_song': $box_title = T_('Playlist Songs') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_playlist_songs.inc.php'; break; case 'playlist_localplay': $box_title = T_('Current Playlist'); $box_req = AmpConfig::get('prefix') . '/templates/show_localplay_playlist.inc.php'; UI::show_box_bottom(); break; case 'smartplaylist': $box_title = T_('Smart Playlists') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_smartplaylists.inc.php'; break; case 'catalog': $box_title = T_('Catalogs'); $box_req = AmpConfig::get('prefix') . '/templates/show_catalogs.inc.php'; break; case 'shoutbox': $box_title = T_('Shoutbox Records'); $box_req = AmpConfig::get('prefix') . '/templates/show_manage_shoutbox.inc.php'; break; case 'tag': Tag::build_cache($object_ids); $box_title = T_('Tag Cloud'); $box_req = AmpConfig::get('prefix') . '/templates/show_tagcloud.inc.php'; break; case 'video': Video::build_cache($object_ids); $box_title = T_('Videos'); $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php'; break; case 'democratic': $box_title = T_('Democratic Playlist'); $box_req = AmpConfig::get('prefix') . '/templates/show_democratic_playlist.inc.php'; break; case 'wanted': $box_title = T_('Wanted Albums'); $box_req = AmpConfig::get('prefix') . '/templates/show_wanted_albums.inc.php'; break; case 'share': $box_title = T_('Shared Objects'); $box_req = AmpConfig::get('prefix') . '/templates/show_shared_objects.inc.php'; break; case 'song_preview': $box_title = T_('Songs'); $box_req = AmpConfig::get('prefix') . '/templates/show_song_previews.inc.php'; break; case 'channel': $box_title = T_('Channels'); $box_req = AmpConfig::get('prefix') . '/templates/show_channels.inc.php'; break; case 'broadcast': $box_title = T_('Broadcasts'); $box_req = AmpConfig::get('prefix') . '/templates/show_broadcasts.inc.php'; break; default: // Rien a faire break; } // end switch on type Ajax::start_container('browse_content_' . $type, 'browse_content'); if ($this->get_show_header()) { if (isset($box_req) && isset($box_title)) { UI::show_box_top($box_title, $class); } } if (isset($box_req)) { require $box_req; } if ($this->get_show_header()) { if (isset($box_req)) { UI::show_box_bottom(); } echo '<script type="text/javascript">'; echo Ajax::action('?page=browse&action=get_filters&browse_id=' . $this->id, ''); echo ';</script>'; } else { if (!$this->get_use_pages()) { $this->show_next_link(); } } Ajax::end_container(); }
/** * update_media_from_tags * This is a 'wrapper' function calls the update function for the media * type in question */ public static function update_media_from_tags($media, $sort_pattern = '', $rename_pattern = '') { // Check for patterns if (!$sort_pattern or !$rename_pattern) { $catalog = Catalog::create_from_id($media->catalog); $sort_pattern = $catalog->sort_pattern; $rename_pattern = $catalog->rename_pattern; } debug_event('tag-read', 'Reading tags from ' . $media->file, 5); $vainfo = new vainfo($media->file, '', '', '', $sort_pattern, $rename_pattern); $vainfo->get_info(); $key = vainfo::get_tag_type($vainfo->tags); $results = vainfo::clean_tag_info($vainfo->tags, $key, $media->file); // Figure out what type of object this is and call the right // function, giving it the stuff we've figured out above $name = get_class($media) == 'Song' ? 'song' : 'video'; $function = 'update_' . $name . '_from_tags'; $return = call_user_func(array('Catalog', $function), $results, $media); return $return; }
public function get_root_path() { $catalog = Catalog::create_from_id($this->catalog); if (!$catalog->get_type() == 'local') { debug_event('podcast', 'Bad catalog type.', 1); return ''; } $dirname = $this->title; return $catalog->path . DIRECTORY_SEPARATOR . $dirname; }
/** * create * This is a static function that takes a key'd array for input * and if everything is good creates the object. */ public static function create(array $data) { // Make sure we've got a name if (!strlen($data['name'])) { AmpError::add('name', T_('Name Required')); } $allowed_array = array('https', 'http', 'mms', 'mmsh', 'mmsu', 'mmst', 'rtsp', 'rtmp'); $elements = explode(":", $data['url']); if (!in_array($elements['0'], $allowed_array)) { AmpError::add('url', T_('Invalid URL must be http:// or https://')); } if (!empty($data['site_url'])) { $elements = explode(":", $data['site_url']); if (!in_array($elements['0'], $allowed_array)) { AmpError::add('site_url', T_('Invalid URL must be http:// or https://')); } } // Make sure it's a real catalog $catalog = Catalog::create_from_id($data['catalog']); if (!$catalog->name) { AmpError::add('catalog', T_('Invalid Catalog')); } if (AmpError::occurred()) { return false; } // If we've made it this far everything must be ok... I hope $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`codec`) " . "VALUES (?, ?, ?, ?, ?)"; $db_results = Dba::write($sql, array($data['name'], $data['site_url'], $data['url'], $catalog->id, $data['codec'])); return $db_results; }
* along with this program. If not, see <http://www.gnu.org/licenses/>. * */ /** * Sub-Ajax page, requires AJAX_INCLUDE */ if (!defined('AJAX_INCLUDE')) { exit; } switch ($_REQUEST['action']) { case 'flip_state': if (!Access::check('interface', '75')) { debug_event('DENIED', $GLOBALS['user']->username . ' attempted to change the state of a catalog', '1'); exit; } $catalog = Catalog::create_from_id($_REQUEST['catalog_id']); $new_enabled = $catalog->enabled ? false : true; $catalog->update_enabled($new_enabled, $catalog->id); $catalog->enabled = $new_enabled; $catalog->format(); //Return the new Ajax::button $id = 'button_flip_state_' . $catalog->id; $button = $catalog->enabled ? 'disable' : 'enable'; $results[$id] = Ajax::button('?page=catalog&action=flip_state&catalog_id=' . $catalog->id, $button, T_(ucfirst($button)), 'flip_state_' . $catalog->id); break; default: $results['rfc3514'] = '0x1'; break; } // switch on action; // We always do this
/** * getIndexes * Get an indexed structure of all artists. * Takes optional musicFolderId and optional ifModifiedSince in parameters. */ public static function getindexes($input) { self::check_version($input); set_time_limit(300); $musicFolderId = $input['musicFolderId']; $ifModifiedSince = $input['ifModifiedSince']; $catalogs = array(); if (!empty($musicFolderId) && $musicFolderId != '-1') { $catalogs[] = $musicFolderId; } else { $catalogs = Catalog::get_catalogs(); } $lastmodified = 0; $fcatalogs = array(); foreach ($catalogs as $id) { $clastmodified = 0; $catalog = Catalog::create_from_id($id); if ($catalog->last_update > $clastmodified) { $clastmodified = $catalog->last_update; } if ($catalog->last_add > $clastmodified) { $clastmodified = $catalog->last_add; } if ($catalog->last_clean > $clastmodified) { $clastmodified = $catalog->last_clean; } if ($clastmodified > $lastmodified) { $lastmodified = $clastmodified; } if (!empty($ifModifiedSince) && $clastmodified > $ifModifiedSince / 1000) { $fcatalogs[] = $id; } } if (empty($ifModifiedSince)) { $fcatalogs = $catalogs; } $r = Subsonic_XML_Data::createSuccessResponse(); if (count($fcatalogs) > 0) { $artists = Catalog::get_artists($fcatalogs); Subsonic_XML_Data::addArtistsIndexes($r, $artists, $lastmodified); } self::apiOutput($input, $r); }
?> </th> <th class="cel_lastclean optional "><?php echo T_('Last Clean'); ?> </th> <th class="cel_action cel_action_text essential"><?php echo T_('Actions'); ?> </th> </tr> </thead> <tbody> <?php foreach ($object_ids as $catalog_id) { $libitem = Catalog::create_from_id($catalog_id); $libitem->format(); ?> <tr class="<?php echo UI::flip_class(); ?> " id="catalog_<?php echo $libitem->id; ?> "> <?php require AmpConfig::get('prefix') . UI::find_template('show_catalog_row.inc.php'); ?> </tr> <?php }
/** * show_objects * This takes an array of objects * and requires the correct template based on the * type that we are currently browsing * * @param int[] $object_ids */ public function show_objects($object_ids = null, $argument = null) { if ($this->is_simple() || !is_array($object_ids)) { $object_ids = $this->get_saved(); } else { $this->save_objects($object_ids); } // Limit is based on the user's preferences if this is not a // simple browse because we've got too much here if ($this->get_start() >= 0 && count($object_ids) > $this->get_start() && !$this->is_simple()) { $object_ids = array_slice($object_ids, $this->get_start(), $this->get_offset(), true); } else { if (!count($object_ids)) { $this->set_total(0); } } // Load any additional object we need for this $extra_objects = $this->get_supplemental_objects(); $browse = $this; foreach ($extra_objects as $class_name => $id) { ${$class_name} = new $class_name($id); } $match = ''; // Format any matches we have so we can show them to the masses if ($filter_value = $this->get_filter('alpha_match')) { $match = ' (' . $filter_value . ')'; } elseif ($filter_value = $this->get_filter('starts_with')) { $match = ' (' . $filter_value . ')'; /*} elseif ($filter_value = $this->get_filter('regex_match')) { $match = ' (' . $filter_value . ')'; } elseif ($filter_value = $this->get_filter('regex_not_match')) { $match = ' (' . $filter_value . ')';*/ } elseif ($filter_value = $this->get_filter('catalog')) { // Get the catalog title $catalog = Catalog::create_from_id(intval($filter_value)); $match = ' (' . $catalog->name . ')'; } $type = $this->get_type(); // Update the session value only if it's allowed on the current browser if ($this->get_update_session()) { $_SESSION['browse_current_' . $type]['start'] = $browse->get_start(); } // Set the correct classes based on type $class = "box browse_" . $type; $argument_param = $argument ? '&argument=' . scrub_in($argument) : ''; debug_event('browse', 'Show objects called for type {' . $type . '}', '5'); $limit_threshold = $this->get_threshold(); // Switch on the type of browsing we're doing switch ($type) { case 'song': $box_title = T_('Songs') . $match; Song::build_cache($object_ids, $limit_threshold); $box_req = AmpConfig::get('prefix') . '/templates/show_songs.inc.php'; break; case 'album': Album::build_cache($object_ids); $box_title = T_('Albums') . $match; if (is_array($argument)) { $allow_group_disks = $argument['group_disks']; if ($argument['title']) { $box_title = $argument['title']; } } else { $allow_group_disks = false; } $box_req = AmpConfig::get('prefix') . '/templates/show_albums.inc.php'; break; case 'user': $box_title = T_('Users') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_users.inc.php'; break; case 'artist': $box_title = T_('Artists') . $match; Artist::build_cache($object_ids, true, $limit_threshold); $box_req = AmpConfig::get('prefix') . '/templates/show_artists.inc.php'; break; case 'live_stream': require_once AmpConfig::get('prefix') . '/templates/show_live_stream.inc.php'; $box_title = T_('Radio Stations') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_live_streams.inc.php'; break; case 'playlist': Playlist::build_cache($object_ids); $box_title = T_('Playlists') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_playlists.inc.php'; break; case 'playlist_song': $box_title = T_('Playlist Songs') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_playlist_songs.inc.php'; break; case 'playlist_localplay': $box_title = T_('Current Playlist'); $box_req = AmpConfig::get('prefix') . '/templates/show_localplay_playlist.inc.php'; UI::show_box_bottom(); break; case 'smartplaylist': $box_title = T_('Smart Playlists') . $match; $box_req = AmpConfig::get('prefix') . '/templates/show_searches.inc.php'; break; case 'catalog': $box_title = T_('Catalogs'); $box_req = AmpConfig::get('prefix') . '/templates/show_catalogs.inc.php'; break; case 'shoutbox': $box_title = T_('Shoutbox Records'); $box_req = AmpConfig::get('prefix') . '/templates/show_manage_shoutbox.inc.php'; break; case 'tag': Tag::build_cache($object_ids); $box_title = T_('Tag Cloud'); $box_req = AmpConfig::get('prefix') . '/templates/show_tagcloud.inc.php'; break; case 'video': Video::build_cache($object_ids); $video_type = 'video'; $box_title = T_('Videos'); $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php'; break; case 'democratic': $box_title = T_('Democratic Playlist'); $box_req = AmpConfig::get('prefix') . '/templates/show_democratic_playlist.inc.php'; break; case 'wanted': $box_title = T_('Wanted Albums'); $box_req = AmpConfig::get('prefix') . '/templates/show_wanted_albums.inc.php'; break; case 'share': $box_title = T_('Shared Objects'); $box_req = AmpConfig::get('prefix') . '/templates/show_shared_objects.inc.php'; break; case 'song_preview': $box_title = T_('Songs'); $box_req = AmpConfig::get('prefix') . '/templates/show_song_previews.inc.php'; break; case 'channel': $box_title = T_('Channels'); $box_req = AmpConfig::get('prefix') . '/templates/show_channels.inc.php'; break; case 'broadcast': $box_title = T_('Broadcasts'); $box_req = AmpConfig::get('prefix') . '/templates/show_broadcasts.inc.php'; break; case 'license': $box_title = T_('Media Licenses'); $box_req = AmpConfig::get('prefix') . '/templates/show_manage_license.inc.php'; break; case 'tvshow': $box_title = T_('TV Shows'); $box_req = AmpConfig::get('prefix') . '/templates/show_tvshows.inc.php'; break; case 'tvshow_season': $box_title = T_('Seasons'); $box_req = AmpConfig::get('prefix') . '/templates/show_tvshow_seasons.inc.php'; break; case 'tvshow_episode': $box_title = T_('Episodes'); $video_type = $type; $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php'; break; case 'movie': $box_title = T_('Movies'); $video_type = $type; $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php'; break; case 'clip': $box_title = T_('Clips'); $video_type = $type; $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php'; break; case 'personal_video': $box_title = T_('Personal Videos'); $video_type = $type; $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php'; break; case 'label': $box_title = T_('Labels'); $box_req = AmpConfig::get('prefix') . '/templates/show_labels.inc.php'; break; case 'pvmsg': $box_title = T_('Private Messages'); $box_req = AmpConfig::get('prefix') . '/templates/show_pvmsgs.inc.php'; break; default: // Rien a faire break; } // end switch on type Ajax::start_container($this->get_content_div(), 'browse_content'); if ($this->get_show_header()) { if (isset($box_req) && isset($box_title)) { UI::show_box_top($box_title, $class); } } if (isset($box_req)) { require $box_req; } if ($this->get_show_header()) { if (isset($box_req)) { UI::show_box_bottom(); } echo '<script type="text/javascript">'; echo Ajax::action('?page=browse&action=get_filters&browse_id=' . $this->id . $argument_param, ''); echo ';</script>'; } else { if (!$this->get_use_pages()) { $this->show_next_link($argument); } } Ajax::end_container(); }
public static function setSections($xml, $catalogs) { foreach ($catalogs as $id) { $catalog = Catalog::create_from_id($id); $catalog->format(); $dir = $xml->addChild('Directory'); $dir->addAttribute('filters', '1'); $dir->addAttribute('refreshing', '0'); $dir->addAttribute('key', $id); $dir->addAttribute('type', 'artist'); $dir->addAttribute('agent', 'com.plexapp.agents.none'); // com.plexapp.agents.lastfm $dir->addAttribute('scanner', 'Plex Music Scanner'); $dir->addAttribute('language', 'en'); $dir->addAttribute('uuid', self::uuidFromSubKey($id)); $dir->addAttribute('updatedAt', self::getLastUpdate($catalogs)); self::setSectionXContent($dir, $catalog, 'title'); //$date = new DateTime("2013-01-01"); //$dir->addAttribute('createdAt', $date->getTimestamp()); $location = $dir->addChild('Location'); $location->addAttribute('id', $id); $location->addAttribute('path', $catalog->f_full_info); } $xml->addAttribute('allowSync', '0'); self::setContainerTitle($xml, 'Plex Library'); }