[YoutubeBridge] Add playlist caching (#1162)
This commit is contained in:
parent
e4e04a7865
commit
f76a23f0a5
1 changed files with 63 additions and 46 deletions
|
@ -65,7 +65,7 @@ class YoutubeBridge extends BridgeAbstract {
|
|||
private $feedName = '';
|
||||
|
||||
private function ytBridgeQueryVideoInfo($vid, &$author, &$desc, &$time){
|
||||
$html = $this->ytGetSimpleHTMLDOM(self::URI . "watch?v=$vid");
|
||||
$html = $this->ytGetSimpleHTMLDOM(self::URI . "watch?v=$vid", true);
|
||||
|
||||
// Skip unavailable videos
|
||||
if(!strpos($html->innertext, 'IS_UNAVAILABLE_PAGE')) {
|
||||
|
@ -127,7 +127,6 @@ class YoutubeBridge extends BridgeAbstract {
|
|||
}
|
||||
|
||||
private function ytBridgeParseHtmlListing($html, $element_selector, $title_selector, $add_parsed_items = true) {
|
||||
$limit = $add_parsed_items ? 10 : INF;
|
||||
$count = 0;
|
||||
|
||||
$duration_min = $this->getInput('duration_min') ?: -1;
|
||||
|
@ -141,7 +140,6 @@ class YoutubeBridge extends BridgeAbstract {
|
|||
}
|
||||
|
||||
foreach($html->find($element_selector) as $element) {
|
||||
if($count < $limit) {
|
||||
$author = '';
|
||||
$desc = '';
|
||||
$time = 0;
|
||||
|
@ -175,7 +173,6 @@ class YoutubeBridge extends BridgeAbstract {
|
|||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
@ -184,18 +181,38 @@ class YoutubeBridge extends BridgeAbstract {
|
|||
return html_entity_decode($title, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
private function ytGetSimpleHTMLDOM($url){
|
||||
return getSimpleHTMLDOM($url,
|
||||
private function ytGetSimpleHTMLDOM($url, $cached = false){
|
||||
$header = array(
|
||||
'Accept-Language: en-US'
|
||||
),
|
||||
$opts = array(),
|
||||
$lowercase = true,
|
||||
$forceTagsClosed = true,
|
||||
$target_charset = DEFAULT_TARGET_CHARSET,
|
||||
$stripRN = false,
|
||||
$defaultBRText = DEFAULT_BR_TEXT,
|
||||
$defaultSpanText = DEFAULT_SPAN_TEXT);
|
||||
);
|
||||
$opts = array();
|
||||
$lowercase = true;
|
||||
$forceTagsClosed = true;
|
||||
$target_charset = DEFAULT_TARGET_CHARSET;
|
||||
$stripRN = false;
|
||||
$defaultBRText = DEFAULT_BR_TEXT;
|
||||
$defaultSpanText = DEFAULT_SPAN_TEXT;
|
||||
if ($cached) {
|
||||
return getSimpleHTMLDOMCached($url,
|
||||
86400,
|
||||
$header,
|
||||
$opts,
|
||||
$lowercase,
|
||||
$forceTagsClosed,
|
||||
$target_charset,
|
||||
$stripRN,
|
||||
$defaultBRText,
|
||||
$defaultSpanText);
|
||||
}
|
||||
return getSimpleHTMLDOM($url,
|
||||
$header,
|
||||
$opts,
|
||||
$lowercase,
|
||||
$forceTagsClosed,
|
||||
$target_charset,
|
||||
$stripRN,
|
||||
$defaultBRText,
|
||||
$defaultSpanText);
|
||||
}
|
||||
|
||||
public function collectData(){
|
||||
|
@ -229,7 +246,7 @@ class YoutubeBridge extends BridgeAbstract {
|
|||
$url_listing = self::URI . 'playlist?list=' . urlencode($this->request);
|
||||
$html = $this->ytGetSimpleHTMLDOM($url_listing)
|
||||
or returnServerError("Could not request YouTube. Tried:\n - $url_listing");
|
||||
$item_count = $this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a', true);
|
||||
$item_count = $this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a', false);
|
||||
if ($item_count <= 15 && !$this->skipFeeds() && ($xml = $this->ytGetSimpleHTMLDOM($url_feed))) {
|
||||
$this->ytBridgeParseXmlFeed($xml);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue