[melonvod] Add extractor for vod.melon.com
[youtube-dl] / youtube_dl / extractor / melonvod.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import int_or_none
6
7
8 class MelonVODIE(InfoExtractor):
9     _VALID_URL = r'https?://vod\.melon\.com/video/detail2\.html?.*mvId=(?P<id>[0-9]+)'
10     _TEST = {
11         'url': 'http://vod.melon.com/video/detail2.htm?mvId=50158734',
12         'md5': '461fc04c6d23cbf49f4fef4d61851d32',
13         'info_dict': {
14             'id': '50158734',
15             'ext': 'mp4',
16             'title': 'Jessica \'Wonderland\' MV Making Film',
17             'thumbnail': 're:^https?://.*\.jpg$',
18             'artist': 'Jessica (์ œ์‹œ์นด)',
19             'upload_date': '20161212',
20             'duration': 203,
21         },
22         'params': {
23             'skip_download': 'm3u8 download',
24         }
25     }
26
27     def _real_extract(self, url):
28         video_id = self._match_id(url)
29
30         play_info = self._download_json(
31             'http://vod.melon.com/video/playerInfo.json', video_id,
32             note='Downloading playerInfo', query={'mvId': video_id}
33         )
34         title = play_info['mvInfo']['MVTITLE']
35         artist = ', '.join([artist['ARTISTNAMEWEBLIST'] for artist in play_info.get('artistList', [])])
36
37         info = self._download_json(
38             'http://vod.melon.com/delivery/streamingInfo.json', video_id,
39             note='Downloading streamingInfo',
40             query={'contsId': video_id, 'contsType': 'VIDEO'}
41         )
42         stream_info = info.get('streamingInfo', {})
43         m3u8_url = stream_info.get('encUrl')
44         formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls')
45         self._sort_formats(formats)
46
47         thumbnail = info.get('staticDomain', '') + stream_info.get('imgPath', '')
48         duration = int_or_none(stream_info.get('playTime'))
49         upload_date = stream_info.get('mvSvcOpenDt', '')[:8]
50
51         return {
52             'id': video_id,
53             'title': title,
54             'artist': artist,
55             'thumbnail': thumbnail,
56             'upload_date': upload_date,
57             'duration': duration,
58             'formats': formats
59         }