1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-08 09:36:39 +02:00

[YoutubeCommunityTabsBridge] Rename Community→Posts to fix broken bridge (#4606)

* youtube community posts are just called "Posts" now

* finish renaming Community -> Posts

* add feedName fallbacks (thanks @Mar-Koeh)

* rename YouTubePostsTabBridge back to YouTubeCommunityTabBridge

* fix linter error by breaking up long expression

* fix optional-chaining regression by using ‘?? null’
This commit is contained in:
shaun
2025-08-04 07:30:48 -05:00
committed by GitHub
parent 1211ac63d9
commit aba38845d2
2 changed files with 25 additions and 21 deletions

View File

@@ -46,7 +46,7 @@ Requires minimum PHP 7.4.
* `TwitchBridge`: [Fetches videos from channel](https://rss-bridge.org/bridge01/#bridge-TwitchBridge) * `TwitchBridge`: [Fetches videos from channel](https://rss-bridge.org/bridge01/#bridge-TwitchBridge)
* `XPathBridge`: [Scrape out a feed using XPath expressions](https://rss-bridge.org/bridge01/#bridge-XPathBridge) * `XPathBridge`: [Scrape out a feed using XPath expressions](https://rss-bridge.org/bridge01/#bridge-XPathBridge)
* `YoutubeBridge`: [Fetches videos by username/channel/playlist/search](https://rss-bridge.org/bridge01/#bridge-YoutubeBridge) * `YoutubeBridge`: [Fetches videos by username/channel/playlist/search](https://rss-bridge.org/bridge01/#bridge-YoutubeBridge)
* `YouTubeCommunityTabBridge`: [Fetches posts from a channel's community tab](https://rss-bridge.org/bridge01/#bridge-YouTubeCommunityTabBridge) * `YouTubeCommunityTabBridge`: [Fetches posts from a channel's Posts tab](https://rss-bridge.org/bridge01/#bridge-YouTubeCommunityTabBridge)
## Tutorial ## Tutorial

View File

@@ -2,9 +2,9 @@
class YouTubeCommunityTabBridge extends BridgeAbstract class YouTubeCommunityTabBridge extends BridgeAbstract
{ {
const NAME = 'YouTube Community Tab Bridge'; const NAME = 'YouTube Posts Tab Bridge';
const URI = 'https://www.youtube.com'; const URI = 'https://www.youtube.com';
const DESCRIPTION = 'Returns posts from a channel\'s community tab'; const DESCRIPTION = 'Returns posts from a channel\'s posts tab';
const MAINTAINER = 'VerifiedJoseph'; const MAINTAINER = 'VerifiedJoseph';
const PARAMETERS = [ const PARAMETERS = [
'By channel ID' => [ 'By channel ID' => [
@@ -31,7 +31,7 @@ class YouTubeCommunityTabBridge extends BridgeAbstract
private $feedName = ''; private $feedName = '';
private $itemTitle = ''; private $itemTitle = '';
private $urlRegex = '/youtube\.com\/(channel|user|c)\/([\w]+)\/community/'; private $urlRegex = '/youtube\.com\/(channel|user|c)\/([\w]+)\/posts/';
private $jsonRegex = '/var ytInitialData = ([^<]*);<\/script>/'; private $jsonRegex = '/var ytInitialData = ([^<]*);<\/script>/';
public function detectParameters($url) public function detectParameters($url)
@@ -59,26 +59,30 @@ class YouTubeCommunityTabBridge extends BridgeAbstract
{ {
if (is_null($this->getInput('username')) === false) { if (is_null($this->getInput('username')) === false) {
try { try {
$this->feedUrl = $this->buildCommunityUri($this->getInput('username'), 'c'); $this->feedUrl = $this->buildPostsUri($this->getInput('username'), 'c');
$html = getSimpleHTMLDOM($this->feedUrl); $html = getSimpleHTMLDOM($this->feedUrl);
} catch (Exception $e) { } catch (Exception $e) {
$this->feedUrl = $this->buildCommunityUri($this->getInput('username'), 'user'); $this->feedUrl = $this->buildPostsUri($this->getInput('username'), 'user');
$html = getSimpleHTMLDOM($this->feedUrl); $html = getSimpleHTMLDOM($this->feedUrl);
} }
} else { } else {
$this->feedUrl = $this->buildCommunityUri($this->getInput('channel'), 'channel'); $this->feedUrl = $this->buildPostsUri($this->getInput('channel'), 'channel');
$html = getSimpleHTMLDOM($this->feedUrl); $html = getSimpleHTMLDOM($this->feedUrl);
} }
$json = $this->extractJson($html->find('html', 0)->innertext); $json = $this->extractJson($html->find('html', 0)->innertext);
$this->feedName = $json->header->c4TabbedHeaderRenderer->title; $this->feedName = $json->header->c4TabbedHeaderRenderer->title ?? null;
$this->feedName ??= $json->header->pageHeaderRenderer->pageTitle ?? null;
$this->feedName ??= $json->metadata->channelMetadataRenderer->title ?? null;
$this->feedName ??= $json->microformat->microformatDataRenderer->title ?? null;
$this->feedName ??= '';
if ($this->hasCommunityTab($json) === false) { if ($this->hasPostsTab($json) === false) {
returnServerError('Channel does not have a community tab'); returnServerError('Channel does not have a posts tab');
} }
$posts = $this->getCommunityPosts($json); $posts = $this->getPosts($json);
foreach ($posts as $key => $post) { foreach ($posts as $key => $post) {
$this->itemTitle = ''; $this->itemTitle = '';
@@ -132,18 +136,18 @@ class YouTubeCommunityTabBridge extends BridgeAbstract
public function getName() public function getName()
{ {
if (!empty($this->feedName)) { if (!empty($this->feedName)) {
return $this->feedName . ' - YouTube Community Tab'; return $this->feedName . ' - YouTube Posts Tab';
} }
return parent::getName(); return parent::getName();
} }
/** /**
* Build Community URI * Build Posts URI
*/ */
private function buildCommunityUri($value, $type) private function buildPostsUri($value, $type)
{ {
return self::URI . '/' . $type . '/' . $value . '/community'; return self::URI . '/' . $type . '/' . $value . '/posts';
} }
/** /**
@@ -165,14 +169,14 @@ class YouTubeCommunityTabBridge extends BridgeAbstract
} }
/** /**
* Check if channel has a community tab * Check if channel has a posts tab
*/ */
private function hasCommunityTab($json) private function hasPostsTab($json)
{ {
foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) { foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) {
if ( if (
isset($tab->tabRenderer) isset($tab->tabRenderer)
&& str_ends_with($tab->tabRenderer->endpoint->commandMetadata->webCommandMetadata->url, 'community') && str_ends_with($tab->tabRenderer->endpoint->commandMetadata->webCommandMetadata->url, 'posts')
) { ) {
return true; return true;
} }
@@ -182,14 +186,14 @@ class YouTubeCommunityTabBridge extends BridgeAbstract
} }
/** /**
* Get community tab posts * Get posts from posts tab
*/ */
private function getCommunityPosts($json) private function getPosts($json)
{ {
foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) { foreach ($json->contents->twoColumnBrowseResultsRenderer->tabs as $tab) {
if ( if (
isset($tab->tabRenderer) isset($tab->tabRenderer)
&& str_ends_with($tab->tabRenderer->endpoint->commandMetadata->webCommandMetadata->url, 'community') && str_ends_with($tab->tabRenderer->endpoint->commandMetadata->webCommandMetadata->url, 'posts')
) { ) {
return $tab->tabRenderer->content->sectionListRenderer->contents[0]->itemSectionRenderer->contents; return $tab->tabRenderer->content->sectionListRenderer->contents[0]->itemSectionRenderer->contents;
} }