From 120e74c1b403f34995c1c6e6fe1436bf4bcbc508 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Thu, 27 Apr 2017 21:40:20 +0200 Subject: [PATCH] [YoutubeBridge] Improve readability of feed contents Previously feed contents were rendered as one block of text with no structure. This brings back the structure of original video descriptions and makes links in the description work again. References #520 --- bridges/YoutubeBridge.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 1155a13..786530b 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -49,7 +49,7 @@ class YoutubeBridge extends BridgeAbstract { ); private function ytBridgeQueryVideoInfo($vid, &$author, &$desc, &$time){ - $html = getSimpleHTMLDOM(self::URI . "watch?v=$vid"); + $html = $this->ytGetSimpleHTMLDOM(self::URI . "watch?v=$vid"); $author = $html->innertext; $author = substr($author, strpos($author, '"author=') + 8); $author = substr($author, 0, strpos($author, '\u0026')); @@ -74,6 +74,14 @@ class YoutubeBridge extends BridgeAbstract { $title = $this->ytBridgeFixTitle($element->find('title', 0)->plaintext); $author = $element->find('name', 0)->plaintext; $desc = $element->find('media:description', 0)->innertext; + + // Make sure the description is easy on the eye :) + $desc = htmlspecialchars($desc); + $desc = nl2br($desc); + $desc = preg_replace('/(http[s]{0,1}\:\/\/[a-zA-Z0-9.\/]{4,})/ims', + '$1 ', + $desc); + $vid = str_replace('yt:video:', '', $element->find('id', 0)->plaintext); $time = strtotime($element->find('published', 0)->plaintext); $this->ytBridgeAddItem($vid, $title, $author, $desc, $time); @@ -105,6 +113,20 @@ class YoutubeBridge extends BridgeAbstract { return html_entity_decode($title, ENT_QUOTES, 'UTF-8'); } + private function ytGetSimpleHTMLDOM($url){ + return getSimpleHTMLDOM($url, + $use_include_path = false, + $context = null, + $offset = 0, + $maxLen = null, + $lowercase = true, + $forceTagsClosed = true, + $target_charset = DEFAULT_TARGET_CHARSET, + $stripRN = false, + $defaultBRText = DEFAULT_BR_TEXT, + $defaultSpanText = DEFAULT_SPAN_TEXT); + } + public function collectData(){ $xml = ''; @@ -123,9 +145,9 @@ class YoutubeBridge extends BridgeAbstract { } if(!empty($url_feed) && !empty($url_listing)){ - if($xml = getSimpleHTMLDOM($url_feed)){ + if($xml = $this->ytGetSimpleHTMLDOM($url_feed)){ $this->ytBridgeParseXmlFeed($xml); - } elseif($html = getSimpleHTMLDOM($url_listing)){ + } elseif($html = $this->ytGetSimpleHTMLDOM($url_listing)){ $this->ytBridgeParseHtmlListing($html, 'li.channels-content-item', 'h3'); } else { returnServerError("Could not request YouTube. Tried:\n - $url_feed\n - $url_listing"); @@ -133,7 +155,7 @@ class YoutubeBridge extends BridgeAbstract { } elseif($this->getInput('p')){ /* playlist mode */ $this->request = $this->getInput('p'); $url_listing = self::URI . 'playlist?list=' . urlencode($this->request); - $html = getSimpleHTMLDOM($url_listing) + $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); @@ -150,7 +172,7 @@ class YoutubeBridge extends BridgeAbstract { . $page . '&filters=video&search_sort=video_date_uploaded'; - $html = getSimpleHTMLDOM($url_listing) + $html = $this->ytGetSimpleHTMLDOM($url_listing) or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); $this->ytBridgeParseHtmlListing($html, 'div.yt-lockup', 'h3');