[BakaUpdatesMangaReleasesBridge] rework to parse new layout (#1052)

* rework to parse new layout
* skip incomplete rows

The last row could have fewer columns if there are less rows than the items limit. This usually should not happen, though.

* use constant for skipping
This commit is contained in:
fulmeek 2019-03-02 19:09:16 +01:00 committed by LogMANOriginal
parent dac685b887
commit 9d85b951f7
1 changed files with 17 additions and 19 deletions

View File

@ -12,6 +12,7 @@ class BakaUpdatesMangaReleasesBridge extends BridgeAbstract {
'exampleValue' => '12345' 'exampleValue' => '12345'
) )
)); ));
const LIMIT_COLS = 5;
const LIMIT_ITEMS = 10; const LIMIT_ITEMS = 10;
private $feedName = ''; private $feedName = '';
@ -20,21 +21,21 @@ class BakaUpdatesMangaReleasesBridge extends BridgeAbstract {
$html = getSimpleHTMLDOM($this->getURI()) $html = getSimpleHTMLDOM($this->getURI())
or returnServerError('Series not found'); or returnServerError('Series not found');
$objTitle = $html->find('td[class="text pad"]', 1); // content is an unstructured pile of divs, ugly to parse
if ($objTitle) $cols = $html->find('div#main_content div.row > div.text');
$this->feedName = $objTitle->plaintext; if (!$cols)
$itemlist = $html->find('td#main_content table table table tr');
if (!$itemlist)
returnServerError('No releases'); returnServerError('No releases');
$limit = self::LIMIT_ITEMS; $rows = array_slice(
foreach($itemlist as $element) { array_chunk($cols, self::LIMIT_COLS), 0, self::LIMIT_ITEMS
$cols = $element->find('td[class="text pad"]'); );
if (!$cols)
continue; if (isset($rows[0][1])) {
if ($limit <= 0) $this->feedName = html_entity_decode($rows[0][1]->plaintext);
break; }
foreach($rows as $cols) {
if (count($cols) < self::LIMIT_COLS) continue;
$item = array(); $item = array();
$title = array(); $title = array();
@ -66,13 +67,10 @@ class BakaUpdatesMangaReleasesBridge extends BridgeAbstract {
} }
$item['title'] = implode(' ', $title); $item['title'] = implode(' ', $title);
$item['uri'] = $this->getURI() . '#' . hash('sha1', $item['title']); $item['uri'] = $this->getURI();
$item['uid'] = hash('sha1', $item['title']);
$this->items[] = $item; $this->items[] = $item;
if(count($this->items) >= $limit) {
break;
}
} }
} }