]>
Commit | Line | Data |
---|---|---|
49cbe7c8 PP |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
639e5b2a | 3 | int_or_none, |
49cbe7c8 | 4 | qualities, |
639e5b2a | 5 | remove_end, |
04f3fd2c | 6 | strip_or_none, |
639e5b2a S |
7 | try_get, |
8 | unified_timestamp, | |
65f4c1de | 9 | url_basename, |
49cbe7c8 PP |
10 | ) |
11 | ||
12 | ||
13 | class AllocineIE(InfoExtractor): | |
65f4c1de | 14 | _VALID_URL = r'https?://(?:www\.)?allocine\.fr/(?:article|video|film)/(?:fichearticle_gen_carticle=|player_gen_cmedia=|fichefilm_gen_cfilm=|video-)(?P<id>[0-9]+)(?:\.html)?' |
49cbe7c8 PP |
15 | |
16 | _TESTS = [{ | |
17 | 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html', | |
18 | 'md5': '0c9fcf59a841f65635fa300ac43d8269', | |
19 | 'info_dict': { | |
20 | 'id': '19546517', | |
65f4c1de | 21 | 'display_id': '18635087', |
49cbe7c8 PP |
22 | 'ext': 'mp4', |
23 | 'title': 'Astérix - Le Domaine des Dieux Teaser VF', | |
65f4c1de | 24 | 'description': 'md5:4a754271d9c6f16c72629a8a993ee884', |
ec85ded8 | 25 | 'thumbnail': r're:http://.*\.jpg', |
639e5b2a S |
26 | 'duration': 39, |
27 | 'timestamp': 1404273600, | |
28 | 'upload_date': '20140702', | |
29 | 'view_count': int, | |
49cbe7c8 PP |
30 | }, |
31 | }, { | |
32 | 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html', | |
33 | 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0', | |
34 | 'info_dict': { | |
35 | 'id': '19540403', | |
65f4c1de | 36 | 'display_id': '19540403', |
49cbe7c8 PP |
37 | 'ext': 'mp4', |
38 | 'title': 'Planes 2 Bande-annonce VF', | |
7a0ed069 | 39 | 'description': 'Regardez la bande annonce du film Planes 2 (Planes 2 Bande-annonce VF). Planes 2, un film de Roberts Gannaway', |
ec85ded8 | 40 | 'thumbnail': r're:http://.*\.jpg', |
639e5b2a S |
41 | 'duration': 69, |
42 | 'timestamp': 1385659800, | |
43 | 'upload_date': '20131128', | |
44 | 'view_count': int, | |
49cbe7c8 PP |
45 | }, |
46 | }, { | |
65f4c1de | 47 | 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19544709&cfilm=181290.html', |
49cbe7c8 PP |
48 | 'md5': '101250fb127ef9ca3d73186ff22a47ce', |
49 | 'info_dict': { | |
50 | 'id': '19544709', | |
65f4c1de | 51 | 'display_id': '19544709', |
49cbe7c8 PP |
52 | 'ext': 'mp4', |
53 | 'title': 'Dragons 2 - Bande annonce finale VF', | |
65f4c1de | 54 | 'description': 'md5:6cdd2d7c2687d4c6aafe80a35e17267a', |
ec85ded8 | 55 | 'thumbnail': r're:http://.*\.jpg', |
639e5b2a S |
56 | 'duration': 144, |
57 | 'timestamp': 1397589900, | |
58 | 'upload_date': '20140415', | |
59 | 'view_count': int, | |
49cbe7c8 | 60 | }, |
9209fe38 S |
61 | }, { |
62 | 'url': 'http://www.allocine.fr/video/video-19550147/', | |
176006a1 YCH |
63 | 'md5': '3566c0668c0235e2d224fd8edb389f67', |
64 | 'info_dict': { | |
65 | 'id': '19550147', | |
66 | 'ext': 'mp4', | |
67 | 'title': 'Faux Raccord N°123 - Les gaffes de Cliffhanger', | |
68 | 'description': 'md5:bc734b83ffa2d8a12188d9eb48bb6354', | |
ec85ded8 | 69 | 'thumbnail': r're:http://.*\.jpg', |
176006a1 | 70 | }, |
49cbe7c8 PP |
71 | }] |
72 | ||
73 | def _real_extract(self, url): | |
65f4c1de | 74 | display_id = self._match_id(url) |
49cbe7c8 PP |
75 | |
76 | webpage = self._download_webpage(url, display_id) | |
77 | ||
176006a1 YCH |
78 | formats = [] |
79 | quality = qualities(['ld', 'md', 'hd']) | |
80 | ||
65f4c1de | 81 | model = self._html_search_regex( |
176006a1 YCH |
82 | r'data-model="([^"]+)"', webpage, 'data model', default=None) |
83 | if model: | |
84 | model_data = self._parse_json(model, display_id) | |
639e5b2a S |
85 | video = model_data['videos'][0] |
86 | title = video['title'] | |
87 | for video_url in video['sources'].values(): | |
176006a1 YCH |
88 | video_id, format_id = url_basename(video_url).split('_')[:2] |
89 | formats.append({ | |
90 | 'format_id': format_id, | |
91 | 'quality': quality(format_id), | |
92 | 'url': video_url, | |
93 | }) | |
639e5b2a S |
94 | duration = int_or_none(video.get('duration')) |
95 | view_count = int_or_none(video.get('view_count')) | |
96 | timestamp = unified_timestamp(try_get( | |
add96eb9 | 97 | video, lambda x: x['added_at']['date'], str)) |
176006a1 YCH |
98 | else: |
99 | video_id = display_id | |
100 | media_data = self._download_json( | |
add96eb9 | 101 | f'http://www.allocine.fr/ws/AcVisiondataV5.ashx?media={video_id}', display_id) |
04f3fd2c | 102 | title = remove_end(strip_or_none(self._html_extract_title(webpage), ' - AlloCiné')) |
176006a1 YCH |
103 | for key, value in media_data['video'].items(): |
104 | if not key.endswith('Path'): | |
105 | continue | |
176006a1 YCH |
106 | format_id = key[:-len('Path')] |
107 | formats.append({ | |
108 | 'format_id': format_id, | |
109 | 'quality': quality(format_id), | |
110 | 'url': value, | |
111 | }) | |
639e5b2a | 112 | duration, view_count, timestamp = [None] * 3 |
49cbe7c8 | 113 | |
49cbe7c8 PP |
114 | return { |
115 | 'id': video_id, | |
65f4c1de | 116 | 'display_id': display_id, |
176006a1 | 117 | 'title': title, |
639e5b2a | 118 | 'description': self._og_search_description(webpage), |
49cbe7c8 | 119 | 'thumbnail': self._og_search_thumbnail(webpage), |
639e5b2a S |
120 | 'duration': duration, |
121 | 'timestamp': timestamp, | |
122 | 'view_count': view_count, | |
49cbe7c8 | 123 | 'formats': formats, |
49cbe7c8 | 124 | } |