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]
");
+ }
?>