Add WatIE
[youtube-dl] / youtube_dl / extractor / wat.py
1 import json
2 import re
3
4 from .common import InfoExtractor
5
6 from ..utils import (
7     compat_urllib_parse,
8 )
9
10
11 class WatIE(InfoExtractor):
12     _VALID_URL=r'http://www.wat.tv/.*-(?P<shortID>.*?)_.*?.html'
13     IE_NAME = 'wat.tv'
14     _TEST = {
15         u'url': u'http://www.wat.tv/video/world-war-philadelphia-vost-6bv55_2fjr7_.html',
16         u'file': u'6bv55.mp4',
17         u'md5': u'0a4fe7870f31eaeabb5e25fd8da8414a',
18         u'info_dict': {
19             u"title": u"World War Z - Philadelphia VOST"
20         }
21     }
22
23     def _real_extract(self, url):
24         mobj = re.match(self._VALID_URL, url)
25         short_id = mobj.group('shortID')
26
27         player_data = compat_urllib_parse.urlencode({'shortVideoId': short_id,
28                                                      'html5': '1'})
29         player_info = self._download_webpage('http://www.wat.tv/player?' + player_data,
30                                              short_id, u'Downloading player info')
31         player = json.loads(player_info)['player']
32         html5_player = self._html_search_regex(r'iframe src="(.*?)"', player,
33                                                'html5 player')
34         player_webpage = self._download_webpage(html5_player, short_id,
35                                                 u'Downloading player webpage')
36
37         video_url = self._search_regex(r'urlhtml5 : "(.*?)"', player_webpage,
38                                        'video url')
39         title = self._search_regex(r'contentTitle : "(.*?)"', player_webpage,
40                                    'title')
41         thumbnail = self._search_regex(r'previewMedia : "(.*?)"', player_webpage,
42                                        'thumbnail')
43         return {'id': short_id,
44                 'url': video_url,
45                 'ext': 'mp4',
46                 'title': title,
47                 'thumbnail': thumbnail,
48                 }