summaryrefslogtreecommitdiff
path: root/bridges/RTBFBridge.php
blob: 0f0acdc897b38d2f1d3ea13a72e1bdb1d48e8fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class RTBFBridge extends BridgeAbstract {
	const NAME = 'RTBF Bridge';
	const URI = 'http://www.rtbf.be/auvio/';
	const CACHE_TIMEOUT = 21600; //6h
	const DESCRIPTION = 'Returns the newest RTBF videos by series ID';
	const MAINTAINER = 'Frenzie';

	const PARAMETERS = array( array(
		'c' => array(
			'name' => 'series id',
			'exampleValue' => 9500,
			'required' => true
		)
	));

	public function collectData(){
		$html = '';
		$limit = 10;
		$count = 0;

		$html = getSimpleHTMLDOM($this->getURI())
			or returnServerError('Could not request RTBF.');

		foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) {
			if($count >= $limit) {
				break;
			}

			$item = array();
			$item['id'] = $element->getAttribute('data-id');
			$item['uri'] = self::URI . 'detail?id=' . $item['id'];
			$thumbnailUriSrcSet = explode(
				',',
				$element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset')
			);

			$thumbnailUriLastSrc = end($thumbnailUriSrcSet);
			$thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0];
			$item['title'] = trim($element->find('h3', 0)->plaintext)
			. ' - '
			. trim($element->find('h4', 0)->plaintext);

			$item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime'));
			$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>';
			$this->items[] = $item;
			$count++;
		}
	}

	public function getURI(){
		if(!is_null($this->getInput('c'))) {
			return self::URI . 'emissions/detail?id=' . $this->getInput('c');
		}

		return parent::getURI() . 'emissions/';
	}

	public function getName(){
		if(!is_null($this->getInput('c'))) {
			return $this->getInput('c') . ' - RTBF Bridge';
		}

		return parent::getName();
	}
}