This commit is contained in:
Dave Z 2025-04-02 21:33:10 -04:00 committed by GitHub
commit 9593532d44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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'] = '<img src="' . $json['contentUrl'] . '" alt="">';
$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'] = '<img src="' . $imagelink . '" />';
$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]];
}
}
}