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