]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import unified_strdate | |
3 | ||
4 | ||
5 | class InaIE(InfoExtractor): | |
6 | _VALID_URL = r'https?://(?:(?:www|m)\.)?ina\.fr/(?:[^?#]+/)(?P<id>[\w-]+)' | |
7 | _TESTS = [{ | |
8 | 'url': 'https://www.ina.fr/video/I12055569/francois-hollande-je-crois-que-c-est-clair-video.html', | |
9 | 'md5': 'c5a09e5cb5604ed10709f06e7a377dda', | |
10 | 'info_dict': { | |
11 | 'id': 'I12055569', | |
12 | 'ext': 'mp4', | |
13 | 'title': 'François Hollande "Je crois que c\'est clair"', | |
14 | 'description': 'md5:19f61e2b4844ed4bb2e3df9ab9f527ff', | |
15 | 'upload_date': '20070712', | |
16 | 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/3c4/I12055569.jpeg', | |
17 | } | |
18 | }, { | |
19 | 'url': 'https://www.ina.fr/video/S806544_001/don-d-organes-des-avancees-mais-d-importants-besoins-video.html', | |
20 | 'only_matching': True, | |
21 | }, { | |
22 | 'url': 'https://www.ina.fr/audio/P16173408', | |
23 | 'only_matching': True, | |
24 | }, { | |
25 | 'url': 'https://www.ina.fr/video/P16173408-video.html', | |
26 | 'only_matching': True, | |
27 | }, { | |
28 | 'url': 'http://m.ina.fr/video/I12055569', | |
29 | 'only_matching': True, | |
30 | }, { | |
31 | 'url': 'https://www.ina.fr/ina-eclaire-actu/video/cpb8205116303/les-jeux-electroniques', | |
32 | 'md5': '4b8284a9a3a184fdc7e744225b8251e7', | |
33 | 'info_dict': { | |
34 | 'id': 'CPB8205116303', | |
35 | 'ext': 'mp4', | |
36 | 'title': 'Les jeux électroniques', | |
37 | 'description': 'md5:e09f7683dad1cc60b74950490127d233', | |
38 | 'upload_date': '19821204', | |
39 | 'duration': 657, | |
40 | 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/203/CPB8205116303.jpeg', | |
41 | }, | |
42 | }, { | |
43 | 'url': 'https://www.ina.fr/ina-eclaire-actu/arletty-carriere-conseils-actrice-marcel-carne', | |
44 | 'md5': '743d6f069a00e19dda0da166a54eeccb', | |
45 | 'info_dict': { | |
46 | 'id': 'I22203233', | |
47 | 'ext': 'mp4', | |
48 | 'title': 'Arletty sur le métier d\'actrice', | |
49 | 'description': 'md5:3d89b5e419d8514c934f146045ccdbad', | |
50 | 'upload_date': '19581128', | |
51 | 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/082/I22203233.jpeg', | |
52 | }, | |
53 | }, { | |
54 | 'url': 'https://www.ina.fr/ina-eclaire-actu/chasse-croise-sncf-gare-d-austerlitz-vacances-d-ete', | |
55 | 'md5': 'a96fb85e9ba3b5c5b2eeb0c5daa55f2f', | |
56 | 'info_dict': { | |
57 | 'id': 'CAF91038285', | |
58 | 'ext': 'mp4', | |
59 | 'title': 'Les grands départs : les trains', | |
60 | 'description': 'md5:1630ee819d8d4da97df53459e99f72bb', | |
61 | 'upload_date': '19740801', | |
62 | 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/2cf/CAF91038285.jpeg', | |
63 | }, | |
64 | }] | |
65 | ||
66 | def _real_extract(self, url): | |
67 | display_id = self._match_id(url) | |
68 | webpage = self._download_webpage(url, display_id) | |
69 | ||
70 | api_url = self._html_search_regex(r'asset-details-url\s*=\s*["\'](?P<api_url>[^"\']+)', webpage, 'api_url') | |
71 | asset_id = self._search_regex(r'assets/([^?/]+)', api_url, 'asset_id') | |
72 | ||
73 | api_response = self._download_json(api_url.replace(asset_id, f'{asset_id}.json'), asset_id) | |
74 | ||
75 | return { | |
76 | 'id': asset_id, | |
77 | 'url': api_response['resourceUrl'], | |
78 | 'ext': {'video': 'mp4', 'audio': 'mp3'}.get(api_response.get('type')), | |
79 | 'title': api_response.get('title'), | |
80 | 'description': api_response.get('description'), | |
81 | 'upload_date': unified_strdate(api_response.get('dateOfBroadcast')), | |
82 | 'duration': api_response.get('duration'), | |
83 | 'thumbnail': api_response.get('resourceThumbnail'), | |
84 | } |