aboutsummaryrefslogtreecommitdiff
path: root/bridges/MangaReaderBridge.php
blob: 1b8e765b13450f405c8ad938ce008e65c8351aec (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
<?php

class MangaReaderBridge extends BridgeAbstract
{
    const NAME = 'MangaReader Bridge';
    const URI = 'https://mangareader.to';
    const DESCRIPTION = 'Fetches the latest chapters from MangaReader.to.';
    const MAINTAINER = 'cubethethird';
    const PARAMETERS = [
        [
            'url' => [
                'name' => 'Manga URL',
                'type' => 'text',
                'required' => true,
                'title' => 'The URL of the manga on MangaReader',
                'pattern' => '^https:\/\/mangareader\.to\/[^\/]+$',
                'exampleValue' => 'https://mangareader.to/bleach-1623',
            ],
            'lang' => [
                'name' => 'Chapter Language',
                'title' => 'two-letter language code (example "en", "jp", "fr")',
                'exampleValue' => 'en',
                'required' => true,
                'pattern' => '^[a-z][a-z]$',
            ]
        ]
    ];

    protected $feedName = '';


    public function getName()
    {
        if (empty($this->feedName)) {
            return parent::getName();
        } else {
            return $this->feedName;
        }
    }

    public function collectData()
    {
        $url = $this->getInput('url');
        $lang = $this->getInput('lang');
        $dom = getSimpleHTMLDOM($url);
        $aniDetail = $dom->getElementById('ani_detail');
        $this->feedName = html_entity_decode($aniDetail->find('h2', 0)->plaintext);

        $chapters = $dom->getElementById($lang . '-chapters');

        foreach ($chapters->getElementsByTagName('li') as $chapter) {
            $a = $chapter->getElementsByTagName('a')[0];
            $item = [];
            $item['title'] = $a->getAttribute('title');
            $item['uri'] = self::URI . $a->getAttribute('href');
            $this->items[] = $item;
        }
    }
}