[tf1] add support for TFOU
[youtube-dl] / youtube_dl / extractor / tf1.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8
9 class TF1IE(InfoExtractor):
10     """TF1 uses the wat.tv player."""
11     _VALID_URL = r'http://(?:videos\.tf1|www\.tfou)\.fr/.*?-(?P<id>\d+)(?:-\d+)?\.html'
12     _TESTS = {
13         'url': 'http://videos.tf1.fr/auto-moto/citroen-grand-c4-picasso-2013-presentation-officielle-8062060.html',
14         'info_dict': {
15             'id': '10635995',
16             'ext': 'mp4',
17             'title': 'Citroën Grand C4 Picasso 2013 : présentation officielle',
18             'description': 'Vidéo officielle du nouveau Citroën Grand C4 Picasso, lancé à l\'automne 2013.',
19         },
20         'params': {
21             # Sometimes wat serves the whole file with the --test option
22             'skip_download': True,
23         },
24     }, {
25         'url': 'http://www.tfou.fr/chuggington/videos/le-grand-mysterioso-chuggington-7085291-739.html',
26         'info_dict': {
27             'id': '7085291',
28             'ext': 'mp4',
29             'title': 'Le grand Mystérioso - Chuggington',
30             'description': 'Emery rêve qu\'un article lui soit consacré dans le journal.',
31         },
32         'params': {
33             # Sometimes wat serves the whole file with the --test option
34             'skip_download': True,
35         },
36     }
37
38     def _real_extract(self, url):
39         video_id = self._match_id(url)
40         webpage = self._download_webpage(url, video_id)
41         embed_url = self._html_search_regex(
42             r'["\'](http(?:s)?://www.wat.tv/embedframe/.*?)["\']', webpage, 'embed url')
43         embed_page = self._download_webpage(embed_url, video_id,
44                                             'Downloading embed player page')
45         wat_id = self._search_regex(r'UVID=(.*?)&', embed_page, 'wat id')
46         wat_info = self._download_json(
47             'http://www.wat.tv/interface/contentv3/%s' % wat_id, video_id)
48         return self.url_result(wat_info['media']['url'], 'Wat')