]>
Commit | Line | Data |
---|---|---|
8244288d | 1 | # coding: utf-8 |
e7916255 | 2 | from __future__ import unicode_literals |
8244288d | 3 | |
99afb3dd JMF |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
c5f51551 | 7 | from ..compat import compat_str |
86916dae S |
8 | from ..utils import ( |
9 | ExtractorError, | |
10 | unified_strdate, | |
c5f51551 | 11 | HEADRequest, |
12 | float_or_none, | |
86916dae | 13 | ) |
99afb3dd JMF |
14 | |
15 | ||
16 | class WatIE(InfoExtractor): | |
c5f51551 | 17 | _VALID_URL = r'(?:wat:|https?://(?:www\.)?wat\.tv/video/.*-)(?P<id>[0-9a-z]+)' |
99afb3dd | 18 | IE_NAME = 'wat.tv' |
c28df247 S |
19 | _TESTS = [ |
20 | { | |
21 | 'url': 'http://www.wat.tv/video/soupe-figues-l-orange-aux-epices-6z1uz_2hvf7_.html', | |
c5f51551 | 22 | 'md5': '83d882d9de5c9d97f0bb2c6273cde56a', |
c28df247 S |
23 | 'info_dict': { |
24 | 'id': '11713067', | |
c28df247 S |
25 | 'ext': 'mp4', |
26 | 'title': 'Soupe de figues à l\'orange et aux épices', | |
27 | 'description': 'Retrouvez l\'émission "Petits plats en équilibre", diffusée le 18 août 2014.', | |
28 | 'upload_date': '20140819', | |
29 | 'duration': 120, | |
30 | }, | |
31 | }, | |
32 | { | |
33 | 'url': 'http://www.wat.tv/video/gregory-lemarchal-voix-ange-6z1v7_6ygkj_.html', | |
34 | 'md5': 'fbc84e4378165278e743956d9c1bf16b', | |
35 | 'info_dict': { | |
36 | 'id': '11713075', | |
c28df247 S |
37 | 'ext': 'mp4', |
38 | 'title': 'Grégory Lemarchal, une voix d\'ange depuis 10 ans (1/3)', | |
39 | 'description': 'md5:b7a849cf16a2b733d9cd10c52906dee3', | |
40 | 'upload_date': '20140816', | |
41 | 'duration': 2910, | |
42 | }, | |
54e9a4af | 43 | 'skip': "Ce contenu n'est pas disponible pour l'instant.", |
fa800269 | 44 | }, |
c28df247 | 45 | ] |
e7916255 | 46 | |
99afb3dd | 47 | def _real_extract(self, url): |
c5f51551 | 48 | video_id = self._match_id(url) |
49 | video_id = video_id if video_id.isdigit() and len(video_id) > 6 else compat_str(int(video_id, 36)) | |
8244288d | 50 | |
c5f51551 | 51 | # 'contentv4' is used in the website, but it also returns the related |
52 | # videos, we don't need them | |
53 | video_info = self._download_json( | |
54 | 'http://www.wat.tv/interface/contentv3/' + video_id, video_id)['media'] | |
a54bda3a | 55 | |
86916dae S |
56 | error_desc = video_info.get('error_desc') |
57 | if error_desc: | |
58 | raise ExtractorError( | |
59 | '%s returned error: %s' % (self.IE_NAME, error_desc), expected=True) | |
60 | ||
8244288d JMF |
61 | chapters = video_info['chapters'] |
62 | first_chapter = chapters[0] | |
99afb3dd | 63 | |
c5f51551 | 64 | def video_id_for_chapter(chapter): |
65 | return chapter['tc_start'].split('-')[0] | |
8244288d | 66 | |
c5f51551 | 67 | if video_id_for_chapter(first_chapter) != video_id: |
68 | self.to_screen('Multipart video detected') | |
69 | entries = [self.url_result('wat:%s' % video_id_for_chapter(chapter)) for chapter in chapters] | |
70 | return self.playlist_result(entries, video_id, video_info['title']) | |
8244288d | 71 | # Otherwise we can continue and extract just one part, we have to use |
c5f51551 | 72 | # the video id for getting the video url |
73 | ||
74 | date_diffusion = first_chapter.get('date_diffusion') | |
75 | upload_date = unified_strdate(date_diffusion) if date_diffusion else None | |
76 | ||
77 | def extract_url(path_template, url_type): | |
78 | req_url = 'http://www.wat.tv/get/%s' % (path_template % video_id) | |
79 | head = self._request_webpage(HEADRequest(req_url), video_id, 'Extracting %s url' % url_type) | |
80 | red_url = head.geturl() | |
81 | if req_url == red_url: | |
82 | raise ExtractorError( | |
83 | '%s said: Sorry, this video is not available from your country.' % self.IE_NAME, | |
84 | expected=True) | |
85 | return red_url | |
86 | ||
87 | m3u8_url = extract_url('ipad/%s.m3u8', 'm3u8') | |
88 | http_url = extract_url('android5/%s.mp4', 'http') | |
89 | ||
90 | formats = [] | |
91 | m3u8_formats = self._extract_m3u8_formats( | |
92 | m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls') | |
93 | formats.extend(m3u8_formats) | |
94 | formats.extend(self._extract_f4m_formats( | |
95 | m3u8_url.replace('ios.', 'web.').replace('.m3u8', '.f4m'), | |
96 | video_id, f4m_id='hds', fatal=False)) | |
97 | for m3u8_format in m3u8_formats: | |
98 | mobj = re.search( | |
99 | r'audio.*?%3D(\d+)(?:-video.*?%3D(\d+))?', m3u8_format['url']) | |
100 | if not mobj: | |
a54bda3a | 101 | continue |
c5f51551 | 102 | abr, vbr = mobj.groups() |
103 | abr, vbr = float_or_none(abr, 1000), float_or_none(vbr, 1000) | |
104 | m3u8_format.update({ | |
105 | 'vbr': vbr, | |
106 | 'abr': abr, | |
107 | }) | |
108 | if not vbr or not abr: | |
109 | continue | |
110 | f = m3u8_format.copy() | |
111 | f.update({ | |
112 | 'url': re.sub(r'%s-\d+00-\d+' % video_id, '%s-%d00-%d' % (video_id, round(vbr / 100), round(abr)), http_url), | |
113 | 'format_id': f['format_id'].replace('hls', 'http'), | |
114 | 'protocol': 'http', | |
a54bda3a | 115 | }) |
c5f51551 | 116 | formats.append(f) |
117 | self._sort_formats(formats) | |
a54bda3a | 118 | |
e7916255 | 119 | return { |
c5f51551 | 120 | 'id': video_id, |
e7916255 JMF |
121 | 'title': first_chapter['title'], |
122 | 'thumbnail': first_chapter['preview'], | |
123 | 'description': first_chapter['description'], | |
124 | 'view_count': video_info['views'], | |
125 | 'upload_date': upload_date, | |
c5f51551 | 126 | 'duration': video_info['files'][0]['duration'], |
a54bda3a | 127 | 'formats': formats, |
e7916255 | 128 | } |