rssmonster/rssmonster.php

71 lines
1.8 KiB
PHP

<?php
declare(strict_types = 1);
// Some dependencies haven't been updated for PHP 8
// This can probably be removed for PHP 7.3
error_reporting(E_ALL & ~E_DEPRECATED);
require_once('vendor/autoload.php');
include_once('config/default.php');
include_once('lib/log.php');
// include_once('lib/fetch-pages.php');
// include_once('lib/generate-feed.php');
// $content = fetchPages();
// $feedXml = generateFeed($content);
// Log::info("writing " . strlen($feedXml) . " bytes to " . Config::feedPath);
// file_put_contents(Config::feedPath, $feedXml, LOCK_EX);
include_once('lib/fetch-url.php');
$archivePage = fetchUrl(Config::archiveUrl);
class ComicPageLink {
public string $href = '';
public string $pageNo = '';
public string $title = '';
function __construct() {}
function __toString() {
return "[{$this->href}] {$this->pageNo} // {$this->title}\n";
}
};
$comicPageLinks = array();
foreach ($archivePage->find('div.textcontent ul') as $arc) {
$arcHtml = $arc->innerHTML;
$comicLinks = $arc->find('a');
foreach ($comicLinks as $el) {
$link = new ComicPageLink;
$start = strpos($arcHtml, $el->href);
do {
$start += 1;
} while (substr($arcHtml, $start, 4) != '</a>');
$start += 4; // '</a>'
$start += 4; // ' // '
$end = strpos($arcHtml, '<br', $start);
if (!$end) {
$end = strpos($arcHtml, '</', $start);
};
if (!$end) {
throw new Exception("Failed to find a title endpoint at {$el} ({$el->href})");
};
$link->title = trim(substr($arcHtml, $start, $end - $start));
$link->href = Config::baseUrl . "/" . $el->href;
$link->pageNo = $el->innerText;
print $link;
};
};