2 from __future__ import unicode_literals
4 from .common import InfoExtractor
6 from ..utils import js_to_json
9 class TF1IE(InfoExtractor):
10 """TF1 uses the wat.tv player."""
11 _VALID_URL = r'https?://(?:(?:videos|www|lci)\.tf1|(?:www\.)?(?:tfou|ushuaiatv|histoire|tvbreizh))\.fr/(?:[^/]+/)*(?P<id>[^/?#.]+)'
13 'url': 'http://videos.tf1.fr/auto-moto/citroen-grand-c4-picasso-2013-presentation-officielle-8062060.html',
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.',
21 # Sometimes wat serves the whole file with the --test option
22 'skip_download': True,
24 'expected_warnings': ['HTTP Error 404'],
26 'url': 'http://www.tfou.fr/chuggington/videos/le-grand-mysterioso-chuggington-7085291-739.html',
28 'id': 'le-grand-mysterioso-chuggington-7085291-739',
30 'title': 'Le grand Mystérioso - Chuggington',
31 'description': 'Le grand Mystérioso - Emery rêve qu\'un article lui soit consacré dans le journal.',
32 'upload_date': '20150103',
35 # Sometimes wat serves the whole file with the --test option
36 'skip_download': True,
38 'skip': 'HTTP Error 410: Gone',
40 'url': 'http://www.tf1.fr/tf1/koh-lanta/videos/replay-koh-lanta-22-mai-2015.html',
41 'only_matching': True,
43 'url': 'http://lci.tf1.fr/sept-a-huit/videos/sept-a-huit-du-24-mai-2015-8611550.html',
44 'only_matching': True,
46 'url': 'http://www.tf1.fr/hd1/documentaire/videos/mylene-farmer-d-une-icone.html',
47 'only_matching': True,
49 'url': 'https://www.tf1.fr/tmc/quotidien-avec-yann-barthes/videos/quotidien-premiere-partie-11-juin-2019.html',
53 'title': 'md5:f392bc52245dc5ad43771650c96fb620',
54 'description': 'md5:44bc54f0a21322f5b91d68e76a544eae',
55 'upload_date': '20190611',
58 # Sometimes wat serves the whole file with the --test option
59 'skip_download': True,
63 def _real_extract(self, url):
64 video_id = self._match_id(url)
65 webpage = self._download_webpage(url, video_id)
66 vids_data_string = self._html_search_regex(
67 r'<script>\s*window\.__APOLLO_STATE__\s*=\s*(?P<vids_data_string>\{.*?\})\s*;?\s*</script>',
68 webpage, 'videos data string', group='vids_data_string', default=None)
70 if vids_data_string is not None:
71 vids_data = self._parse_json(
72 vids_data_string, video_id,
73 transform_source=js_to_json)
74 video_data = [v for v in vids_data.values()
75 if 'slug' in v and v['slug'] == video_id]
76 if len(video_data) > 0 and 'streamId' in video_data[0]:
77 wat_id = video_data[0]['streamId']
79 wat_id = self._html_search_regex(
80 [r'(["\'])(?:https?:)?//www\.wat\.tv/embedframe/.*?(?P<id>\d{8})\1',
81 r'(["\']?)streamId\1\s*:\s*(["\']?)(?P<id>\d+)\2'
83 webpage, 'wat id', group='id')
84 return self.url_result('wat:%s' % wat_id, 'Wat')