aboutsummaryrefslogtreecommitdiff
path: root/bridges/PicartoBridge.php
blob: 0326e02d9929d1fde3e49af6e7014e26c0f3aa0e (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
<?php

class PicartoBridge extends BridgeAbstract
{
    const NAME = 'Picarto';
    const URI = 'https://picarto.tv';
    const DESCRIPTION = 'Produces a new feed item each time a channel goes live';
    const CACHE_TIMEOUT = 300;
    const PARAMETERS = [[
            'channel' => [
                'name'      => 'Channel name',
                'type'      => 'text',
                'required'  => true,
                'title'     => 'Channel name',
                'exampleValue' => 'Wysdrem',
            ],
        ]
    ];

    public function collectData()
    {
        $channel = $this->getInput('channel');
        $data = json_decode(getContents('https://api.picarto.tv/api/v1/channel/name/' . $channel), true);
        if (!$data['online']) {
            return;
        }
        $lastLive = new \DateTime($data['last_live']);
        $this->items[] = [
            'uri' => 'https://picarto.tv/' . $channel,
            'title' => $data['name'] . ' is now online',
            'content' => sprintf('<img src="%s"/>', $data['thumbnails']['tablet']),
            'timestamp' => $lastLive->getTimestamp(),
            'uid' => 'https://picarto.tv/' . $channel . $lastLive->getTimestamp(),
        ];
    }

    public function getName()
    {
        return 'Picarto - ' . $this->getInput('channel');
    }
}