fix(duckduckgo): order by date (#3689)

This commit is contained in:
Dag 2023-09-23 17:50:41 +02:00 committed by GitHub
parent 07f49225d9
commit cb6c931b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 37 deletions

View File

@ -14,29 +14,10 @@ class AwwwardsBridge extends BridgeAbstract
private $sites = [];
public function getIcon()
{
return 'https://www.awwwards.com/favicon.ico';
}
private function fetchSites()
{
Debug::log('Fetching all sites');
$sites = getSimpleHTMLDOM(self::SITESURI);
Debug::log('Parsing all JSON data');
foreach ($sites->find('.grid-sites li') as $site) {
$decode = html_entity_decode($site->attr['data-collectable-model-value'], ENT_QUOTES, 'utf-8');
$decode = json_decode($decode, true);
$this->sites[] = $decode;
}
}
public function collectData()
{
$this->fetchSites();
Debug::log('Building RSS feed');
foreach ($this->sites as $site) {
$item = [];
$item['title'] = $site['title'];
@ -56,4 +37,23 @@ class AwwwardsBridge extends BridgeAbstract
}
}
}
public function getIcon()
{
return 'https://www.awwwards.com/favicon.ico';
}
private function fetchSites()
{
$sites = getSimpleHTMLDOM(self::SITESURI);
foreach ($sites->find('.grid-sites li') as $li) {
$encodedJson = $li->attr['data-collectable-model-value'] ?? null;
if (!$encodedJson) {
continue;
}
$json = html_entity_decode($encodedJson, ENT_QUOTES, 'utf-8');
$site = Json::decode($json);
$this->sites[] = $site;
}
}
}

View File

@ -8,7 +8,7 @@ class DuckDuckGoBridge extends BridgeAbstract
const CACHE_TIMEOUT = 21600; // 6h
const DESCRIPTION = 'Returns results from DuckDuckGo.';
const SORT_DATE = '+sort:date';
const SORT_DATE = ' sort:date';
const SORT_RELEVANCE = '';
const PARAMETERS = [ [
@ -31,13 +31,22 @@ class DuckDuckGoBridge extends BridgeAbstract
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI . 'html/?kd=-1&q=' . $this->getInput('u') . $this->getInput('sort'));
$query = [
'kd' => '-1',
'q' => $this->getInput('u') . $this->getInput('sort'),
];
$url = 'https://duckduckgo.com/html/?' . http_build_query($query);
$html = getSimpleHTMLDOM($url);
foreach ($html->find('div.result') as $element) {
$item = [];
$item['uri'] = $element->find('a.result__a', 0)->href;
$item['title'] = $element->find('h2.result__title', 0)->plaintext;
$item['content'] = $element->find('a.result__snippet', 0)->plaintext;
$snippet = $element->find('a.result__snippet', 0);
if ($snippet) {
$item['content'] = $snippet->plaintext;
}
$this->items[] = $item;
}
}

View File

@ -10,14 +10,19 @@ class EngadgetBridge extends FeedExpander
public function collectData()
{
$this->collectExpandableDatas(static::URI . 'rss.xml', 15);
$max = 10;
$this->collectExpandableDatas(static::URI . 'rss.xml', $max);
}
protected function parseItem($newsItem)
{
$item = parent::parseItem($newsItem);
// $articlePage gets the entire page's contents
$articlePage = getSimpleHTMLDOM($newsItem->link);
$url = (string) $newsItem->link;
if (!$url) {
return $item;
}
// todo: remove querystring tracking
$articlePage = getSimpleHTMLDOM($url);
// figure contain's the main article image
$article = $articlePage->find('figure', 0);
// .article-text has the actual article

View File

@ -170,22 +170,21 @@ class JustWatchBridge extends BridgeAbstract
$item = [];
$item['uri'] = $title->find('a', 0)->href;
$posterImage = $title->find('.title-poster__image > img', 0);
$itemTitle = sprintf(
'%s - %s',
$provider->find('picture > img', 0)->alt ?? '',
$title->find('.title-poster__image > img', 0)->alt ?? ''
$posterImage->alt ?? ''
);
$item['title'] = $itemTitle;
$imageUrl = $title->find('.title-poster__image > img', 0)->attr['src'] ?? '';
$imageUrl = $posterImage->attr['src'] ?? '';
if (str_starts_with($imageUrl, 'data')) {
$imageUrl = $title->find('.title-poster__image > img', 0)->attr['data-src'];
$imageUrl = $posterImage->attr['data-src'];
}
$content = '<b>Provider:</b> '
. $provider->find('picture > img', 0)->alt . '<br>';
$content .= '<b>Media:</b> '
. $title->find('.title-poster__image > img', 0)->alt . '<br>';
$content = '<b>Provider:</b> ' . $provider->find('picture > img', 0)->alt . '<br>';
$content .= '<b>Media:</b> ' . ($posterImage->alt ?? '') . '<br>';
if (isset($title->find('.title-poster__badge', 0)->plaintext)) {
$content .= '<b>Type:</b> Series<br>';

View File

@ -45,10 +45,12 @@ class YandexZenBridge extends BridgeAbstract
$item['timestamp'] = date(DateTimeInterface::ATOM, $publicationDateUnixTimestamp);
}
$item['content'] = $post->text . "<br /><img src='$post->image' />";
$item['enclosures'] = [
$post->image,
];
$postImage = $post->image ?? null;
$item['content'] = $post->text;
if ($postImage) {
$item['content'] .= "<br /><img src='$postImage' />";
$item['enclosures'] = [$postImage];
}
$this->items[] = $item;
}

View File

@ -228,7 +228,10 @@ class YoutubeBridge extends BridgeAbstract
return;
}
$jsonData = $jsonData->contents->twoColumnWatchNextResults->results->results->contents;
$jsonData = $jsonData->contents->twoColumnWatchNextResults->results->results->contents ?? null;
if (!$jsonData) {
throw new \Exception('Unable to find json data');
}
$videoSecondaryInfo = null;
foreach ($jsonData as $item) {
if (isset($item->videoSecondaryInfoRenderer)) {