Example #1
0
 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());
 }
Example #2
0
 public static function library_metadata($params)
 {
     $r = Plex_XML_Data::createLibContainer();
     $n = count($params);
     if ($n > 0) {
         $key = $params[0];
         $id = Plex_XML_Data::getAmpacheId($key);
         if ($n == 1) {
             // Should we check that files still exists here?
             $checkFiles = $_REQUEST['checkFiles'];
             if (Plex_XML_Data::isArtist($key)) {
                 $artist = new Artist($id);
                 $artist->format();
                 Plex_XML_Data::addArtist($r, $artist);
             } elseif (Plex_XML_Data::isAlbum($key)) {
                 $album = new Album($id);
                 $album->format();
                 Plex_XML_Data::addAlbum($r, $album);
             } elseif (Plex_XML_Data::isTrack($key)) {
                 $song = new Song($id);
                 $song->format();
                 Plex_XML_Data::addSong($r, $song);
             }
         } else {
             $subact = $params[1];
             if ($subact == "children") {
                 if (Plex_XML_Data::isArtist($key)) {
                     $artist = new Artist($id);
                     $artist->format();
                     Plex_XML_Data::setArtistRoot($r, $artist);
                 } else {
                     if (Plex_XML_Data::isAlbum($key)) {
                         $album = new Album($id);
                         $album->format();
                         Plex_XML_Data::setAlbumRoot($r, $album);
                     }
                 }
             } elseif ($subact == "thumb") {
                 if ($n == 3) {
                     // Ignore thumb id as we can only have 1 thumb
                     $art = null;
                     if (Plex_XML_Data::isArtist($key)) {
                         $art = new Art($id, "artist");
                     } else {
                         if (Plex_XML_Data::isAlbum($key)) {
                             $art = new Art($id, "album");
                         } else {
                             if (Plex_XML_Data::isTrack($key)) {
                                 $art = new Art($id, "song");
                             }
                         }
                     }
                     if ($art != null) {
                         $art->get_db();
                         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;
                     }
                 }
             }
         }
     }
     Plex_XML_Data::setContainerSize($r);
     self::apiOutput($r->asXML());
 }