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