/** * @Todo recupérer la thumbnail d'une playlist * * @param string $object * @param int $offset_start * @param int $quantity * @return Bridge_Api_ContainerCollection */ public function list_containers($object, $offset_start = 0, $quantity = 10) { switch ($object) { case self::CONTAINER_TYPE_PLAYLIST: $username = $this->get_user_name(); $params = ['fields' => ['description', 'id', 'name'], 'page' => !$offset_start ? 1 : $offset_start]; //add quantity if (!!$quantity) { $params["limit"] = $quantity; } $url = sprintf('/me/%ss', $object); $result = $this->_api->call($url, $params, $this->oauth_token); $container_collection = new Bridge_Api_ContainerCollection(); $container_collection->set_items_per_page($result["limit"]); $total = sizeof($result["list"]); $current_page = $result["limit"]; $total_page = null; $container_collection->set_total_items($total); $container_collection->set_current_page($current_page); $container_collection->set_total_page($total_page); foreach ($result['list'] as $entry) { //get 1st image $list_element = $this->list_containers_content($object, $entry['id'], ['thumbnail_medium_url'], 1); $elements = $list_element->get_elements(); $first_element = array_shift($elements); $thumbnail = $first_element instanceof Bridge_Api_Dailymotion_Element ? $first_element->get_thumbnail() : ''; $url = $this->get_url_playlist($entry['id'], $entry['name'], $username); $container_collection->add_element(new Bridge_Api_Dailymotion_Container($entry, $object, $thumbnail, $url)); } return $container_collection; break; default: throw new Bridge_Exception_ElementUnknown('Unknown element ' . $object); break; } }
/** * * @param string $object * @param int $offset_start * @param int $quantity * @return Bridge_Api_ContainerCollection */ public function list_containers($object, $offset_start = 0, $quantity = 10) { switch ($object) { case self::CONTAINER_TYPE_PLAYLIST: $playlist_feed = $this->get_user_object_list_feed($object, $offset_start, $quantity); $container_collection = new Bridge_Api_ContainerCollection(); $container_collection->set_items_per_page($playlist_feed->getItemsPerPage()->getText()); $total = $playlist_feed->getTotalResults()->getText(); $current_page = floor((int) $playlist_feed->getStartIndex()->getText() / (int) $playlist_feed->getItemsPerPage()->getText()); $total_page = ceil((int) $total / (int) $playlist_feed->getItemsPerPage()->getText()); $container_collection->set_total_items($total); $container_collection->set_current_page($current_page); $container_collection->set_total_page($total_page); foreach ($playlist_feed as $entry) { $playlist_video_feed = $this->_api->getPlaylistVideoFeed($entry->getPlaylistVideoFeedUrl()); $thumbnail = null; if (!is_null($playlist_video_feed)) { foreach ($playlist_video_feed as $entry2) { $playlist_thumbnails = $entry2->getVideoThumbnails(); foreach ($playlist_thumbnails as $playlist_thumbnail) { if (120 == $playlist_thumbnail['width'] && 90 == $playlist_thumbnail['height']) { $thumbnail = $playlist_thumbnail['url']; break; } } break; } } $container_collection->add_element(new Bridge_Api_Youtube_Container($entry, $object, $thumbnail)); } return $container_collection; break; default: throw new Bridge_Exception_ElementUnknown('Unknown element ' . $object); break; } }