Skip to content

Commit c21362f

Browse files
Fix #321: Use getJSONFromHTML forceLanguage parameter than getJSONFromHTMLForcingLanguage
1 parent 261b4b0 commit c21362f

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

channels.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ function getItem($id, $order, $continuationToken)
151151
$continuationTokenProvided = $continuationToken != '';
152152

153153
if ($options['status']) {
154-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id", true);
154+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id", forceLanguage: true, verifiesChannelRedirection: true);
155155
$status = $result['alerts'][0]['alertRenderer']['text']['simpleText'];
156156
$item['status'] = $status;
157157
}
158158

159159
if ($options['upcomingEvents']) {
160160
$upcomingEvents = [];
161-
$result = getJSONFromHTML("https://www.youtube.com/channel/$id", verifiesChannelRedirection: true);
161+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id", forceLanguage: true, verifiesChannelRedirection: true);
162162
$subItems = getTabs($result)[0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['shelfRenderer']['content']['horizontalListRenderer']['items'];
163163
foreach ($subItems as $subItem) {
164164
$path = 'gridVideoRenderer/upcomingEventData';
@@ -175,7 +175,7 @@ function getItem($id, $order, $continuationToken)
175175

176176
if ($options['shorts']) {
177177
if (!$continuationTokenProvided) {
178-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id/shorts", true);
178+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id/shorts", forceLanguage: true, verifiesChannelRedirection: true);
179179
$visitorData = getVisitorData($result);
180180
$tab = getTabByName($result, 'Shorts');
181181
$tabRenderer = $tab['tabRenderer'];
@@ -230,7 +230,7 @@ function getItem($id, $order, $continuationToken)
230230

231231
if ($options['community']) {
232232
if (!$continuationTokenProvided) {
233-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id/community", true);
233+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id/community", forceLanguage: true, verifiesChannelRedirection: true);
234234
} else {
235235
$result = getContinuationJson($continuationToken);
236236
}
@@ -258,7 +258,7 @@ function getItem($id, $order, $continuationToken)
258258

259259
if ($options['channels']) {
260260
if (!$continuationTokenProvided) {
261-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id/channels", true);
261+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id/channels", forceLanguage: true, verifiesChannelRedirection: true);
262262

263263
$tab = getTabByName($result, 'Channels');
264264
$sectionListRenderer = $tab['tabRenderer']['content']['sectionListRenderer'];
@@ -323,7 +323,7 @@ function getItem($id, $order, $continuationToken)
323323
}
324324

325325
if ($options['about']) {
326-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id/about", true);
326+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id/about", forceLanguage: true, verifiesChannelRedirection: true);
327327

328328
$c4TabbedHeaderRenderer = $result['header']['c4TabbedHeaderRenderer'];
329329
$item['countryChannelId'] = $c4TabbedHeaderRenderer['channelId'];
@@ -366,7 +366,7 @@ function getItem($id, $order, $continuationToken)
366366
}
367367

368368
if ($options['approval']) {
369-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id", true);
369+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id", forceLanguage: true, verifiesChannelRedirection: true);
370370
$item['approval'] = end(explode(', ', $result['header']['pageHeaderRenderer']['content']['pageHeaderViewModel']['title']['dynamicTextViewModel']['rendererContext']['accessibilityContext']['label']));
371371
}
372372

@@ -385,7 +385,7 @@ function getItem($id, $order, $continuationToken)
385385

386386
if ($options['playlists']) {
387387
if (!$continuationTokenProvided) {
388-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id/playlists", true);
388+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id/playlists", forceLanguage: true, verifiesChannelRedirection: true);
389389

390390
$tab = getTabByName($result, 'Playlists');
391391
if ($tab === null) {
@@ -526,7 +526,7 @@ function getItem($id, $order, $continuationToken)
526526
if ($options['letsPlay'])
527527
{
528528
$letsPlay = [];
529-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id/letsplay");
529+
$result = getJSONFromHTML("https://www.youtube.com/channel/$id/letsplay", forceLanguage: true);
530530
$gridRendererItems = getTabByName($result, 'Let\'s play')['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['shelfRenderer']['content']['gridRenderer']['items'];
531531
foreach($gridRendererItems as $gridRendererItem)
532532
{
@@ -602,7 +602,7 @@ function getVideos(&$item, $url, $getGridRendererItems, $continuationToken)
602602
{
603603
$videos = [];
604604
if ($continuationToken === '') {
605-
$result = getJSONFromHTMLForcingLanguage($url);
605+
$result = getJSONFromHTML($url, forceLanguage: true);
606606
$gridRendererItems = $getGridRendererItems($result);
607607
$visitorData = getVisitorData($result);
608608
}

common.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ function getJSONStringFromHTML($html, $scriptVariable = '', $prefix = 'var ')
154154

155155
function getJSONFromHTML($url, $opts = [], $scriptVariable = '', $prefix = 'var ', $forceLanguage = false, $verifiesChannelRedirection = false)
156156
{
157+
if($forceLanguage) {
158+
$HEADER = 'Accept-Language: en';
159+
if(!doesPathExist($opts, 'http/header')) {
160+
$opts['http']['header'] = [$HEADER];
161+
} else {
162+
array_push($opts['http']['header'], $HEADER);
163+
}
164+
}
165+
157166
$html = getRemote($url, $opts);
158167
$jsonStr = getJSONStringFromHTML($html, $scriptVariable, $prefix);
159168
$json = json_decode($jsonStr, true);
@@ -171,16 +180,6 @@ function getJSONFromHTML($url, $opts = [], $scriptVariable = '', $prefix = 'var
171180
return $json;
172181
}
173182

174-
function getJSONFromHTMLForcingLanguage($url, $verifiesChannelRedirection = false)
175-
{
176-
$opts = [
177-
'http' => [
178-
'header' => ['Accept-Language: en']
179-
]
180-
];
181-
return getJSONFromHTML($url, $opts, verifiesChannelRedirection: $verifiesChannelRedirection);
182-
}
183-
184183
function checkRegex($regex, $str)
185184
{
186185
return preg_match("/^$regex$/", $str) === 1;

playlists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
function getItem($id)
4646
{
4747
global $options;
48-
$result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/playlist?list=$id");
48+
$result = getJSONFromHTML("https://www.youtube.com/playlist?list=$id", forceLanguage: true);
4949

5050
$item = [
5151
'kind' => 'youtube#playlist',

videos.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function getItem($id)
245245
}
246246

247247
if(isset($_GET['clipId'])) {
248-
$json = getJSONFromHTMLForcingLanguage("https://www.youtube.com/clip/$id");
248+
$json = getJSONFromHTML("https://www.youtube.com/clip/$id", forceLanguage: true);
249249
if ($options['id']) {
250250
$videoId = $json['currentVideoEndpoint']['watchEndpoint']['videoId'];
251251
$item['videoId'] = $videoId;
@@ -291,7 +291,7 @@ function getItem($id)
291291
}
292292

293293
if ($options['mostReplayed']) {
294-
$json = getJSONFromHTMLForcingLanguage("https://www.youtube.com/watch?v=$id");
294+
$json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", forceLanguage: true);
295295
$mutations = $json['frameworkUpdates']['entityBatchUpdate']['mutations'];
296296
$commonJsonPath = 'payload/macroMarkersListEntity/markersList';
297297
$jsonPath = "$commonJsonPath/markersDecoration";
@@ -400,7 +400,7 @@ function getItem($id)
400400
}
401401

402402
if ($options['snippet']) {
403-
$json = getJSONFromHTMLForcingLanguage("https://www.youtube.com/watch?v=$id");
403+
$json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", forceLanguage: true);
404404
$contents = $json['contents']['twoColumnWatchNextResults']['results']['results']['contents'];
405405
// Note that `publishedAt` has a day only precision.
406406
$publishedAt = strtotime($contents[0]['videoPrimaryInfoRenderer']['dateText']['simpleText']);
@@ -413,7 +413,7 @@ function getItem($id)
413413
}
414414

415415
if ($options['statistics']) {
416-
$json = getJSONFromHTMLForcingLanguage("https://www.youtube.com/watch?v=$id");
416+
$json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", forceLanguage: true);
417417
preg_match('/like this video along with ([\d,]+) other people/', $json['contents']['twoColumnWatchNextResults']['results']['results']['contents'][0]['videoPrimaryInfoRenderer']['videoActions']['menuRenderer']['topLevelButtons'][0]['segmentedLikeDislikeButtonViewModel']['likeButtonViewModel']['likeButtonViewModel']['toggleButtonViewModel']['toggleButtonViewModel']['defaultButtonViewModel']['buttonViewModel']['accessibilityText'], $viewCount);
418418
$statistics = [
419419
'viewCount' => getIntValue($json['playerOverlays']['playerOverlayRenderer']['videoDetails']['playerOverlayVideoDetailsRenderer']['subtitle']['runs'][2]['text'], 'view'),
@@ -423,7 +423,7 @@ function getItem($id)
423423
}
424424

425425
if ($options['activity']) {
426-
$json = getJSONFromHTMLForcingLanguage("https://www.youtube.com/watch?v=$id");
426+
$json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", forceLanguage: true);
427427
$activity = $json['contents']['twoColumnWatchNextResults']['results']['results']['contents'][1]['videoSecondaryInfoRenderer']['metadataRowContainer']['metadataRowContainerRenderer']['rows'][0]['richMetadataRowRenderer']['contents'][0]['richMetadataRenderer'];
428428
$name = $activity['title']['simpleText'];
429429
$year = $activity['subtitle']['simpleText'];

0 commit comments

Comments
 (0)