Add TF1IE
[youtube-dl] / youtube_dl / extractor / wat.py
1 # coding: utf-8
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7
8 from ..utils import (
9     compat_urllib_parse,
10 )
11
12
13 class WatIE(InfoExtractor):
14     _VALID_URL=r'http://www.wat.tv/.*-(?P<shortID>.*?)_.*?.html'
15     IE_NAME = 'wat.tv'
16     _TEST = {
17         u'url': u'http://www.wat.tv/video/world-war-philadelphia-vost-6bv55_2fjr7_.html',
18         u'file': u'6bv55.mp4',
19         u'md5': u'0a4fe7870f31eaeabb5e25fd8da8414a',
20         u'info_dict': {
21             u"title": u"World War Z - Philadelphia VOST"
22         }
23     }
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         short_id = mobj.group('shortID')
28
29         player_data = compat_urllib_parse.urlencode({'shortVideoId': short_id,
30                                                      'html5': '1'})
31         player_info = self._download_webpage('http://www.wat.tv/player?' + player_data,
32                                              short_id, u'Downloading player info')
33         player = json.loads(player_info)['player']
34         html5_player = self._html_search_regex(r'iframe src="(.*?)"', player,
35                                                'html5 player')
36         player_webpage = self._download_webpage(html5_player, short_id,
37                                                 u'Downloading player webpage')
38
39         video_url = self._search_regex(r'urlhtml5 : "(.*?)"', player_webpage,
40                                        'video url')
41         title = self._search_regex(r'contentTitle : "(.*?)"', player_webpage,
42                                    'title')
43         thumbnail = self._search_regex(r'previewMedia : "(.*?)"', player_webpage,
44                                        'thumbnail')
45         return {'id': short_id,
46                 'url': video_url,
47                 'ext': 'mp4',
48                 'title': title,
49                 'thumbnail': thumbnail,
50                 }
51
52 class TF1IE(InfoExtractor):
53     """
54     TF1 uses the wat.tv player, currently it can only download videos with the
55     html5 player enabled, it cannot download HD videos or the news.
56     """
57     _VALID_URL = r'http://videos.tf1.fr/.*-(.*?).html'
58     _TEST = {
59         u'url': u'http://videos.tf1.fr/auto-moto/citroen-grand-c4-picasso-2013-presentation-officielle-8062060.html',
60         u'file': u'6bysb.mp4',
61         u'md5': u'66789d3e91278d332f75e1feb7aea327',
62         u'info_dict': {
63             u"title": u"Citroën Grand C4 Picasso 2013 : présentation officielle"
64         }
65     }
66
67     def _real_extract(self, url):
68         mobj = re.match(self._VALID_URL, url)
69         id = mobj.group(1)
70         webpage = self._download_webpage(url, id)
71         embed_url = self._html_search_regex(r'"(https://www.wat.tv/embedframe/.*?)"',
72                                 webpage, 'embed url')
73         embed_page = self._download_webpage(embed_url, id, u'Downloading embed player page')
74         wat_id = self._search_regex(r'UVID=(.*?)&', embed_page, 'wat id')
75         wat_info = self._download_webpage('http://www.wat.tv/interface/contentv3/%s' % wat_id, id, u'Downloading Wat info')
76         wat_info = json.loads(wat_info)['media']
77         wat_url = wat_info['url']
78         return self.url_result(wat_url, 'Wat')