/** * Gets information about all queued YouTube videos and applies it to the * stored videos in the local playlist. * * After fetching the video info, the queue of videos is cleared. * * @access private * @since 0.4 */ private function _retrieve_queued_video_info() { // Abort if we have no videos in the queue global $nxtdb; $queue = $this->get_option('info_queue'); if (empty($queue)) { return; } // Request information on all videos in the queue using a single connection $conn = new ClassBlogs_Http(self::_YOUTUBE_VIDEO_INFO_URL_TEMPLATE); $queue_length = count($queue) - 1; for ($i = 0; $i <= $queue_length; $i++) { $request = sprintf(self::_YOUTUBE_VIDEO_INFO_URL_TEMPLATE, $queue[$i]); $conn->add_request_line("GET {$request} HTTP/1.1\r\n"); if ($i != $queue_length) { $conn->add_request_line("\r\n"); } } $responses = $conn->get_responses(); $conn->close_connection(); // Update each video in the local playlist with the information found // in the YouTube API response foreach ($responses as $response) { $xml = ClassBlogs_Utils::xml_from_string($response->body); $title = ClassBlogs_Utils::get_single_xml_tag_value($xml, 'title'); $youtube_id = ClassBlogs_Utils::get_single_xml_tag_value($xml, 'videoid', self::_YT_NAMESPACE); if ($title && $youtube_id) { $nxtdb->query($nxtdb->prepare("\n\t\t\t\t\tUPDATE {$this->tables->videos}\n\t\t\t\t\tSET title = %s\n\t\t\t\t\tWHERE youtube_id = %s", $title, $youtube_id)); } } // Clear the queue $this->update_option('info_queue', array()); }