]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/flextv.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / flextv.py
CommitLineData
4f043479
D
1from .common import InfoExtractor
2from ..networking.exceptions import HTTPError
3from ..utils import (
4 ExtractorError,
5 UserNotLive,
6 parse_iso8601,
7 str_or_none,
8 traverse_obj,
9 url_or_none,
10)
11
12
13class FlexTVIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?flextv\.co\.kr/channels/(?P<id>\d+)/live'
15 _TESTS = [{
16 'url': 'https://www.flextv.co.kr/channels/231638/live',
17 'info_dict': {
18 'id': '231638',
19 'ext': 'mp4',
20 'title': r're:^214하나만\.\.\. ',
21 'thumbnail': r're:^https?://.+\.jpg',
22 'upload_date': r're:\d{8}',
23 'timestamp': int,
24 'live_status': 'is_live',
25 'channel': 'Hi별',
26 'channel_id': '244396',
27 },
28 'skip': 'The channel is offline',
29 }, {
30 'url': 'https://www.flextv.co.kr/channels/746/live',
31 'only_matching': True,
32 }]
33
34 def _real_extract(self, url):
35 channel_id = self._match_id(url)
36
37 try:
38 stream_data = self._download_json(
39 f'https://api.flextv.co.kr/api/channels/{channel_id}/stream',
40 channel_id, query={'option': 'all'})
41 except ExtractorError as e:
42 if isinstance(e.cause, HTTPError) and e.cause.status == 400:
43 raise UserNotLive(video_id=channel_id)
44 raise
45
46 playlist_url = stream_data['sources'][0]['url']
47 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
48 playlist_url, channel_id, 'mp4')
49
50 return {
51 'id': channel_id,
52 'formats': formats,
53 'subtitles': subtitles,
54 'is_live': True,
55 **traverse_obj(stream_data, {
56 'title': ('stream', 'title', {str}),
57 'timestamp': ('stream', 'createdAt', {parse_iso8601}),
58 'thumbnail': ('thumbUrl', {url_or_none}),
59 'channel': ('owner', 'name', {str}),
60 'channel_id': ('owner', 'id', {str_or_none}),
61 }),
62 }