Skip to content

Commit a1bd410

Browse files
[YoutubeBridge] workaround for sorting by upload date no longer supported (#4893)
instead, filter by "today" (restrict the upload date to the last 24 hours) and combine it with special "after:yyyy-mm-dd" keyword to restrict the upload date to the last 6-30 hours
1 parent 4356dc6 commit a1bd410

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bridges/YoutubeBridge.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class YoutubeBridge extends BridgeAbstract
44
{
55
const NAME = 'YouTube';
66
const URI = 'https://www.youtube.com';
7-
const CACHE_TIMEOUT = 60 * 60 * 3;
7+
const CACHE_TIMEOUT = 60 * 60 * 3; // 3 hours
88
const DESCRIPTION = 'Returns the 10 newest videos by username/channel/playlist or search';
99

1010
const PARAMETERS = [
@@ -183,8 +183,14 @@ private function collectDataInternal()
183183
});
184184
} elseif ($search) {
185185
// search
186-
$url_listing = self::URI . '/results?search_query=' . urlencode($search) . '&sp=CAI%253D';
187-
$html = $this->fetch($url_listing);
186+
$today_filter = 'EgIIAg'; // restrict the upload date to the last 24 hours
187+
$url_listing = self::URI . '/results?sp=' . $today_filter . '&search_query=' . urlencode($search);
188+
if (!preg_match("/\b(before|after):/i", $search)) {
189+
// unless explicitly overridden, a special "after:yyyy-mm-dd" keyword is appended to restrict the upload date to the last 6-30 hours
190+
$html = $this->fetch($url_listing . urlencode(' after:' . date('Y-m-d', strtotime('-6 hours'))));
191+
} else {
192+
$html = $this->fetch($url_listing);
193+
}
188194
$jsonData = $this->extractJsonFromHtml($html);
189195
$jsonData = $jsonData->contents->twoColumnSearchResultsRenderer->primaryContents;
190196
$jsonData = $jsonData->sectionListRenderer->contents[0]->itemSectionRenderer->contents;

0 commit comments

Comments
 (0)