]>
Commit | Line | Data |
---|---|---|
93ad6c6b RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
b9c9cb5f | 5 | from ..compat import compat_str |
93ad6c6b | 6 | from ..utils import ( |
ab49d7a9 | 7 | determine_ext, |
b9c9cb5f S |
8 | int_or_none, |
9 | try_get, | |
10 | qualities, | |
93ad6c6b RA |
11 | ) |
12 | ||
13 | ||
14 | class SixPlayIE(InfoExtractor): | |
15 | _VALID_URL = r'(?:6play:|https?://(?:www\.)?6play\.fr/.+?-c_)(?P<id>[0-9]+)' | |
16 | _TEST = { | |
b9c9cb5f | 17 | 'url': 'http://www.6play.fr/le-meilleur-patissier-p_1807/le-meilleur-patissier-special-fetes-mercredi-a-21-00-sur-m6-c_11638450', |
93ad6c6b RA |
18 | 'md5': '42310bffe4ba3982db112b9cd3467328', |
19 | 'info_dict': { | |
b9c9cb5f | 20 | 'id': '11638450', |
93ad6c6b | 21 | 'ext': 'mp4', |
b9c9cb5f S |
22 | 'title': 'Le Meilleur Pâtissier, spécial fêtes mercredi à 21:00 sur M6', |
23 | 'description': 'md5:308853f6a5f9e2d55a30fc0654de415f', | |
24 | 'duration': 39, | |
25 | 'series': 'Le meilleur pâtissier', | |
26 | }, | |
27 | 'params': { | |
28 | 'skip_download': True, | |
93ad6c6b RA |
29 | }, |
30 | } | |
31 | ||
32 | def _real_extract(self, url): | |
33 | video_id = self._match_id(url) | |
b9c9cb5f S |
34 | |
35 | data = self._download_json( | |
36 | 'https://pc.middleware.6play.fr/6play/v2/platforms/m6group_web/services/6play/videos/clip_%s' % video_id, | |
37 | video_id, query={ | |
38 | 'csa': 5, | |
39 | 'with': 'clips', | |
40 | }) | |
41 | ||
42 | clip_data = data['clips'][0] | |
43 | title = clip_data['title'] | |
93ad6c6b | 44 | |
0c2ac64b | 45 | quality_key = qualities(['lq', 'sd', 'hq', 'hd']) |
93ad6c6b | 46 | formats = [] |
b9c9cb5f S |
47 | for asset in clip_data['assets']: |
48 | asset_url = asset.get('full_physical_path') | |
49 | if not asset_url: | |
93ad6c6b | 50 | continue |
b9c9cb5f S |
51 | container = asset.get('video_container') |
52 | ext = determine_ext(asset_url) | |
53 | if container == 'm3u8' or ext == 'm3u8': | |
93ad6c6b | 54 | formats.extend(self._extract_m3u8_formats( |
b9c9cb5f | 55 | asset_url, video_id, 'mp4', 'm3u8_native', |
93ad6c6b RA |
56 | m3u8_id='hls', fatal=False)) |
57 | formats.extend(self._extract_f4m_formats( | |
b9c9cb5f | 58 | asset_url.replace('.m3u8', '.f4m'), |
93ad6c6b | 59 | video_id, f4m_id='hds', fatal=False)) |
b9c9cb5f S |
60 | elif container == 'mp4' or ext == 'mp4': |
61 | quality = asset.get('video_quality') | |
93ad6c6b | 62 | formats.append({ |
b9c9cb5f | 63 | 'url': asset_url, |
93ad6c6b | 64 | 'format_id': quality, |
0c2ac64b | 65 | 'quality': quality_key(quality), |
ab49d7a9 | 66 | 'ext': ext, |
93ad6c6b RA |
67 | }) |
68 | self._sort_formats(formats) | |
69 | ||
b9c9cb5f S |
70 | def get(getter): |
71 | for src in (data, clip_data): | |
72 | v = try_get(src, getter, compat_str) | |
73 | if v: | |
74 | return v | |
75 | ||
93ad6c6b RA |
76 | return { |
77 | 'id': video_id, | |
b9c9cb5f S |
78 | 'title': title, |
79 | 'description': get(lambda x: x['description']), | |
80 | 'duration': int_or_none(clip_data.get('duration')), | |
81 | 'series': get(lambda x: x['program']['title']), | |
93ad6c6b RA |
82 | 'formats': formats, |
83 | } |