]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/mwave.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / mwave.py
CommitLineData
7900aede 1from .common import InfoExtractor
22c83245
S
2from ..compat import compat_str
3from ..utils import (
4 int_or_none,
5 parse_duration,
6)
7900aede 7
8
9class MwaveIE(InfoExtractor):
f92bb612 10 _VALID_URL = r'https?://mwave\.interest\.me/(?:[^/]+/)?mnettv/videodetail\.m\?searchVideoDetailVO\.clip_id=(?P<id>[0-9]+)'
a5941305 11 _URL_TEMPLATE = 'http://mwave.interest.me/mnettv/videodetail.m?searchVideoDetailVO.clip_id=%s'
f92bb612 12 _TESTS = [{
7900aede 13 'url': 'http://mwave.interest.me/mnettv/videodetail.m?searchVideoDetailVO.clip_id=168859',
a8062eab 14 # md5 is unstable
7900aede 15 'info_dict': {
16 'id': '168859',
17 'ext': 'flv',
18 'title': '[M COUNTDOWN] SISTAR - SHAKE IT',
ec85ded8 19 'thumbnail': r're:^https?://.*\.jpg$',
22c83245
S
20 'uploader': 'M COUNTDOWN',
21 'duration': 206,
22 'view_count': int,
7900aede 23 }
f92bb612
S
24 }, {
25 'url': 'http://mwave.interest.me/en/mnettv/videodetail.m?searchVideoDetailVO.clip_id=176199',
26 'only_matching': True,
27 }]
7900aede 28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31
22c83245 32 vod_info = self._download_json(
7900aede 33 'http://mwave.interest.me/onair/vod_info.m?vodtype=CL&sectorid=&endinfo=Y&id=%s' % video_id,
22c83245 34 video_id, 'Download vod JSON')
7900aede 35
36 formats = []
22c83245
S
37 for num, cdn_info in enumerate(vod_info['cdn']):
38 stream_url = cdn_info.get('url')
39 if not stream_url:
40 continue
41 stream_name = cdn_info.get('name') or compat_str(num)
42 f4m_stream = self._download_json(
43 stream_url, video_id,
44 'Download %s stream JSON' % stream_name)
45 f4m_url = f4m_stream.get('fileurl')
46 if not f4m_url:
47 continue
7900aede 48 formats.extend(
22c83245 49 self._extract_f4m_formats(f4m_url + '&hdcore=3.0.3', video_id, f4m_id=stream_name))
7900aede 50
51 return {
52 'id': video_id,
22c83245
S
53 'title': vod_info['title'],
54 'thumbnail': vod_info.get('cover'),
55 'uploader': vod_info.get('program_title'),
56 'duration': parse_duration(vod_info.get('time')),
57 'view_count': int_or_none(vod_info.get('hit')),
7900aede 58 'formats': formats,
59 }
5b5d7cc1
PR
60
61
62class MwaveMeetGreetIE(InfoExtractor):
f92bb612
S
63 _VALID_URL = r'https?://mwave\.interest\.me/(?:[^/]+/)?meetgreet/view/(?P<id>\d+)'
64 _TESTS = [{
5b5d7cc1
PR
65 'url': 'http://mwave.interest.me/meetgreet/view/256',
66 'info_dict': {
67 'id': '173294',
68 'ext': 'flv',
69 'title': '[MEET&GREET] Park BoRam',
ec85ded8 70 'thumbnail': r're:^https?://.*\.jpg$',
5b5d7cc1
PR
71 'uploader': 'Mwave',
72 'duration': 3634,
73 'view_count': int,
74 }
f92bb612
S
75 }, {
76 'url': 'http://mwave.interest.me/en/meetgreet/view/256',
77 'only_matching': True,
78 }]
5b5d7cc1
PR
79
80 def _real_extract(self, url):
81 video_id = self._match_id(url)
82 webpage = self._download_webpage(url, video_id)
a5941305
YCH
83 clip_id = self._html_search_regex(
84 r'<iframe[^>]+src="/mnettv/ifr_clip\.m\?searchVideoDetailVO\.clip_id=(\d+)',
85 webpage, 'clip ID')
86 clip_url = MwaveIE._URL_TEMPLATE % clip_id
5b5d7cc1 87 return self.url_result(clip_url, 'Mwave', clip_id)