forked from blallo/rss-bridge
[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
This commit is contained in:
parent
890ba69116
commit
120e74c1b4
1 changed files with 27 additions and 5 deletions
|
@ -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',
|
||||
'<a href="$1" target="_blank">$1</a> ',
|
||||
$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');
|
||||
|
|
Loading…
Reference in a new issue