]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/freshlive.py
[afreecatv] Support password-protected livestreams (#2738)
[yt-dlp.git] / yt_dlp / extractor / freshlive.py
CommitLineData
5fc8d893
RC
1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
e498758b 5from ..compat import compat_str
5fc8d893 6from ..utils import (
e498758b 7 ExtractorError,
5fc8d893 8 int_or_none,
e498758b
S
9 try_get,
10 unified_timestamp,
5fc8d893
RC
11)
12
e498758b
S
13
14class FreshLiveIE(InfoExtractor):
15 _VALID_URL = r'https?://freshlive\.tv/[^/]+/(?P<id>\d+)'
5fc8d893
RC
16 _TEST = {
17 'url': 'https://freshlive.tv/satotv/74712',
e498758b 18 'md5': '9f0cf5516979c4454ce982df3d97f352',
5fc8d893 19 'info_dict': {
5fc8d893
RC
20 'id': '74712',
21 'ext': 'mp4',
5fc8d893 22 'title': 'テスト',
e498758b 23 'description': 'テスト',
5fc8d893 24 'thumbnail': r're:^https?://.*\.jpg$',
e498758b
S
25 'duration': 1511,
26 'timestamp': 1483619655,
5fc8d893
RC
27 'upload_date': '20170105',
28 'uploader': 'サトTV',
29 'uploader_id': 'satotv',
30 'view_count': int,
e498758b
S
31 'comment_count': int,
32 'is_live': False,
5fc8d893
RC
33 }
34 }
35
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
e498758b 38
5fc8d893
RC
39 webpage = self._download_webpage(url, video_id)
40
41 options = self._parse_json(
42 self._search_regex(
43 r'window\.__CONTEXT__\s*=\s*({.+?});\s*</script>',
44 webpage, 'initial context'),
45 video_id)
46
e498758b 47 info = options['context']['dispatcher']['stores']['ProgramStore']['programs'][video_id]
5fc8d893 48
e498758b
S
49 title = info['title']
50
51 if info.get('status') == 'upcoming':
52 raise ExtractorError('Stream %s is upcoming' % video_id, expected=True)
53
54 stream_url = info.get('liveStreamUrl') or info['archiveStreamUrl']
55
56 is_live = info.get('liveStreamUrl') is not None
5fc8d893
RC
57
58 formats = self._extract_m3u8_formats(
fb4fc449
RA
59 stream_url, video_id, 'mp4',
60 'm3u8_native', m3u8_id='hls')
e498758b 61
5fc8d893
RC
62 return {
63 'id': video_id,
64 'formats': formats,
e498758b 65 'title': title,
5fc8d893 66 'description': info.get('description'),
5fc8d893 67 'thumbnail': info.get('thumbnailUrl'),
e498758b
S
68 'duration': int_or_none(info.get('airTime')),
69 'timestamp': unified_timestamp(info.get('createdAt')),
70 'uploader': try_get(
71 info, lambda x: x['channel']['title'], compat_str),
72 'uploader_id': try_get(
73 info, lambda x: x['channel']['code'], compat_str),
74 'uploader_url': try_get(
75 info, lambda x: x['channel']['permalink'], compat_str),
5fc8d893 76 'view_count': int_or_none(info.get('viewCount')),
e498758b
S
77 'comment_count': int_or_none(info.get('commentCount')),
78 'tags': info.get('tags', []),
79 'is_live': is_live,
80 }