Skip to content

Commit

Permalink
[BakaUpdatesMangaReleasesBridge] rework to parse new layout (#1052)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fulmeek authored and logmanoriginal committed Mar 2, 2019
1 parent dac685b commit 9d85b95
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions bridges/BakaUpdatesMangaReleasesBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BakaUpdatesMangaReleasesBridge extends BridgeAbstract {
'exampleValue' => '12345'
)
));
const LIMIT_COLS = 5;
const LIMIT_ITEMS = 10;

private $feedName = '';
Expand All @@ -20,21 +21,21 @@ public function collectData() {
$html = getSimpleHTMLDOM($this->getURI())
or returnServerError('Series not found');

$objTitle = $html->find('td[class="text pad"]', 1);
if ($objTitle)
$this->feedName = $objTitle->plaintext;

$itemlist = $html->find('td#main_content table table table tr');
if (!$itemlist)
// content is an unstructured pile of divs, ugly to parse
$cols = $html->find('div#main_content div.row > div.text');
if (!$cols)
returnServerError('No releases');

$limit = self::LIMIT_ITEMS;
foreach($itemlist as $element) {
$cols = $element->find('td[class="text pad"]');
if (!$cols)
continue;
if ($limit <= 0)
break;
$rows = array_slice(
array_chunk($cols, self::LIMIT_COLS), 0, self::LIMIT_ITEMS
);

if (isset($rows[0][1])) {
$this->feedName = html_entity_decode($rows[0][1]->plaintext);
}

foreach($rows as $cols) {
if (count($cols) < self::LIMIT_COLS) continue;

$item = array();
$title = array();
Expand Down Expand Up @@ -65,14 +66,11 @@ public function collectData() {
$item['content'] .= '<p>Groups: ' . $objAuthor->innertext . '</p>';
}

$item['title'] = implode(' ', $title);
$item['uri'] = $this->getURI() . '#' . hash('sha1', $item['title']);
$item['title'] = implode(' ', $title);
$item['uri'] = $this->getURI();
$item['uid'] = hash('sha1', $item['title']);

$this->items[] = $item;

if(count($this->items) >= $limit) {
break;
}
}
}

Expand Down

0 comments on commit 9d85b95

Please sign in to comment.