From 4015f92c4ea08cff98af3c93169804abcb0e07ef Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Sat, 7 Jan 2023 04:59:20 +0100 Subject: [PATCH] =?UTF-8?q?#47:=20Use=20`"`=20=C3=A0=20la=20`printf`=20ins?= =?UTF-8?q?tead=20of=20`'`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addKey.php | 2 +- channels.php | 24 ++++++++++++------------ commentThreads.php | 4 ++-- common.php | 14 +++++++------- community.php | 4 ++-- constants.php | 2 +- index.php | 35 ++++++++++++++++++++--------------- keys.php | 2 +- liveChats.php | 6 +++--- lives.php | 6 +++--- playlistItems.php | 4 ++-- playlists.php | 4 ++-- search.php | 4 ++-- videos.php | 34 +++++++++++++++++----------------- ytPrivate/test.php | 8 ++++---- ytPrivate/tests.php | 4 ++-- 16 files changed, 81 insertions(+), 76 deletions(-) diff --git a/addKey.php b/addKey.php index 65690c3..79d1465 100644 --- a/addKey.php +++ b/addKey.php @@ -15,7 +15,7 @@ 'ignore_errors' => true, ] ]; - $content = getJSON('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=mWdFMNQBcjs&key=' . $key, $httpOptions); + $content = getJSON("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=mWdFMNQBcjs&key=$key", $httpOptions); if ($content['items'][0]['snippet']['title'] === 'A public video') { file_put_contents(KEYS_FILE, ($keysContent === '' ? '' : "\n") . $key, FILE_APPEND); echo 'YouTube Data API v3 key added.'; diff --git a/channels.php b/channels.php index bfcf82e..41f7450 100644 --- a/channels.php +++ b/channels.php @@ -19,7 +19,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -36,7 +36,7 @@ "header" => 'Cookie: CONSENT=YES+' ] ]; - $result = getJSONFromHTML('https://www.youtube.com/c/' . $forUsername . '/about', $opts); + $result = getJSONFromHTML("https://www.youtube.com/c/$forUsername/about", $opts); $id = $result['header']['c4TabbedHeaderRenderer']['channelId']; } else if (isset($_GET['id'])) { $id = $_GET['id']; @@ -48,7 +48,7 @@ if (!isHandle($handle)) { die('invalid handle'); } - $result = getJSONFromHTML('https://www.youtube.com/@' . $handle); + $result = getJSONFromHTML("https://www.youtube.com/@$handle"); $id = $result['responseContext']['serviceTrackingParams'][0]['params'][6]['value']; } $continuationToken = ''; @@ -80,14 +80,14 @@ function getItem($id, $continuationToken) $httpOptions = [ 'http' => $http ]; - $result = getJSONFromHTML('https://www.youtube.com/channel/' . $id, $httpOptions); + $result = getJSONFromHTML("https://www.youtube.com/channel/$id", $httpOptions); $status = $result['alerts'][0]['alertRenderer']['text']['simpleText']; $item['status'] = $status; } if ($options['premieres']) { $premieres = []; - $result = getJSONFromHTML('https://www.youtube.com/channel/' . $id); + $result = getJSONFromHTML("https://www.youtube.com/channel/$id"); $subItems = $result['contents']['twoColumnBrowseResultsRenderer']['tabs'][0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['shelfRenderer']['content']['horizontalListRenderer']['items']; foreach ($subItems as $subItem) { $subItem = $subItem['gridVideoRenderer']; @@ -112,7 +112,7 @@ function getItem($id, $continuationToken) $httpOptions = [ 'http' => $http ]; - $result = getJSONFromHTML('https://www.youtube.com/channel/' . $id . '/shorts', $httpOptions); + $result = getJSONFromHTML("https://www.youtube.com/channel/$id/shorts", $httpOptions); $visitorData = $result['responseContext']['webResponseContextExtensionData']['ytConfigData']['visitorData']; } else { $continuationParts = explode(',', $continuationToken); @@ -122,7 +122,7 @@ function getItem($id, $continuationToken) $http = [ 'header' => [ 'Content-Type: application/json', - 'X-Goog-EOM-Visitor-Id: ' . $visitorData + "X-Goog-EOM-Visitor-Id: $visitorData" ], 'method' => 'POST', 'content' => $rawData @@ -163,7 +163,7 @@ function getItem($id, $continuationToken) } $item['shorts'] = $shorts; if($reelShelfRendererItems != null && count($reelShelfRendererItems) > 48) - $item['nextPageToken'] = urldecode($reelShelfRendererItems[48]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'] . ',' . $visitorData); + $item['nextPageToken'] = urldecode($reelShelfRendererItems[48]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'] . ",$visitorData"); } if ($options['community']) { @@ -176,7 +176,7 @@ function getItem($id, $continuationToken) 'http' => $http ]; - $result = getJSONFromHTML('https://www.youtube.com/channel/' . $id . '/community', $httpOptions); + $result = getJSONFromHTML("https://www.youtube.com/channel/$id/community", $httpOptions); } else { $rawData = '{"context":{"client":{"clientName":"WEB","clientVersion":"' . MUSIC_VERSION . '"}},"continuation":"' . $continuationToken . '"}'; $http = [ @@ -226,7 +226,7 @@ function getItem($id, $continuationToken) 'http' => $http ]; - $result = getJSONFromHTML('https://www.youtube.com/channel/' . $id . '/channels', $httpOptions); + $result = getJSONFromHTML("https://www.youtube.com/channel/$id/channels", $httpOptions); $sectionListRenderer = array_slice($result['contents']['twoColumnBrowseResultsRenderer']['tabs'], -3)[0]['tabRenderer']['content']['sectionListRenderer']; $channels = []; $channelsItems = $sectionListRenderer['contents'][0]['itemSectionRenderer']['contents'][0]['gridRenderer']['items']; @@ -264,7 +264,7 @@ function getItem($id, $continuationToken) 'http' => $http ]; - $result = getJSONFromHTML('https://www.youtube.com/channel/' . $id . '/about', $httpOptions); + $result = getJSONFromHTML("https://www.youtube.com/channel/$id/about", $httpOptions); $resultCommon = array_slice($result['contents']['twoColumnBrowseResultsRenderer']['tabs'], -2)[0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['channelAboutFullMetadataRenderer']; @@ -313,7 +313,7 @@ function getItem($id, $continuationToken) 'http' => $http ]; - $result = getJSONFromHTML('https://www.youtube.com/channel/' . $id, $httpOptions); + $result = getJSONFromHTML("https://www.youtube.com/channel/$id", $httpOptions); $badgeTooltipPath = 'header/c4TabbedHeaderRenderer/badges/0/metadataBadgeRenderer/tooltip'; $item['approval'] = doesPathExist($result, $badgeTooltipPath) ? getValue($result, $badgeTooltipPath) : ''; } diff --git a/commentThreads.php b/commentThreads.php index 9896079..e3f9a4a 100644 --- a/commentThreads.php +++ b/commentThreads.php @@ -18,7 +18,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -58,7 +58,7 @@ function getAPI($videoId, $order, $continuationToken) ]; $result = getJSON('https://www.youtube.com/youtubei/v1/next?key=' . UI_KEY, $opts); } else { - $result = getJSONFromHTML('https://www.youtube.com/watch?v=' . $videoId); + $result = getJSONFromHTML("https://www.youtube.com/watch?v=$videoId"); $continuationToken = ($order === 'time' ? $result['engagementPanels'][2]['engagementPanelSectionListRenderer']['header']['engagementPanelTitleHeaderRenderer']['menu']['sortFilterSubMenuRenderer']['subMenuItems'][1]['serviceEndpoint'] : end($result['contents']['twoColumnWatchNextResults']['results']['results']['contents'])['itemSectionRenderer']['contents'][0]['continuationItemRenderer']['continuationEndpoint'])['continuationCommand']['token']; return getAPI($videoId, $order, $continuationToken); } diff --git a/common.php b/common.php index db2e75d..b6f60f1 100644 --- a/common.php +++ b/common.php @@ -55,7 +55,7 @@ function getJSON($url, $opts = []) function getJSONFromHTMLScriptPrefix($html, $scriptPrefix) { - $html = explode(';', explode('">' . $scriptPrefix, $html, 3)[1], 2)[0]; + $html = explode(';', explode("\">$scriptPrefix", $html, 3)[1], 2)[0]; return json_decode($html, true); } @@ -65,7 +65,7 @@ function getJSONStringFromHTML($html, $scriptVariable = '', $prefix = 'var ') if ($scriptVariable === '') { $scriptVariable = 'ytInitialData'; } - return explode(';', explode('">' . $prefix . $scriptVariable . ' = ', $html, 3)[1], 2)[0]; + return explode(';', explode("\">$prefix$scriptVariable = ", $html, 3)[1], 2)[0]; } function getJSONFromHTML($url, $opts = [], $scriptVariable = '', $prefix = 'var ') @@ -77,7 +77,7 @@ function getJSONFromHTML($url, $opts = [], $scriptVariable = '', $prefix = 'var function checkRegex($regex, $str) { - return preg_match('/^' . $regex . '$/', $str) === 1; + return preg_match("/^$regex$/", $str) === 1; } function isContinuationToken($continuationToken) @@ -178,12 +178,12 @@ function getValue($json, $path) function getIntValue($unitCount, $unit) { - $unitCount = str_replace(' ' . $unit . 's', '', $unitCount); - $unitCount = str_replace(' ' . $unit, '', $unitCount); + $unitCount = str_replace(" {$unit}s", '', $unitCount); + $unitCount = str_replace(" $unit", '', $unitCount); $unitCount = str_replace('K', '*1000', $unitCount); $unitCount = str_replace('M', '*1000000', $unitCount); if(checkRegex('[0-9.*KM]+', $unitCount)) { - $unitCount = eval('return ' . $unitCount . ';'); + $unitCount = eval("return $unitCount;"); } return $unitCount; } @@ -211,7 +211,7 @@ function getCommunityPostFromContent($content) } else { $url = $navigationEndpoint['browseEndpoint']['canonicalBaseUrl']; } - $contentTextItem['url'] = 'https://www.youtube.com' . $url; + $contentTextItem['url'] = "https://www.youtube.com$url"; } } array_push($contentText, $contentTextItem); diff --git a/community.php b/community.php index 3e42382..55f7ac1 100644 --- a/community.php +++ b/community.php @@ -13,7 +13,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -36,7 +36,7 @@ function getAPI($postId) 'http' => $http ]; - $result = getJSONFromHTML('https://www.youtube.com/post/' . $postId, $options); + $result = getJSONFromHTML("https://www.youtube.com/post/$postId", $options); $content = $result['contents']['twoColumnBrowseResultsRenderer']['tabs'][0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]; $post = getCommunityPostFromContent($content); diff --git a/constants.php b/constants.php index 42793f5..c04f508 100644 --- a/constants.php +++ b/constants.php @@ -2,7 +2,7 @@ define('DOMAIN_NAME', $_SERVER['SERVER_NAME']); $protocol = (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on')) ? 'https' : 'http'; - define('WEBSITE_URL', $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + define('WEBSITE_URL', "$protocol://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"); define('SUB_VERSION_STR', '.9999099'); define('KEYS_FILE', '/var/www/ytPrivate/keys.txt'); diff --git a/index.php b/index.php index 9139de5..764e478 100644 --- a/index.php +++ b/index.php @@ -9,7 +9,7 @@ function url($url, $name = '') if ($name === '') { $name = $url; } - return '' . $name . ''; + return "$name"; } function yt() @@ -19,20 +19,20 @@ function yt() function feature($feature) { - $suburl = $feature[0]; + $suburl = "$feature[0]/list"; $webpage = explode('/', $suburl, 2)[0]; $url = $feature[1]; $name = ucfirst(str_replace('/', ': ', $suburl)); - echo 'Based on ' . $name . ': ' . url(WEBSITE_URL . $webpage . '?part=' . $url) . '
'; + echo "Based on $name: " . url(WEBSITE_URL . "$webpage?part=$url") . '
'; } - $features = [['channels/list', 'status,premieres,shorts,community,channels,about,approval,playlists&forUsername=USERNAME&id=CHANNEL_ID&handle=HANDLE'], - ['community/list', 'snippet&id=POST_ID'], - ['commentThreads/list', 'snippet,replies&videoId=VIDEO_ID&order=relevance,time(&pageToken=PAGE_TOKEN)'], - ['playlists/list', 'snippet,statistics&id=PLAYLIST_ID'], - ['playlistItems/list', 'snippet&playlistId=PLAYLIST_ID(&pageToken=PAGE_TOKEN)'], - ['search/list', 'id,snippet&q=QUERY&channelId=CHANNEL_ID&eventType=upcoming&hashTag=HASH_TAG&type=video&order=viewCount,relevance(&pageToken=PAGE_TOKEN)'], - ['videos/list', 'id,status,contentDetails,music,short,impressions,musics,isPaidPromotion,isPremium,isMemberOnly,mostReplayed,qualities,chapters,isOriginal,isRestricted&id=VIDEO_ID&clipId=CLIP_ID&SAPISIDHASH=YOUR_SAPISIDHASH']]; + $features = [['channels', 'status,premieres,shorts,community,channels,about,approval,playlists&forUsername=USERNAME&id=CHANNEL_ID&handle=HANDLE'], + ['community', 'snippet&id=POST_ID'], + ['commentThreads', 'snippet,replies&videoId=VIDEO_ID&order=relevance,time(&pageToken=PAGE_TOKEN)'], + ['playlists', 'snippet,statistics&id=PLAYLIST_ID'], + ['playlistItems', 'snippet&playlistId=PLAYLIST_ID(&pageToken=PAGE_TOKEN)'], + ['search', 'id,snippet&q=QUERY&channelId=CHANNEL_ID&eventType=upcoming&hashTag=HASH_TAG&type=video&order=viewCount,relevance(&pageToken=PAGE_TOKEN)'], + ['videos', 'id,status,contentDetails,music,short,impressions,musics,isPaidPromotion,isPremium,isMemberOnly,mostReplayed,qualities,chapters,isOriginal,isRestricted&id=VIDEO_ID&clipId=CLIP_ID&SAPISIDHASH=YOUR_SAPISIDHASH']]; ?> @@ -46,15 +46,20 @@ function feature($feature) } echo '
'; - echo url(WEBSITE_URL . 'lives' . '?part=' . 'donations&id=VIDEO_ID') . '
'; - echo url(WEBSITE_URL . 'liveChats' . '?part=' . 'snippet,participants&id=VIDEO_ID&time=TIME_MS') . '
'; + + $features = [['lives', 'donations&id=VIDEO_ID'], + ['liveChats', 'snippet,participants&id=VIDEO_ID&time=TIME_MS']]; + + foreach ($features as $feature) { + echo url(WEBSITE_URL . "$feature[0]?part=$feature[1]
"); + } ?>

Make request WITHOUT ANY KEY:

-To make ANY request WITHOUT ANY KEY/USING YOUR QUOTA, you can use:
-For instance you can use: instead of
+To make ANY request WITHOUT ANY KEY/USING YOUR QUOTA, you can use:
+For instance you can use: instead of
I may add in the future limitation per IP etc if the quota need to be better shared among the persons using this API.

This instance uses version: ' . $hash . ''; + echo "

This instance uses version: $hash"; } ?> diff --git a/keys.php b/keys.php index 2358666..4bcd8dd 100644 --- a/keys.php +++ b/keys.php @@ -1,3 +1,3 @@ -All keys have all worked at least once and some keys may have extended quota (more than 10 000). +All keys have all worked at least once and some keys may have extended quota (more than 10,000). diff --git a/liveChats.php b/liveChats.php index 2600db6..34efb75 100644 --- a/liveChats.php +++ b/liveChats.php @@ -15,7 +15,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -43,7 +43,7 @@ function getItem($id) { global $options; - $result = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id); + $result = getJSONFromHTML("https://www.youtube.com/watch?v=$id"); $continuation = $result['contents']['twoColumnWatchNextResults']['conversationBar']['liveChatRenderer']['continuations'][0]['reloadContinuationData']['continuation']; $rawData = '{"context":{"client":{"clientName":"WEB","clientVersion":"' . MUSIC_VERSION . '"}},"continuation":"' . $continuation . '","currentPlayerState":{"playerOffsetMs":"' . $_GET['time'] . '"}}'; @@ -83,7 +83,7 @@ function getItem($id) ] ]; - $result = getJSONFromHTML('https://www.youtube.com/live_chat?continuation=' . $continuation, $opts, 'window["ytInitialData"]', ''); + $result = getJSONFromHTML("https://www.youtube.com/live_chat?continuation=$continuation", $opts, 'window["ytInitialData"]', ''); $participants = array_slice($result['continuationContents']['liveChatContinuation']['actions'], 1); $item['participants'] = $participants; } diff --git a/lives.php b/lives.php index 6ef96ab..1c384da 100644 --- a/lives.php +++ b/lives.php @@ -15,7 +15,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -39,7 +39,7 @@ function getItem($id) { global $options; - $result = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id); + $result = getJSONFromHTML("https://www.youtube.com/watch?v=$id"); $continuation = $result['contents']['twoColumnWatchNextResults']['conversationBar']['liveChatRenderer']['continuations'][0]['reloadContinuationData']['continuation']; $opts = [ @@ -47,7 +47,7 @@ function getItem($id) "user_agent" => USER_AGENT, ] ]; - $html = getJSONFromHTML('https://www.youtube.com/live_chat?continuation=' . $continuation, $opts, 'window["ytInitialData"]', ''); + $html = getJSONFromHTML("https://www.youtube.com/live_chat?continuation=$continuation", $opts, 'window["ytInitialData"]', ''); $item = [ 'kind' => 'youtube#video', diff --git a/playlistItems.php b/playlistItems.php index a4c3d42..d983c3d 100644 --- a/playlistItems.php +++ b/playlistItems.php @@ -37,7 +37,7 @@ function getAPI($playlistId, $continuationToken) $http['header'] = 'Content-Type: application/json'; $http['content'] = $rawData; } else { - $url = 'https://www.youtube.com/playlist?list=' . $playlistId; + $url = "https://www.youtube.com/playlist?list=$playlistId"; $http['header'] = ['Cookie: CONSENT=YES+', 'Accept-Language: en']; } @@ -90,7 +90,7 @@ function getAPI($playlistId, $continuationToken) break; } } - $publishedAt = time() - eval('return ' . $publishedAtStr . ';'); + $publishedAt = time() - eval("return $publishedAtStr;"); // the time is not perfectly accurate this way $answerItem = [ 'kind' => 'youtube#playlistItem', diff --git a/playlists.php b/playlists.php index ea8974a..13017a2 100644 --- a/playlists.php +++ b/playlists.php @@ -16,7 +16,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -43,7 +43,7 @@ function getItem($id) "header" => ['Cookie: CONSENT=YES+', 'Accept-Language: en'] ] ]; - $result = getJSONFromHTML('https://www.youtube.com/playlist?list=' . $id, $opts); + $result = getJSONFromHTML("https://www.youtube.com/playlist?list=$id", $opts); if ($options['snippet']) { $title = $result['metadata']['playlistMetadataRenderer']['title']; } diff --git a/search.php b/search.php index b4e05ce..b3373be 100644 --- a/search.php +++ b/search.php @@ -23,7 +23,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -100,7 +100,7 @@ function getAPI($id, $order, $continuationToken) } $items = $continuationTokenProvided ? $json['onResponseReceivedActions'][0]['appendContinuationItemsAction']['continuationItems'] : $json['contents']['twoColumnBrowseResultsRenderer']['tabs'][0]['tabRenderer']['content']['richGridRenderer']['contents']; } elseif (isset($_GET['eventType'])) { - $json = getJSONFromHTML('https://www.youtube.com/channel/' . $_GET['channelId'] . '/videos?view=2&live_view=502'); + $json = getJSONFromHTML("https://www.youtube.com/channel/{$_GET['channelId']}/videos?view=2&live_view=502"); $items = $json['contents']['twoColumnBrowseResultsRenderer']['tabs']['1']['tabRenderer']['content']['sectionListRenderer']['contents']['0']['itemSectionRenderer']['contents']['0']['gridRenderer']['items']; } elseif (isset($_GET['q'])) { $typeBase64 = 'EgIQAQ=='; diff --git a/videos.php b/videos.php index 59cb4a9..eb8e775 100644 --- a/videos.php +++ b/videos.php @@ -23,7 +23,7 @@ $parts = explode(',', $part, count($realOptions)); foreach ($parts as $part) { if (!in_array($part, $realOptions)) { - die('invalid part ' . $part); + die("invalid part $part"); } else { $options[$part] = true; } @@ -38,7 +38,7 @@ } foreach ($realIds as $realId) { if ((!$isClip && !isVideoId($realId)) && !isClipId($realId)) { - die('invalid ' . $field); + die("invalid $field"); } } @@ -110,7 +110,7 @@ function getItem($id) if ($options['short']) { $short = [ - 'available' => !isRedirection('https://www.youtube.com/shorts/' . $id) + 'available' => !isRedirection("https://www.youtube.com/shorts/$id") ]; $item['short'] = $short; } @@ -118,7 +118,7 @@ function getItem($id) if ($options['impressions']) { $headers = [ "x-origin: https://studio.youtube.com", - "authorization: SAPISIDHASH " . $_GET['SAPISIDHASH'], + "authorization: SAPISIDHASH {$_GET['SAPISIDHASH']}", "Content-Type:", "cookie: HSID=A4BqSu4moNA0Be1N9; SSID=AA0tycmNyGWo-Z_5v; APISID=a; SAPISID=zRbK-_14V7wIAieP/Ab_wY1sjLVrKQUM2c; SID=HwhYm6rJKOn_3R9oOrTNDJjpHIiq9Uos0F5fv4LPdMRSqyVHA1EDZwbLXo0kuUYAIN_MUQ." ]; @@ -145,7 +145,7 @@ function getItem($id) $httpOptions = [ 'http' => $http ]; - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id, $httpOptions); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", $httpOptions); $musics = []; $engagementPanels = $json['engagementPanels']; @@ -217,31 +217,31 @@ function getItem($id) } if ($options['id'] && isset($_GET['clipId'])) { - $json = getJSONFromHTML('https://www.youtube.com/clip/' . $id); + $json = getJSONFromHTML("https://www.youtube.com/clip/$id"); $videoId = $json['currentVideoEndpoint']['watchEndpoint']['videoId']; $item['videoId'] = $videoId; } if ($options['isPaidPromotion']) { - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id, [], 'ytInitialPlayerResponse'); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", [], 'ytInitialPlayerResponse'); $isPaidPromotion = array_key_exists('paidContentOverlay', $json); $item['isPaidPromotion'] = $isPaidPromotion; } if ($options['isPremium']) { - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id"); $isPremium = array_key_exists('offerModule', $json['contents']['twoColumnWatchNextResults']['secondaryResults']['secondaryResults']); $item['isPremium'] = $isPremium; } if ($options['isMemberOnly']) { - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id, $opts); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", $opts); $isMemberOnly = array_key_exists('badges', $json['contents']['twoColumnWatchNextResults']['results']['results']['contents'][0]['videoPrimaryInfoRenderer']); $item['isMemberOnly'] = $isMemberOnly; } if ($options['mostReplayed']) { - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id"); $markerMap = end($json['playerOverlays']['playerOverlayRenderer']['decoratedPlayerBarRenderer']['decoratedPlayerBarRenderer']['playerBar']['multiMarkersPlayerBarRenderer']['markersMap']); $mostReplayed = $markerMap['value']['heatmap']['heatmapRenderer']; // What is `Dp` in `maxHeightDp` and `minHeightDp` ? If not relevant could add ['heatMarkers'] to the JSON path above. @@ -249,7 +249,7 @@ function getItem($id) } if ($options['qualities']) { - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id, [], 'ytInitialPlayerResponse'); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", [], 'ytInitialPlayerResponse'); $qualities = []; foreach ($json['streamingData']['adaptiveFormats'] as $quality) { if (array_key_exists('qualityLabel', $quality)) { @@ -263,13 +263,13 @@ function getItem($id) } if ($options['location']) { - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id"); $location = $json['contents']['twoColumnWatchNextResults']['results']['results']['contents'][0]['videoPrimaryInfoRenderer']['superTitleLink']['runs'][0]['text']; $item['location'] = $location; } if ($options['chapters']) { - $json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id); + $json = getJSONFromHTML("https://www.youtube.com/watch?v=$id"); $chapters = []; $contents = $json['engagementPanels'][1]['engagementPanelSectionListRenderer']['content']['macroMarkersListRenderer']['contents']; $areAutoGenerated = array_key_exists('macroMarkersInfoItemRenderer', $contents[0]); @@ -281,10 +281,10 @@ function getItem($id) $timeParts = explode(':', $timeStr); $timePartsCount = count($timeParts); $minutes = $timeParts[$timePartsCount - 2]; - $timeParts[$timePartsCount - 2] = strlen($minutes) == 1 ? '0' . $minutes : $minutes; + $timeParts[$timePartsCount - 2] = strlen($minutes) == 1 ? "0$minutes" : $minutes; $timeStr = implode(':', $timeParts); for ($timePartsIndex = 0; $timePartsIndex < 4 - $timePartsCount; $timePartsIndex++) { - $timeStr = '00:' . $timeStr; + $timeStr = "00:$timeStr"; } while (date_parse_from_format($format, $timeStr) === false) { $format = substr($format, 2); @@ -308,7 +308,7 @@ function getItem($id) } if ($options['isOriginal']) { - $html = getRemote('https://www.youtube.com/watch?v=' . $id); + $html = getRemote("https://www.youtube.com/watch?v=$id"); $jsonStr = getJSONStringFromHTML($html); $json = json_decode($jsonStr, true); $isOriginal = doesPathExist($json, 'contents/twoColumnWatchNextResults/results/results/contents/1/videoSecondaryInfoRenderer/metadataRowContainer/metadataRowContainerRenderer/rows/2/metadataRowRenderer/contents/0/simpleText'); @@ -324,7 +324,7 @@ function getItem($id) "header" => ["cookie: PREF=f2=8000000"], ] ]; - $html = getRemote('https://www.youtube.com/watch?v=' . $id, $opts); + $html = getRemote("https://www.youtube.com/watch?v=$id", $opts); $jsonStr = getJSONStringFromHTML($html, 'ytInitialPlayerResponse'); $json = json_decode($jsonStr, true); $playabilityStatus = $json['playabilityStatus']; diff --git a/ytPrivate/test.php b/ytPrivate/test.php index a6b9f7b..38bdaee 100644 --- a/ytPrivate/test.php +++ b/ytPrivate/test.php @@ -1,16 +1,16 @@