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