Example #1
0
 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];
             $gtypes = $catalog->get_gather_types();
             if ($gtypes[0] == 'music') {
                 $type = 'artist';
                 if ($_GET['type']) {
                     $type = Plex_XML_Data::getAmpacheType($_GET['type']);
                 }
                 if ($view == "all") {
                     switch ($type) {
                         case 'artist':
                             Plex_XML_Data::setSectionAll_Artists($r, $catalog);
                             break;
                         case 'album':
                             Plex_XML_Data::setSectionAll_Albums($r, $catalog);
                             break;
                     }
                 } elseif ($view == "albums") {
                     Plex_XML_Data::setSectionAlbums($r, $catalog);
                 } elseif ($view == "recentlyadded") {
                     Plex_XML_Data::setCustomSectionView($r, $catalog, Stats::get_recent('album', 25, $key));
                 } elseif ($view == "genre") {
                     Plex_XML_Data::setSectionTags($r, $catalog, 'song');
                 }
             } elseif ($gtypes[0] == "tvshow") {
                 $type = 'tvshow';
                 if ($_GET['type']) {
                     $type = Plex_XML_Data::getAmpacheType($_GET['type']);
                 }
                 if ($view == "all") {
                     switch ($type) {
                         case 'tvshow':
                             Plex_XML_Data::setSectionAll_TVShows($r, $catalog);
                             break;
                         case 'season':
                             Plex_XML_Data::setSectionAll_Seasons($r, $catalog);
                             break;
                         case 'episode':
                             Plex_XML_Data::setSectionAll_Episodes($r, $catalog);
                             break;
                     }
                 } elseif ($view == "recentlyadded") {
                     Plex_XML_Data::setCustomSectionView($r, $catalog, Stats::get_recent('tvshow_episode', 25, $key));
                 } elseif ($view == "genre") {
                     Plex_XML_Data::setSectionTags($r, $catalog, 'video');
                 }
             } elseif ($gtypes[0] == "movie") {
                 $type = 'tvshow';
                 if ($_GET['type']) {
                     $type = Plex_XML_Data::getAmpacheType($_GET['type']);
                 }
                 if ($view == "all") {
                     Plex_XML_Data::setSectionAll_Movies($r, $catalog);
                 } elseif ($view == "recentlyadded") {
                     Plex_XML_Data::setCustomSectionView($r, $catalog, Stats::get_recent('movie', 25, $key));
                 } elseif ($view == "genre") {
                     Plex_XML_Data::setSectionTags($r, $catalog, 'video');
                 }
             }
         }
     }
     Plex_XML_Data::setContainerSize($r);
     self::apiOutputXml($r->asXML());
 }