title; // If the artist is worth noticing, include them into the search. if (!$song->artist->isUnknown() && !$song->artist->isVarious()) { $q .= ' '.$song->artist->name; } return $this->search($q, $pageToken); } /** * Search for YouTube videos by a query string. * * @param string $q The query string * @param string $pageToken YouTube page token (e.g. for next/previous page) * @param int $perPage Number of results per page * * @return object|false */ public function search($q, $pageToken = '', $perPage = 10) { if (!$this->enabled()) { return false; } $uri = sprintf('search?part=snippet&type=video&maxResults=%s&pageToken=%s&q=%s', $perPage, urlencode($pageToken), urlencode($q) ); $cacheKey = md5("youtube_$uri"); if ($response = cache($cacheKey)) { return $response; } if ($response = $this->get($uri)) { // Cache the result for 7 days cache([$cacheKey => $response], 60 * 24 * 7); } return $response; } }