Bridges/KemonoFriendsMusicNewsBridge.php

40 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2023-08-11 22:09:51 +02:00
<?php
class KemonoFriendsMusicNewsBridge extends BridgeAbstract {
const MAINTAINER = 'Akamaru';
const NAME = 'Kemono Friends Music News';
const URI = 'https://www.jvcmusic.co.jp/kemono-friends/';
const CACHE_TIMEOUT = 1; // 21600 = 6h
const DESCRIPTION = 'Get the latest news for Kemono Friends Music.';
public function collectData() {
// Retrieve webpage
$pageUrl = self::URI;
$html = getSimpleHTMLDOM($pageUrl)
or returnServerError('Could not request webpage: ' . $pageUrl);
// Process articles
foreach($html->find('ul.l_newslink li') as $element) {
if(count($this->items) >= 10) {
break;
}
$article_title = trim(strip_tags($element->find('p.newslink_txt', 0)->innertext));
$article_uri = self::URI . substr($element->find('a', 0)->href, 0);
// strtotime() doesn't seem to like the missing zeroes in the month
$article_time = trim(strip_tags($element->find('div.newslink_date', 0)->innertext));
$article_timestamp = date_format(date_create_from_format("Y.m.d", $article_time), "d.m.Y");
// Store article in items array
if (!empty($article_title)) {
$item = array();
$item['uri'] = $article_uri;
$item['title'] = $article_title;
$item['timestamp'] = $article_timestamp;
$this->items[] = $item;
}
}
}
}