1
0
Fork 0
forked from blallo/rss-bridge

[YoutubeBridge] Playlist mode: faster feed generating if item count is less or equal to 15 (#648)

* [YoutubeBridge] Playlist mode: faster feed generating if item count is less or equal to 15
This commit is contained in:
Eugene Molotov 2018-03-19 17:41:53 +05:00 committed by Teromene
parent 38c7e0272e
commit 41b7984a4e

View file

@ -110,8 +110,8 @@ class YoutubeBridge extends BridgeAbstract {
$this->feedName = $this->ytBridgeFixTitle($xml->find('feed > title', 0)->plaintext); // feedName will be used by getName() $this->feedName = $this->ytBridgeFixTitle($xml->find('feed > title', 0)->plaintext); // feedName will be used by getName()
} }
private function ytBridgeParseHtmlListing($html, $element_selector, $title_selector){ private function ytBridgeParseHtmlListing($html, $element_selector, $title_selector, $add_parsed_items = true) {
$limit = 10; $limit = $add_parsed_items ? 10 : INF;
$count = 0; $count = 0;
foreach($html->find($element_selector) as $element) { foreach($html->find($element_selector) as $element) {
if($count < $limit) { if($count < $limit) {
@ -122,12 +122,15 @@ class YoutubeBridge extends BridgeAbstract {
$vid = substr($vid, 0, strpos($vid, '&') ?: strlen($vid)); $vid = substr($vid, 0, strpos($vid, '&') ?: strlen($vid));
$title = $this->ytBridgeFixTitle($element->find($title_selector, 0)->plaintext); $title = $this->ytBridgeFixTitle($element->find($title_selector, 0)->plaintext);
if($title != '[Private Video]' && strpos($vid, 'googleads') === false) { if($title != '[Private Video]' && strpos($vid, 'googleads') === false) {
if ($add_parsed_items) {
$this->ytBridgeQueryVideoInfo($vid, $author, $desc, $time); $this->ytBridgeQueryVideoInfo($vid, $author, $desc, $time);
$this->ytBridgeAddItem($vid, $title, $author, $desc, $time); $this->ytBridgeAddItem($vid, $title, $author, $desc, $time);
}
$count++; $count++;
} }
} }
} }
return $count;
} }
private function ytBridgeFixTitle($title) { private function ytBridgeFixTitle($title) {
@ -176,10 +179,16 @@ class YoutubeBridge extends BridgeAbstract {
} }
} elseif($this->getInput('p')) { /* playlist mode */ } elseif($this->getInput('p')) { /* playlist mode */
$this->request = $this->getInput('p'); $this->request = $this->getInput('p');
$url_feed = self::URI . 'feeds/videos.xml?playlist_id=' . urlencode($this->request);
$url_listing = self::URI . 'playlist?list=' . urlencode($this->request); $url_listing = self::URI . 'playlist?list=' . urlencode($this->request);
$html = $this->ytGetSimpleHTMLDOM($url_listing) $html = $this->ytGetSimpleHTMLDOM($url_listing)
or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); or returnServerError("Could not request YouTube. Tried:\n - $url_listing");
$item_count = $this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a', false);
if ($item_count <= 15 && ($xml = $this->ytGetSimpleHTMLDOM($url_feed))) {
$this->ytBridgeParseXmlFeed($xml);
} else {
$this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a'); $this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a');
}
$this->feedName = 'Playlist: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // feedName will be used by getName() $this->feedName = 'Playlist: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // feedName will be used by getName()
usort($this->items, function ($item1, $item2) { usort($this->items, function ($item1, $item2) {
return $item2['timestamp'] - $item1['timestamp']; return $item2['timestamp'] - $item1['timestamp'];