Skip to content

Commit

Permalink
Restore YouTube UI channel tabs order
Browse files Browse the repository at this point in the history
By swapping `community` and `about`.
  • Loading branch information
Benjamin-Loison committed Oct 26, 2022
1 parent 899316c commit 6ea736d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 49 deletions.
96 changes: 48 additions & 48 deletions channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

include_once 'common.php';

$realOptions = ['snippet', 'premieres', 'about', 'community'];
$realOptions = ['snippet', 'premieres', 'community', 'about'];

// really necessary ?
foreach ($realOptions as $realOption) {
Expand Down Expand Up @@ -77,53 +77,6 @@ function getItem($id, $continuationToken)
$item['premieres'] = $premieres;
}

if ($options['about']) {
$http = [
'header' => ['Accept-Language: en']
];

$options = [
'http' => $http
];

$result = getJSONFromHTML('https://www.youtube.com/channel/' . $id . '/about', $options);

$resultCommon = array_slice($result['contents']['twoColumnBrowseResultsRenderer']['tabs'], -2)[0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['channelAboutFullMetadataRenderer'];

$stats = [];

$stats['joinedDate'] = strtotime($resultCommon['joinedDateText']['runs'][1]['text']);

$viewCount = $resultCommon['viewCountText']['simpleText'];
// Could try to find a YouTube channel with a single view to make sure it displays "view" and not "views".
$viewCount = str_replace(' view', '', str_replace(' views', '', str_replace(',', '', $viewCount)));
$stats['viewCount'] = $viewCount;

$about['stats'] = $stats;

$description = $resultCommon['description']['simpleText'];
$about['description'] = $description;

$details = [];
$details['location'] = $resultCommon['country']['simpleText'];
$about['details'] = $details;

$linksObjects = $resultCommon['primaryLinks'];
$links = [];
foreach ($linksObjects as $linkObject) {
$link = [];
$urlComponents = parse_url($linkObject['navigationEndpoint']['urlEndpoint']['url']);
parse_str($urlComponents['query'], $params);
$link['url'] = $params['q'];
$link['thumbnail'] = $linkObject['icon']['thumbnails'][0]['url'];
$link['title'] = $linkObject['title']['simpleText'];
array_push($links, $link);
}
$about['links'] = $links;

$item['about'] = $about;
}

if ($options['community']) {
if (!$continuationTokenProvided) {
$http = [
Expand Down Expand Up @@ -230,6 +183,53 @@ function getItem($id, $continuationToken)
$item['nextPageToken'] = str_replace('%3D', '=', $contents[10]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token']);
}

if ($options['about']) {
$http = [
'header' => ['Accept-Language: en']
];

$options = [
'http' => $http
];

$result = getJSONFromHTML('https://www.youtube.com/channel/' . $id . '/about', $options);

$resultCommon = array_slice($result['contents']['twoColumnBrowseResultsRenderer']['tabs'], -2)[0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['channelAboutFullMetadataRenderer'];

$stats = [];

$stats['joinedDate'] = strtotime($resultCommon['joinedDateText']['runs'][1]['text']);

$viewCount = $resultCommon['viewCountText']['simpleText'];
// Could try to find a YouTube channel with a single view to make sure it displays "view" and not "views".
$viewCount = str_replace(' view', '', str_replace(' views', '', str_replace(',', '', $viewCount)));
$stats['viewCount'] = $viewCount;

$about['stats'] = $stats;

$description = $resultCommon['description']['simpleText'];
$about['description'] = $description;

$details = [];
$details['location'] = $resultCommon['country']['simpleText'];
$about['details'] = $details;

$linksObjects = $resultCommon['primaryLinks'];
$links = [];
foreach ($linksObjects as $linkObject) {
$link = [];
$urlComponents = parse_url($linkObject['navigationEndpoint']['urlEndpoint']['url']);
parse_str($urlComponents['query'], $params);
$link['url'] = $params['q'];
$link['thumbnail'] = $linkObject['icon']['thumbnails'][0]['url'];
$link['title'] = $linkObject['title']['simpleText'];
array_push($links, $link);
}
$about['links'] = $links;

$item['about'] = $about;
}

return $item;
}

Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function feature($feature)
}

// don't know if already written but making a table may be nice
$features = [['channels/list', 'snippet,premieres,about,community&forUsername=USERNAME&id=CHANNEL_ID'], // could use ',' instead of '&' to describe that `forUsername` and `id` have the same aim
$features = [['channels/list', 'snippet,premieres,community,about&forUsername=USERNAME&id=CHANNEL_ID'], // could use ',' instead of '&' to describe that `forUsername` and `id` have the same aim
def
['commentThreads/list', 'snippet,replies&videoId=VIDEO_ID(&pageToken=PAGE_TOKEN)'],
['playlists/list', 'statistics&id=PLAYLIST_ID'],
['playlistItems/list', 'snippet&playlistId=PLAYLIST_ID(&pageToken=PAGE_TOKEN)'],
Expand Down

0 comments on commit 6ea736d

Please sign in to comment.