aboutsummaryrefslogtreecommitdiff
path: root/bridges/NewOnNetflixBridge.php
blob: 43278fd9eb71748d4e506ebdee29b12855c96c2d (plain) (blame)
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
<?php

class NewOnNetflixBridge extends BridgeAbstract
{
    const NAME = 'NewOnNetflix removals bridge';
    const URI = 'https://www.newonnetflix.info';
    const DESCRIPTION = 'Upcoming removals from Netflix (NewOnNetflix already provides additions as RSS)';
    const MAINTAINER = 'jdesgats';
    const PARAMETERS = [[
        'country' => [
            'name' => 'Country',
            'type' => 'list',
            'values' => [
                'Australia/New Zealand' => 'anz',
                'Canada' => 'can',
                'United Kingdom' => 'uk',
                'United States' => 'usa',
            ],
            'defaultValue' => 'uk',
        ]
    ]];
    const CACHE_TIMEOUT = 3600 * 24;

    public function collectData()
    {
        $baseURI = 'https://' . $this->getInput('country') . '.newonnetflix.info';
        $html = getSimpleHTMLDOMCached($baseURI . '/lastchance', self::CACHE_TIMEOUT);

        foreach ($html->find('article.oldpost') as $element) {
            $title = $element->find('a.infopop[title]', 0);
            $img = $element->find('img[lazy_src]', 0);
            $date = $element->find('span[title]', 0);

            // format sholud be 'dd/mm/yy - dd/mm/yy'
            // (the added date might be "unknown")
            $fromTo = [];
            if (preg_match('/^\s*(.*?)\s*-\s*(.*?)\s*$/', $date->title, $fromTo)) {
                $from = $fromTo[1];
                $to = $fromTo[2];
            } else {
                $from = 'unknown';
                $to = 'unknown';
            }
            $summary = <<<EOD
				<img src="{$img->lazy_src}" loading="lazy">
				<div>{$title->title}</div>
				<div><strong>Added on:</strong>$from</div>
				<div><strong>Removed on:</strong>$to</div>
EOD;

            $item = [];
            $item['uri'] = $baseURI . $title->href;
            $item['title'] = $to . ' - ' . $title->plaintext;
            $item['content'] = $summary;
            // some movies are added and removed multiple times
            $item['uid'] = $title->href . '-' . $to;
            $this->items[] = $item;
        }
    }
}