From b64f8f2a09a837722b4b83da056aaf371c661c18 Mon Sep 17 00:00:00 2001 From: Dag Date: Tue, 8 Nov 2022 21:17:32 +0100 Subject: [PATCH] fix: various fixes (#3136) --- bridges/FeedMergeBridge.php | 6 +++++- bridges/TwitchBridge.php | 10 +++++++--- bridges/UsbekEtRicaBridge.php | 26 +++++++++++++++----------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/bridges/FeedMergeBridge.php b/bridges/FeedMergeBridge.php index a980dcd4..8fc9dc20 100644 --- a/bridges/FeedMergeBridge.php +++ b/bridges/FeedMergeBridge.php @@ -64,7 +64,11 @@ TEXT; } // Sort by timestamp descending - usort($this->items, fn ($a, $b) => $b['timestamp'] <=> $a['timestamp']); + usort($this->items, function ($a, $b) { + $t1 = $a['timestamp'] ?? $a['uri'] ?? $a['title']; + $t2 = $b['timestamp'] ?? $b['uri'] ?? $b['title']; + return $t2 <=> $t1; + }); // Remove duplicates by using url as unique key $items = []; diff --git a/bridges/TwitchBridge.php b/bridges/TwitchBridge.php index f7e44d1e..b8ff1c40 100644 --- a/bridges/TwitchBridge.php +++ b/bridges/TwitchBridge.php @@ -84,12 +84,16 @@ query VODList($channel: String!, $types: [BroadcastType!]) { } } EOD; + $channel = $this->getInput('channel'); + $type = $this->getInput('type'); $variables = [ - 'channel' => $this->getInput('channel'), - 'types' => self::BROADCAST_TYPES[$this->getInput('type')] + 'channel' => $channel, + 'types' => self::BROADCAST_TYPES[$type] ]; $data = $this->apiRequest($query, $variables); - + if ($data->user === null) { + throw new \Exception(sprintf('Unable to find channel `%s`', $channel)); + } $user = $data->user; foreach ($user->videos->edges as $edge) { $video = $edge->node; diff --git a/bridges/UsbekEtRicaBridge.php b/bridges/UsbekEtRicaBridge.php index 3dd432f0..9cf26995 100644 --- a/bridges/UsbekEtRicaBridge.php +++ b/bridges/UsbekEtRicaBridge.php @@ -49,20 +49,24 @@ class UsbekEtRicaBridge extends BridgeAbstract $item['author'] = $author->plaintext; } + $content = null; + $u = $article->find('a.card-img', 0); - - $uri = $u->href; - if (substr($uri, 0, 1) === 'h') { // absolute uri - $item['uri'] = $uri; - } else { // relative uri - $item['uri'] = $this->getURI() . $uri; + if ($u) { + $uri = $u->href; + if (substr($uri, 0, 1) === 'h') { + // absolute uri + $item['uri'] = $uri; + } else { + // relative uri + $item['uri'] = $this->getURI() . $uri; + } + if ($fullarticle) { + $content = $this->loadFullArticle($item['uri']); + } } - if ($fullarticle) { - $content = $this->loadFullArticle($item['uri']); - } - - if ($fullarticle && !is_null($content)) { + if ($fullarticle && $content) { $item['content'] = $content; } else { $excerpt = $article->find('div.card-excerpt', 0);