original_string: private function _get_collection($keyword, $start, $max, $sort) {
          global $SESSION;
  
          // The new API doesn't use "page" numbers for browsing through results.
          // It uses a prev and next token in each set that you need to use to
          // request the next page of results.
          $sesspagetoken = 'youtube_'.$this->id.'_nextpagetoken';
          $pagetoken = '';
          if ($start > 1 && isset($SESSION->{$sesspagetoken})) {
              $pagetoken = $SESSION->{$sesspagetoken};
          }
  
          $list = array();
          $error = null;
          try {
              $this->init_youtube_service(); // About to use the service, ensure it's loaded.
              $response = $this->service->search->listSearch('id,snippet', array(
                  'q' => $keyword,
                  'maxResults' => $max,
                  'order' => $sort,
                  'pageToken' => $pagetoken,
                  'type' => 'video',
                  'videoEmbeddable' => 'true',
              ));
  
              // Track the next page token for the next request (when a user
              // scrolls down in the file picker for more videos).
              $SESSION->{$sesspagetoken} = $response['nextPageToken'];
  
              foreach ($response['items'] as $result) {
                  $title = $result->snippet->title;
                  $source = 'http://www.youtube.com/v/' . $result->id->videoId . '#' . $title;
                  $thumb = $result->snippet->getThumbnails()->getDefault();
  
                  $list[] = array(
                      'shorttitle' => $title,
                      'thumbnail_title' => $result->snippet->description,
                      'title' => $title.'.avi', // This is a hack so we accept this file by extension.
                      'thumbnail' => $thumb->url,
                      'thumbnail_width' => (int)$thumb->width,
                      'thumbnail_height' => (int)$thumb->height,
                      'size' => '',
                      'date' => '',
                      'source' => $source,
                  );
              }
          } catch (Google_Service_Exception $e) {
              // If we throw the google exception as-is, we may expose the apikey
              // to end users. The full message in the google exception includes
              // the apikey param, so we take just the part pertaining to the
              // actual error.
              $error = $e->getErrors()[0]['message'];
              throw new moodle_exception('apierror', 'repository_youtube', '', $error);
          }
  
          return $list;
      }
code: private function _get_collection($keyword, $start, $max, $sort) {
          global $SESSION;
  
          // The new API doesn't use "page" numbers for browsing through results.
          // It uses a prev and next token in each set that you need to use to
          // request the next page of results.
          $sesspagetoken = 'youtube_'.$this->id.'_nextpagetoken';
          $pagetoken = '';
          if ($start > 1 && isset($SESSION->{$sesspagetoken})) {
              $pagetoken = $SESSION->{$sesspagetoken};
          }
  
          $list = array();
          $error = null;
          try {
              $this->init_youtube_service(); // About to use the service, ensure it's loaded.
              $response = $this->service->search->listSearch('id,snippet', array(
                  'q' => $keyword,
                  'maxResults' => $max,
                  'order' => $sort,
                  'pageToken' => $pagetoken,
                  'type' => 'video',
                  'videoEmbeddable' => 'true',
              ));
  
              // Track the next page token for the next request (when a user
              // scrolls down in the file picker for more videos).
              $SESSION->{$sesspagetoken} = $response['nextPageToken'];
  
              foreach ($response['items'] as $result) {
                  $title = $result->snippet->title;
                  $source = 'http://www.youtube.com/v/' . $result->id->videoId . '#' . $title;
                  $thumb = $result->snippet->getThumbnails()->getDefault();
  
                  $list[] = array(
                      'shorttitle' => $title,
                      'thumbnail_title' => $result->snippet->description,
                      'title' => $title.'.avi', // This is a hack so we accept this file by extension.
                      'thumbnail' => $thumb->url,
                      'thumbnail_width' => (int)$thumb->width,
                      'thumbnail_height' => (int)$thumb->height,
                      'size' => '',
                      'date' => '',
                      'source' => $source,
                  );
              }
          } catch (Google_Service_Exception $e) {
              // If we throw the google exception as-is, we may expose the apikey
              // to end users. The full message in the google exception includes
              // the apikey param, so we take just the part pertaining to the
              // actual error.
              $error = $e->getErrors()[0]['message'];
              throw new moodle_exception('apierror', 'repository_youtube', '', $error);
          }
  
          return $list;
      }
code_tokens: private function _get_collection ( $ keyword , $ start , $ max , $ sort ) { global $ SESSION ; // The new API doesn't use "page" numbers for browsing through results. // It uses a prev and next token in each set that you need to use to // request the next page of results. $ sesspagetoken = 'youtube_' . $ this -> id . '_nextpagetoken' ; $ pagetoken = '' ; if ( $ start > 1 && isset ( $ SESSION -> { $ sesspagetoken } ) ) { $ pagetoken = $ SESSION -> { $ sesspagetoken } ; } $ list = array ( ) ; $ error = null ; try { $ this -> init_youtube_service ( ) ; // About to use the service, ensure it's loaded. $ response = $ this -> service -> search -> listSearch ( 'id,snippet' , array ( 'q' => $ keyword , 'maxResults' => $ max , 'order' => $ sort , 'pageToken' => $ pagetoken , 'type' => 'video' , 'videoEmbeddable' => 'true' , ) ) ; // Track the next page token for the next request (when a user // scrolls down in the file picker for more videos). $ SESSION -> { $ sesspagetoken } = $ response [ 'nextPageToken' ] ; foreach ( $ response [ 'items' ] as $ result ) { $ title = $ result -> snippet -> title ; $ source = 'http://www.youtube.com/v/' . $ result -> id -> videoId . '#' . $ title ; $ thumb = $ result -> snippet -> getThumbnails ( ) -> getDefault ( ) ; $ list [ ] = array ( 'shorttitle' => $ title , 'thumbnail_title' => $ result -> snippet -> description , 'title' => $ title . '.avi' , // This is a hack so we accept this file by extension. 'thumbnail' => $ thumb -> url , 'thumbnail_width' => ( int ) $ thumb -> width , 'thumbnail_height' => ( int ) $ thumb -> height , 'size' => '' , 'date' => '' , 'source' => $ source , ) ; } } catch ( Google_Service_Exception $ e ) { // If we throw the google exception as-is, we may expose the apikey // to end users. The full message in the google exception includes // the apikey param, so we take just the part pertaining to the // actual error. $ error = $ e -> getErrors ( ) [ 0 ] [ 'message' ] ; throw new moodle_exception ( 'apierror' , 'repository_youtube' , '' , $ error ) ; } return $ list ; }
docstring: Private method to get youtube search results
  @param string $keyword
  @param int $start
  @param int $max max results
  @param string $sort
  @throws moodle_exception If the google API returns an error.
  @return array
docstring_tokens: Private method to get youtube search results