[YouTubeCommunityTab] Fix error occuring when YouTube returns non-English webpage. (#2739)

This commit is contained in:
Kingsley Yung 2022-05-17 15:35:16 +08:00 committed by GitHub
parent 1e3f5f3ad3
commit 7a87a09fc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,7 +30,7 @@ class YouTubeCommunityTabBridge extends BridgeAbstract {
private $itemTitle = ''; private $itemTitle = '';
private $urlRegex = '/youtube\.com\/(channel|user|c)\/([\w]+)\/community/'; private $urlRegex = '/youtube\.com\/(channel|user|c)\/([\w]+)\/community/';
private $jsonRegex = '/var ytInitialData = (.*);<\/script><link rel="canonical"/'; private $jsonRegex = '/var ytInitialData = (.*);<\/script>/';
public function detectParameters($url) { public function detectParameters($url) {
$params = array(); $params = array();
@ -153,7 +153,9 @@ class YouTubeCommunityTabBridge extends BridgeAbstract {
private function hasCommunityTab($json) { private function hasCommunityTab($json) {
foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) { foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) {
if (isset($tab->tabRenderer) && $tab->tabRenderer->title === 'Community') { if (isset($tab->tabRenderer)
&& str_ends_with($tab->tabRenderer->endpoint->commandMetadata->webCommandMetadata->url, 'community')) {
return true; return true;
} }
} }
@ -167,7 +169,9 @@ class YouTubeCommunityTabBridge extends BridgeAbstract {
private function getCommunityPosts($json) { private function getCommunityPosts($json) {
foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) { foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) {
if ($tab->tabRenderer->title === 'Community') { if (isset($tab->tabRenderer)
&& str_ends_with($tab->tabRenderer->endpoint->commandMetadata->webCommandMetadata->url, 'community')) {
return $tab->tabRenderer->content->sectionListRenderer->contents[0]->itemSectionRenderer->contents; return $tab->tabRenderer->content->sectionListRenderer->contents[0]->itemSectionRenderer->contents;
} }
} }