Skip to content

Commit

Permalink
Fix creating YouTube API URLs for channel & playlist searches (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
VerifiedJoseph authored May 13, 2024
1 parent 3f4a31e commit c512be1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions include/Helper/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Url
'searchChannels' => [
'endpoint' => 'search',
'query' => [
'q' => '',
'part' => [
'id',
'snippet',
Expand All @@ -72,14 +73,14 @@ class Url
'items(id(channelId)',
'snippet(title))'
],
'q' => '',
'type' => 'channel',
'maxResults' => 1
],
],
'searchPlaylists' => [
'endpoint' => 'search',
'query' => [
'q' => '',
'part' => [
'id',
'snippet',
Expand All @@ -88,7 +89,6 @@ class Url
'items(id(playlistId)',
'snippet(title))'
],
'q' => '',
'type' => 'playlist',
'maxResults' => 1
],
Expand Down Expand Up @@ -235,10 +235,10 @@ public static function getApi(string $type, string $parameter, string $apiKey)
foreach (self::$apiEndpoints[$type]['query'] as $name => $section) {
if (is_array($section) === true) {
$query[$name] = implode(',', $section);
} elseif ($name === 'q') {
$query[$name] = urlencode($parameter);
} else {
} elseif ($name === 'q' || $name === 'id') {
$query[$name] = $parameter;
} else {
$query[$name] = $section;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/files/helper-url-samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
"value" :"jNQXAC9IVRw"
},
{
"url": "https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&fields=items%28id%28channelId%29%2Csnippet%28title%29%29&q=jawed&type=jawed&maxResults=jawed&prettyPrint=true&key=ApiKeyHere",
"url": "https://www.googleapis.com/youtube/v3/search?q=jawed&part=id%2Csnippet&fields=items%28id%28channelId%29%2Csnippet%28title%29%29&type=channel&maxResults=1&prettyPrint=true&key=ApiKeyHere",
"type": "searchChannels",
"value" :"jawed"
},
{
"url": "https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&fields=items%28id%28playlistId%29%2Csnippet%28title%29%29&q=YouTube%2BRewind%2B2018&type=YouTube+Rewind+2018&maxResults=YouTube+Rewind+2018&prettyPrint=true&key=ApiKeyHere",
"url": "https://www.googleapis.com/youtube/v3/search?q=YouTube+Rewind+2018&part=id%2Csnippet&fields=items%28id%28playlistId%29%2Csnippet%28title%29%29&type=playlist&maxResults=1&prettyPrint=true&key=ApiKeyHere",
"type": "searchPlaylists",
"value" :"YouTube Rewind 2018"
}
Expand Down

0 comments on commit c512be1

Please sign in to comment.