-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[YoutubeBridge] Playlist mode: faster feed generating if item count is less or equal to 15 #648
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -110,8 +110,12 @@ private function ytBridgeParseXmlFeed($xml) { | |||||||||||||||
$this->feedName = $this->ytBridgeFixTitle($xml->find('feed > title', 0)->plaintext); // feedName will be used by getName() | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
private function ytBridgeParseHtmlListing($html, $element_selector, $title_selector){ | ||||||||||||||||
$limit = 10; | ||||||||||||||||
private function ytCountItemsFromHtmlListing($html, $element_selector, $title_selector) { | ||||||||||||||||
return $this->ytBridgeParseHtmlListing($html, $element_selector, $title_selector, false); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
private function ytBridgeParseHtmlListing($html, $element_selector, $title_selector, $add_parsed_items = true) { | ||||||||||||||||
$limit = $add_parsed_items ? 10 : INF; | ||||||||||||||||
$count = 0; | ||||||||||||||||
foreach($html->find($element_selector) as $element) { | ||||||||||||||||
if($count < $limit) { | ||||||||||||||||
|
@@ -122,12 +126,15 @@ private function ytBridgeParseHtmlListing($html, $element_selector, $title_selec | |||||||||||||||
$vid = substr($vid, 0, strpos($vid, '&') ?: strlen($vid)); | ||||||||||||||||
$title = $this->ytBridgeFixTitle($element->find($title_selector, 0)->plaintext); | ||||||||||||||||
if($title != '[Private Video]' && strpos($vid, 'googleads') === false) { | ||||||||||||||||
$this->ytBridgeQueryVideoInfo($vid, $author, $desc, $time); | ||||||||||||||||
$this->ytBridgeAddItem($vid, $title, $author, $desc, $time); | ||||||||||||||||
if ($add_parsed_items) { | ||||||||||||||||
$this->ytBridgeQueryVideoInfo($vid, $author, $desc, $time); | ||||||||||||||||
$this->ytBridgeAddItem($vid, $title, $author, $desc, $time); | ||||||||||||||||
} | ||||||||||||||||
$count++; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
return $count; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
private function ytBridgeFixTitle($title) { | ||||||||||||||||
|
@@ -176,10 +183,16 @@ public function collectData(){ | |||||||||||||||
} | ||||||||||||||||
} elseif($this->getInput('p')) { /* playlist mode */ | ||||||||||||||||
$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); | ||||||||||||||||
$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'); | ||||||||||||||||
$item_count = $this->ytCountItemsFromHtmlListing($html, 'tr.pl-video', '.pl-video-title a'); | ||||||||||||||||
if ($item_count <= 15 && ($xml = $this->ytGetSimpleHTMLDOM($url_feed))) { | ||||||||||||||||
$this->ytBridgeParseXmlFeed($xml); | ||||||||||||||||
} else { | ||||||||||||||||
$this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a'); | ||||||||||||||||
} | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on how the user/channel mode is implemented, there are cases where the xml feed is not available. In those situations I suggest a fallback to HTML and if that doesn't work an error message. Please have a look at how this is implemented for the user/channel mode: rss-bridge/bridges/YoutubeBridge.php Lines 170 to 176 in 8ba8174
|
||||||||||||||||
$this->feedName = 'Playlist: ' . str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); // feedName will be used by getName() | ||||||||||||||||
usort($this->items, function ($item1, $item2) { | ||||||||||||||||
return $item2['timestamp'] - $item1['timestamp']; | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is a wrapper that adds a constant to another function call. Please keep it simple and directly call the inner function instead.