]>
Commit | Line | Data |
---|---|---|
705f6f35 | 1 | # coding: utf-8 |
2da67107 | 2 | from __future__ import unicode_literals |
705f6f35 | 3 | |
705f6f35 | 4 | from .common import InfoExtractor |
1c112040 | 5 | from ..compat import compat_str |
9c2aaac2 | 6 | |
2da67107 | 7 | |
705f6f35 | 8 | class TF1IE(InfoExtractor): |
0725f584 | 9 | """TF1 uses the wat.tv player.""" |
db3b8b21 | 10 | _VALID_URL = r'https?://(?:(?:videos|www|lci)\.tf1|(?:www\.)?(?:tfou|ushuaiatv|histoire|tvbreizh))\.fr/(?:[^/]+/)*(?P<id>[^/?#.]+)' |
42833b44 | 11 | _TESTS = [{ |
2da67107 JMF |
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, | |
fa800269 | 22 | }, |
8b183bd5 | 23 | 'expected_warnings': ['HTTP Error 404'], |
382e05fa | 24 | }, { |
25 | 'url': 'http://www.tfou.fr/chuggington/videos/le-grand-mysterioso-chuggington-7085291-739.html', | |
26 | 'info_dict': { | |
ad1b6017 | 27 | 'id': 'le-grand-mysterioso-chuggington-7085291-739', |
382e05fa | 28 | 'ext': 'mp4', |
29 | 'title': 'Le grand Mystérioso - Chuggington', | |
2bf098ed | 30 | 'description': 'Le grand Mystérioso - Emery rêve qu\'un article lui soit consacré dans le journal.', |
31 | 'upload_date': '20150103', | |
382e05fa | 32 | }, |
33 | 'params': { | |
34 | # Sometimes wat serves the whole file with the --test option | |
35 | 'skip_download': True, | |
36 | }, | |
ad1b6017 | 37 | 'skip': 'HTTP Error 410: Gone', |
42833b44 YCH |
38 | }, { |
39 | 'url': 'http://www.tf1.fr/tf1/koh-lanta/videos/replay-koh-lanta-22-mai-2015.html', | |
40 | 'only_matching': True, | |
e6e63e91 S |
41 | }, { |
42 | 'url': 'http://lci.tf1.fr/sept-a-huit/videos/sept-a-huit-du-24-mai-2015-8611550.html', | |
43 | 'only_matching': True, | |
05467d5a S |
44 | }, { |
45 | 'url': 'http://www.tf1.fr/hd1/documentaire/videos/mylene-farmer-d-une-icone.html', | |
46 | 'only_matching': True, | |
9c2aaac2 EF |
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 | }, | |
42833b44 | 60 | }] |
705f6f35 JMF |
61 | |
62 | def _real_extract(self, url): | |
382e05fa | 63 | video_id = self._match_id(url) |
1c112040 | 64 | |
2da67107 | 65 | webpage = self._download_webpage(url, video_id) |
1c112040 | 66 | |
9c2aaac2 | 67 | wat_id = None |
1c112040 S |
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: | |
9c2aaac2 | 87 | wat_id = self._html_search_regex( |
1c112040 S |
88 | (r'(["\'])(?:https?:)?//www\.wat\.tv/embedframe/.*?(?P<id>\d{8})\1', |
89 | r'(["\']?)streamId\1\s*:\s*(["\']?)(?P<id>\d+)\2'), | |
9c2aaac2 | 90 | webpage, 'wat id', group='id') |
1c112040 | 91 | |
6212bcb1 | 92 | return self.url_result('wat:%s' % wat_id, 'Wat') |