aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dlc/extractor/bitwave.py
blob: 9aa2105104d810a4e41f382aa6109c71c3fe6451 (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
from __future__ import unicode_literals

from .common import InfoExtractor


class BitwaveReplayIE(InfoExtractor):
    IE_NAME = 'bitwave:replay'
    _VALID_URL = r'https?://(?:www\.)?bitwave\.tv/(?P<user>\w+)/replay/(?P<id>\w+)/?$'

    def _real_extract(self, url):
        replay_id = self._match_id(url)
        replay = self._download_json(
            'https://api.bitwave.tv/v1/replays/' + replay_id,
            replay_id
        )

        return {
            'id': replay_id,
            'title': replay['data']['title'],
            'uploader': replay['data']['name'],
            'uploader_id': replay['data']['name'],
            'url': replay['data']['url'],
            'thumbnails': [
                {'url': x} for x in replay['data']['thumbnails']
            ],
        }


class BitwaveStreamIE(InfoExtractor):
    IE_NAME = 'bitwave:stream'
    _VALID_URL = r'https?://(?:www\.)?bitwave\.tv/(?P<id>\w+)/?$'

    def _real_extract(self, url):
        username = self._match_id(url)
        channel = self._download_json(
            'https://api.bitwave.tv/v1/channels/' + username,
            username)

        formats = self._extract_m3u8_formats(
            channel['data']['url'], username,
            'mp4')
        self._sort_formats(formats)

        return {
            'id': username,
            'title': self._live_title(channel['data']['title']),
            'uploader': username,
            'uploader_id': username,
            'formats': formats,
            'thumbnail': channel['data']['thumbnail'],
            'is_live': True,
            'view_count': channel['data']['viewCount']
        }