From c5fe9a6dc07e1377a261b4b35ef0f77b38f8cf01 Mon Sep 17 00:00:00 2001 From: Matt DeMoss Date: Thu, 28 Dec 2017 19:52:46 -0500 Subject: [PATCH 1/3] mark places where a new variable is needed --- bridges/YoutubeBridge.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 1db0735..4d76851 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -91,7 +91,7 @@ class YoutubeBridge extends BridgeAbstract { if(strpos($vid, 'googleads') === false) $this->ytBridgeAddItem($vid, $title, $author, $desc, $time); } - $this->request = $this->ytBridgeFixTitle($xml->find('feed > title', 0)->plaintext); + $this->request = $this->ytBridgeFixTitle($xml->find('feed > title', 0)->plaintext); // TODO: use another variable for feed title. } private function ytBridgeParseHtmlListing($html, $element_selector, $title_selector){ @@ -164,7 +164,7 @@ class YoutubeBridge extends BridgeAbstract { $html = $this->ytGetSimpleHTMLDOM($url_listing) or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); $this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a'); - $this->request = 'Playlist: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); + $this->request = 'Playlist: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // TODO: use another variable for feed title. } elseif($this->getInput('s')) { /* search mode */ $this->request = $this->getInput('s'); $page = 1; @@ -182,7 +182,7 @@ class YoutubeBridge extends BridgeAbstract { or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); $this->ytBridgeParseHtmlListing($html, 'div.yt-lockup', 'h3'); - $this->request = 'Search: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); + $this->request = 'Search: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // TODO: use another variable for feed title. } else { /* no valid mode */ returnClientError("You must either specify either:\n - YouTube username (?u=...)\n - Channel id (?c=...)\n - Playlist id (?p=...)\n - Search (?s=...)"); From 08713769225cfad9e7eed89ebaba174b6a308a1c Mon Sep 17 00:00:00 2001 From: Matt DeMoss Date: Thu, 28 Dec 2017 20:14:11 -0500 Subject: [PATCH 2/3] store feed name in new variable, switch getName on queriedContext, remove 'bridge' from name for feeds, fixes #609 --- bridges/YoutubeBridge.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 4d76851..69b7e23 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -91,7 +91,7 @@ class YoutubeBridge extends BridgeAbstract { if(strpos($vid, 'googleads') === false) $this->ytBridgeAddItem($vid, $title, $author, $desc, $time); } - $this->request = $this->ytBridgeFixTitle($xml->find('feed > title', 0)->plaintext); // TODO: use another variable for feed title. + $this->feedName = $this->ytBridgeFixTitle($xml->find('feed > title', 0)->plaintext); // feedName will be used by getName() } private function ytBridgeParseHtmlListing($html, $element_selector, $title_selector){ @@ -164,7 +164,7 @@ class YoutubeBridge extends BridgeAbstract { $html = $this->ytGetSimpleHTMLDOM($url_listing) or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); $this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a'); - $this->request = 'Playlist: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // TODO: use another variable for feed title. + $this->feedName = 'Playlist: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // feedName will be used by getName() } elseif($this->getInput('s')) { /* search mode */ $this->request = $this->getInput('s'); $page = 1; @@ -182,7 +182,7 @@ class YoutubeBridge extends BridgeAbstract { or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); $this->ytBridgeParseHtmlListing($html, 'div.yt-lockup', 'h3'); - $this->request = 'Search: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // TODO: use another variable for feed title. + $this->feedName = 'Search: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // feedName will be used by getName() } else { /* no valid mode */ returnClientError("You must either specify either:\n - YouTube username (?u=...)\n - Channel id (?c=...)\n - Playlist id (?p=...)\n - Search (?s=...)"); @@ -190,6 +190,15 @@ class YoutubeBridge extends BridgeAbstract { } public function getName(){ - return (!empty($this->request) ? $this->request . ' - ' : '') . 'YouTube Bridge'; - } + // Name depends on queriedContext: + switch($this->queriedContext) { + case 'By username': + case 'By channel id': + case 'By playlist Id': + case 'Search result': + return $this->feedName . ' - ' . 'YouTube'; // We already know it's a bridge, right? + default: + return parent::getName(); + } + } } From c14b2c6905a392e0663070413c0e45db0ecdb7ff Mon Sep 17 00:00:00 2001 From: Matt DeMoss Date: Thu, 28 Dec 2017 20:19:35 -0500 Subject: [PATCH 3/3] address phpcs style errors --- bridges/YoutubeBridge.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 69b7e23..3d81dae 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -196,9 +196,9 @@ class YoutubeBridge extends BridgeAbstract { case 'By channel id': case 'By playlist Id': case 'Search result': - return $this->feedName . ' - ' . 'YouTube'; // We already know it's a bridge, right? - default: - return parent::getName(); + return $this->feedName . ' - YouTube'; // We already know it's a bridge, right? + default: + return parent::getName(); } } }