]>
Commit | Line | Data |
---|---|---|
8244288d | 1 | # coding: utf-8 |
e7916255 | 2 | from __future__ import unicode_literals |
8244288d | 3 | |
99afb3dd | 4 | from .common import InfoExtractor |
c5f51551 | 5 | from ..compat import compat_str |
86916dae | 6 | from ..utils import ( |
7c60c33e | 7 | ExtractorError, |
57ce8a6d | 8 | int_or_none, |
7c60c33e | 9 | try_get, |
10 | unified_strdate, | |
86916dae | 11 | ) |
99afb3dd JMF |
12 | |
13 | ||
14 | class WatIE(InfoExtractor): | |
c5f51551 | 15 | _VALID_URL = r'(?:wat:|https?://(?:www\.)?wat\.tv/video/.*-)(?P<id>[0-9a-z]+)' |
99afb3dd | 16 | IE_NAME = 'wat.tv' |
c28df247 S |
17 | _TESTS = [ |
18 | { | |
19 | 'url': 'http://www.wat.tv/video/soupe-figues-l-orange-aux-epices-6z1uz_2hvf7_.html', | |
c28df247 S |
20 | 'info_dict': { |
21 | 'id': '11713067', | |
c28df247 S |
22 | 'ext': 'mp4', |
23 | 'title': 'Soupe de figues à l\'orange et aux épices', | |
24 | 'description': 'Retrouvez l\'émission "Petits plats en équilibre", diffusée le 18 août 2014.', | |
25 | 'upload_date': '20140819', | |
26 | 'duration': 120, | |
27 | }, | |
0adf213d RA |
28 | 'params': { |
29 | # m3u8 download | |
30 | 'skip_download': True, | |
31 | }, | |
32 | 'expected_warnings': ['HTTP Error 404'], | |
7c60c33e | 33 | 'skip': 'This content is no longer available', |
c28df247 S |
34 | }, |
35 | { | |
36 | 'url': 'http://www.wat.tv/video/gregory-lemarchal-voix-ange-6z1v7_6ygkj_.html', | |
0adf213d | 37 | 'md5': 'b16574df2c3cd1a36ca0098f2a791925', |
c28df247 S |
38 | 'info_dict': { |
39 | 'id': '11713075', | |
c28df247 S |
40 | 'ext': 'mp4', |
41 | 'title': 'Grégory Lemarchal, une voix d\'ange depuis 10 ans (1/3)', | |
c28df247 | 42 | 'upload_date': '20140816', |
c28df247 | 43 | }, |
57ce8a6d | 44 | 'expected_warnings': ["Ce contenu n'est pas disponible pour l'instant."], |
7c60c33e | 45 | 'skip': 'This content is no longer available', |
fa800269 | 46 | }, |
c28df247 | 47 | ] |
7c60c33e | 48 | _GEO_BYPASS = False |
e7916255 | 49 | |
99afb3dd | 50 | def _real_extract(self, url): |
c5f51551 | 51 | video_id = self._match_id(url) |
52 | video_id = video_id if video_id.isdigit() and len(video_id) > 6 else compat_str(int(video_id, 36)) | |
8244288d | 53 | |
c5f51551 | 54 | # 'contentv4' is used in the website, but it also returns the related |
55 | # videos, we don't need them | |
7c60c33e | 56 | # video_data = self._download_json( |
57 | # 'http://www.wat.tv/interface/contentv4s/' + video_id, video_id) | |
57ce8a6d | 58 | video_data = self._download_json( |
7c60c33e | 59 | 'https://mediainfo.tf1.fr/mediainfocombo/' + video_id, |
60 | video_id, query={'context': 'MYTF1'}) | |
57ce8a6d | 61 | video_info = video_data['media'] |
a54bda3a | 62 | |
86916dae S |
63 | error_desc = video_info.get('error_desc') |
64 | if error_desc: | |
7c60c33e | 65 | if video_info.get('error_code') == 'GEOBLOCKED': |
66 | self.raise_geo_restricted(error_desc, video_info.get('geoList')) | |
67 | raise ExtractorError(error_desc, expected=True) | |
99afb3dd | 68 | |
7c60c33e | 69 | title = video_info['title'] |
8244288d | 70 | |
7c60c33e | 71 | formats = [] |
ec4f374c | 72 | subtitles = {} |
c5f51551 | 73 | |
7c60c33e | 74 | def extract_formats(manifest_urls): |
75 | for f, f_url in manifest_urls.items(): | |
76 | if not f_url: | |
77 | continue | |
78 | if f in ('dash', 'mpd'): | |
ec4f374c | 79 | fmts, subs = self._extract_mpd_formats_and_subtitles( |
7c60c33e | 80 | f_url.replace('://das-q1.tf1.fr/', '://das-q1-ssl.tf1.fr/'), |
ec4f374c | 81 | video_id, mpd_id='dash', fatal=False) |
7c60c33e | 82 | elif f == 'hls': |
ec4f374c | 83 | fmts, subs = self._extract_m3u8_formats_and_subtitles( |
7c60c33e | 84 | f_url, video_id, 'mp4', |
ec4f374c F |
85 | 'm3u8_native', m3u8_id='hls', fatal=False) |
86 | else: | |
87 | continue | |
88 | formats.extend(fmts) | |
89 | self._merge_subtitles(subs, target=subtitles) | |
c5f51551 | 90 | |
7c60c33e | 91 | delivery = video_data.get('delivery') or {} |
92 | extract_formats({delivery.get('format'): delivery.get('url')}) | |
93 | if not formats: | |
94 | if delivery.get('drm'): | |
b7da73eb | 95 | self.raise_no_formats('This video is DRM protected.', expected=True) |
7c60c33e | 96 | manifest_urls = self._download_json( |
97 | 'http://www.wat.tv/get/webhtml/' + video_id, video_id, fatal=False) | |
98 | if manifest_urls: | |
99 | extract_formats(manifest_urls) | |
948cd5b7 | 100 | |
a820dc72 | 101 | self._sort_formats(formats) |
57ce8a6d | 102 | |
e7916255 | 103 | return { |
c5f51551 | 104 | 'id': video_id, |
57ce8a6d | 105 | 'title': title, |
7c60c33e | 106 | 'thumbnail': video_info.get('preview'), |
107 | 'upload_date': unified_strdate(try_get( | |
108 | video_data, lambda x: x['mediametrie']['chapters'][0]['estatS4'])), | |
109 | 'duration': int_or_none(video_info.get('duration')), | |
a54bda3a | 110 | 'formats': formats, |
ec4f374c | 111 | 'subtitles': subtitles, |
e7916255 | 112 | } |