[WDR] fixed parsing of playlists
[youtube-dl] / youtube_dl / extractor / muzu.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_urllib_parse_urlencode
5
6
7 class MuzuTVIE(InfoExtractor):
8     _VALID_URL = r'https?://www\.muzu\.tv/(.+?)/(.+?)/(?P<id>\d+)'
9     IE_NAME = 'muzu.tv'
10
11     _TEST = {
12         'url': 'http://www.muzu.tv/defected/marcashken-featuring-sos-cat-walk-original-mix-music-video/1981454/',
13         'md5': '98f8b2c7bc50578d6a0364fff2bfb000',
14         'info_dict': {
15             'id': '1981454',
16             'ext': 'mp4',
17             'title': 'Cat Walk (Original Mix)',
18             'description': 'md5:90e868994de201b2570e4e5854e19420',
19             'uploader': 'MarcAshken featuring SOS',
20         },
21     }
22
23     def _real_extract(self, url):
24         video_id = self._match_id(url)
25
26         info_data = compat_urllib_parse_urlencode({
27             'format': 'json',
28             'url': url,
29         })
30         info = self._download_json(
31             'http://www.muzu.tv/api/oembed/?%s' % info_data,
32             video_id, 'Downloading video info')
33
34         player_info = self._download_json(
35             'http://player.muzu.tv/player/playerInit?ai=%s' % video_id,
36             video_id, 'Downloading player info')
37         video_info = player_info['videos'][0]
38         for quality in ['1080', '720', '480', '360']:
39             if video_info.get('v%s' % quality):
40                 break
41
42         data = compat_urllib_parse_urlencode({
43             'ai': video_id,
44             # Even if each time you watch a video the hash changes,
45             # it seems to work for different videos, and it will work
46             # even if you use any non empty string as a hash
47             'viewhash': 'VBNff6djeV4HV5TRPW5kOHub2k',
48             'device': 'web',
49             'qv': quality,
50         })
51         video_url_info = self._download_json(
52             'http://player.muzu.tv/player/requestVideo?%s' % data,
53             video_id, 'Downloading video url')
54         video_url = video_url_info['url']
55
56         return {
57             'id': video_id,
58             'title': info['title'],
59             'url': video_url,
60             'thumbnail': info['thumbnail_url'],
61             'description': info['description'],
62             'uploader': info['author_name'],
63         }