]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tf1.py
Update upstream source from tag 'upstream/2019.09.28'
[youtubedl] / youtube_dl / extractor / tf1.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6
7
8 class TF1IE(InfoExtractor):
9 """TF1 uses the wat.tv player."""
10 _VALID_URL = r'https?://(?:(?:videos|www|lci)\.tf1|(?:www\.)?(?:tfou|ushuaiatv|histoire|tvbreizh))\.fr/(?:[^/]+/)*(?P<id>[^/?#.]+)'
11 _TESTS = [{
12 'url': 'http://videos.tf1.fr/auto-moto/citroen-grand-c4-picasso-2013-presentation-officielle-8062060.html',
13 'info_dict': {
14 'id': '10635995',
15 'ext': 'mp4',
16 'title': 'Citroën Grand C4 Picasso 2013 : présentation officielle',
17 'description': 'Vidéo officielle du nouveau Citroën Grand C4 Picasso, lancé à l\'automne 2013.',
18 },
19 'params': {
20 # Sometimes wat serves the whole file with the --test option
21 'skip_download': True,
22 },
23 'expected_warnings': ['HTTP Error 404'],
24 }, {
25 'url': 'http://www.tfou.fr/chuggington/videos/le-grand-mysterioso-chuggington-7085291-739.html',
26 'info_dict': {
27 'id': 'le-grand-mysterioso-chuggington-7085291-739',
28 'ext': 'mp4',
29 'title': 'Le grand Mystérioso - Chuggington',
30 'description': 'Le grand Mystérioso - Emery rêve qu\'un article lui soit consacré dans le journal.',
31 'upload_date': '20150103',
32 },
33 'params': {
34 # Sometimes wat serves the whole file with the --test option
35 'skip_download': True,
36 },
37 'skip': 'HTTP Error 410: Gone',
38 }, {
39 'url': 'http://www.tf1.fr/tf1/koh-lanta/videos/replay-koh-lanta-22-mai-2015.html',
40 'only_matching': True,
41 }, {
42 'url': 'http://lci.tf1.fr/sept-a-huit/videos/sept-a-huit-du-24-mai-2015-8611550.html',
43 'only_matching': True,
44 }, {
45 'url': 'http://www.tf1.fr/hd1/documentaire/videos/mylene-farmer-d-une-icone.html',
46 'only_matching': True,
47 }, {
48 'url': 'https://www.tf1.fr/tmc/quotidien-avec-yann-barthes/videos/quotidien-premiere-partie-11-juin-2019.html',
49 'info_dict': {
50 'id': '13641379',
51 'ext': 'mp4',
52 'title': 'md5:f392bc52245dc5ad43771650c96fb620',
53 'description': 'md5:44bc54f0a21322f5b91d68e76a544eae',
54 'upload_date': '20190611',
55 },
56 'params': {
57 # Sometimes wat serves the whole file with the --test option
58 'skip_download': True,
59 },
60 }]
61
62 def _real_extract(self, url):
63 video_id = self._match_id(url)
64
65 webpage = self._download_webpage(url, video_id)
66
67 wat_id = None
68
69 data = self._parse_json(
70 self._search_regex(
71 r'__APOLLO_STATE__\s*=\s*({.+?})\s*(?:;|</script>)', webpage,
72 'data', default='{}'), video_id, fatal=False)
73
74 if data:
75 try:
76 wat_id = next(
77 video.get('streamId')
78 for key, video in data.items()
79 if isinstance(video, dict)
80 and video.get('slug') == video_id)
81 if not isinstance(wat_id, compat_str) or not wat_id.isdigit():
82 wat_id = None
83 except StopIteration:
84 pass
85
86 if not wat_id:
87 wat_id = self._html_search_regex(
88 (r'(["\'])(?:https?:)?//www\.wat\.tv/embedframe/.*?(?P<id>\d{8})\1',
89 r'(["\']?)streamId\1\s*:\s*(["\']?)(?P<id>\d+)\2'),
90 webpage, 'wat id', group='id')
91
92 return self.url_result('wat:%s' % wat_id, 'Wat')