From 161b3b8ed0c49958d943c53cf488b4116e732cff Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 2 Apr 2025 21:25:12 -0400 Subject: [PATCH] [GoComics] Update to new website structure. Added `detectParameters()` method. --- bridges/GoComicsBridge.php | 45 +++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/bridges/GoComicsBridge.php b/bridges/GoComicsBridge.php index 586e2a0d..e9014ae1 100644 --- a/bridges/GoComicsBridge.php +++ b/bridges/GoComicsBridge.php @@ -18,27 +18,29 @@ class GoComicsBridge extends BridgeAbstract public function collectData() { - $html = getSimpleHTMLDOM($this->getURI()); - - //Get info from first page - $author = preg_replace('/By /', '', $html->find('.media-subheading', 0)->plaintext); - - $link = self::URI . $html->find('.gc-deck--cta-0', 0)->find('a', 0)->href; for ($i = 0; $i < 5; $i++) { + if (isset($dateObj)) { + $dateObj->modify('-1 day'); + $publishedUri = $dateObj->format('/Y/m/d'); + } else { + $publishedUri = ''; + } + + $html = getSimpleHTMLDOM($this->getURI() . $publishedUri); + $page = $html->find('div[class^="ComicViewer_comicViewer__comic__"] script[type="application/ld+json"]', 0); + $json = Json::decode($page->innertext); + + $dateObj = DateTime::createFromFormat('F j, Y', $json['datePublished']); + $item = []; + $item['id'] = $json['contentUrl']; + $item['uri'] = $this->getURI() . $dateObj->format('/Y/m/d'); + $item['author'] = $json['author']['name']; + $item['title'] = 'GoComics ' . $json['name']; + $item['timestamp'] = $dateObj->getTimestamp(); + $item['enclosures'][] = $json['contentUrl']; + $item['content'] = ''; - $page = getSimpleHTMLDOM($link); - $imagelink = $page->find('.comic.container', 0)->getAttribute('data-image'); - $date = explode('/', $link); - - $item['id'] = $imagelink; - $item['uri'] = $link; - $item['author'] = $author; - $item['title'] = 'GoComics ' . $this->getInput('comicname'); - $item['timestamp'] = DateTime::createFromFormat('Ymd', $date[5] . $date[6] . $date[7])->getTimestamp(); - $item['content'] = ''; - - $link = self::URI . $page->find('.js-previous-comic', 0)->href; $this->items[] = $item; } } @@ -60,4 +62,11 @@ class GoComicsBridge extends BridgeAbstract return parent::getName(); } + + public function detectParameters($url) + { + if (preg_match('#^' . self::URI . '([-a-z0-9]+)$#i', $url, $matches)) { + return ['comicname' => $matches[1]]; + } + } }