aboutsummaryrefslogtreecommitdiff
path: root/bridges/AllocineFRSortiesBridge.php
blob: a75187bec876ac17d44363d9c27c2620049c92c5 (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
61
62
63
64
65
66
<?php

class AllocineFRSortiesBridge extends BridgeAbstract
{
    const MAINTAINER = 'Simounet';
    const NAME = 'AlloCiné Sorties Bridge';
    const CACHE_TIMEOUT = 25200; // 7h
    const BASE_URI = 'https://www.allocine.fr';
    const URI = self::BASE_URI . '/film/sorties-semaine/';
    const DESCRIPTION = 'Bridge for AlloCiné - Sorties cinéma cette semaine';

    public function getName()
    {
        return self::NAME;
    }

    public function collectData()
    {
        $html = getSimpleHTMLDOM($this->getURI());

        foreach ($html->find('section.section.section-wrap', 0)->find('li.mdl') as $element) {
            $item = [];

            $thumb = $element->find('figure.thumbnail', 0);
            $meta = $element->find('div.meta-body', 0);
            $synopsis = $element->find('div.synopsis', 0);
            $date = $element->find('span.date', 0);

            $title = $element->find('a[class*=meta-title-link]', 0);
            $content = trim(defaultLinkTo($thumb->outertext . $meta->outertext . $synopsis->outertext, static::URI));

            // Replace image 'src' with the one in 'data-src'
            $content = preg_replace('@src="data:image/gif;base64,[A-Za-z0-9=+\/]*"@', '', $content);
            $content = preg_replace('@data-src=@', 'src=', $content);

            $item['content'] = $content;
            $item['title'] = trim($title->innertext);
            $item['timestamp'] = $this->frenchPubDateToTimestamp($date->plaintext);
            $item['uri'] = static::BASE_URI . '/' . substr($title->href, 1);
            $this->items[] = $item;
        }
    }

    private function frenchPubDateToTimestamp($date)
    {
        return strtotime(
            strtr(
                strtolower($date),
                [
                    'janvier' => 'jan',
                    'février' => 'feb',
                    'mars' => 'march',
                    'avril' => 'apr',
                    'mai' => 'may',
                    'juin' => 'jun',
                    'juillet' => 'jul',
                    'août' => 'aug',
                    'septembre' => 'sep',
                    'octobre' => 'oct',
                    'novembre' => 'nov',
                    'décembre' => 'dec'
                ]
            )
        );
    }
}