]>
Commit | Line | Data |
---|---|---|
49cbe7c8 PP |
1 | # -*- coding: utf-8 -*- |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | import json | |
6 | ||
7 | from .common import InfoExtractor | |
1cc79574 | 8 | from ..compat import compat_str |
49cbe7c8 | 9 | from ..utils import ( |
49cbe7c8 | 10 | qualities, |
7a0ed069 | 11 | unescapeHTML, |
dc4fe5c6 | 12 | xpath_element, |
49cbe7c8 PP |
13 | ) |
14 | ||
15 | ||
16 | class AllocineIE(InfoExtractor): | |
0647084f | 17 | _VALID_URL = r'https?://(?:www\.)?allocine\.fr/(?P<typ>article|video|film)/(fichearticle_gen_carticle=|player_gen_cmedia=|fichefilm_gen_cfilm=|video-)(?P<id>[0-9]+)(?:\.html)?' |
49cbe7c8 PP |
18 | |
19 | _TESTS = [{ | |
20 | 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html', | |
21 | 'md5': '0c9fcf59a841f65635fa300ac43d8269', | |
22 | 'info_dict': { | |
23 | 'id': '19546517', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'Astérix - Le Domaine des Dieux Teaser VF', | |
9d2a4dae | 26 | 'description': 'md5:abcd09ce503c6560512c14ebfdb720d2', |
49cbe7c8 PP |
27 | 'thumbnail': 're:http://.*\.jpg', |
28 | }, | |
29 | }, { | |
30 | 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html', | |
31 | 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0', | |
32 | 'info_dict': { | |
33 | 'id': '19540403', | |
34 | 'ext': 'mp4', | |
35 | 'title': 'Planes 2 Bande-annonce VF', | |
7a0ed069 | 36 | 'description': 'Regardez la bande annonce du film Planes 2 (Planes 2 Bande-annonce VF). Planes 2, un film de Roberts Gannaway', |
49cbe7c8 PP |
37 | 'thumbnail': 're:http://.*\.jpg', |
38 | }, | |
39 | }, { | |
40 | 'url': 'http://www.allocine.fr/film/fichefilm_gen_cfilm=181290.html', | |
41 | 'md5': '101250fb127ef9ca3d73186ff22a47ce', | |
42 | 'info_dict': { | |
43 | 'id': '19544709', | |
44 | 'ext': 'mp4', | |
45 | 'title': 'Dragons 2 - Bande annonce finale VF', | |
7a0ed069 | 46 | 'description': 'md5:601d15393ac40f249648ef000720e7e3', |
49cbe7c8 PP |
47 | 'thumbnail': 're:http://.*\.jpg', |
48 | }, | |
9209fe38 S |
49 | }, { |
50 | 'url': 'http://www.allocine.fr/video/video-19550147/', | |
51 | 'only_matching': True, | |
49cbe7c8 PP |
52 | }] |
53 | ||
54 | def _real_extract(self, url): | |
55 | mobj = re.match(self._VALID_URL, url) | |
56 | typ = mobj.group('typ') | |
57 | display_id = mobj.group('id') | |
58 | ||
59 | webpage = self._download_webpage(url, display_id) | |
60 | ||
61 | if typ == 'film': | |
62 | video_id = self._search_regex(r'href="/video/player_gen_cmedia=([0-9]+).+"', webpage, 'video id') | |
63 | else: | |
7a0ed069 YCH |
64 | player = self._search_regex(r'data-player=\'([^\']+)\'>', webpage, 'data player', default=None) |
65 | if player: | |
66 | player_data = json.loads(player) | |
67 | video_id = compat_str(player_data['refMedia']) | |
68 | else: | |
69 | model = self._search_regex(r'data-model="([^"]+)">', webpage, 'data model') | |
70 | model_data = self._parse_json(unescapeHTML(model), display_id) | |
71 | video_id = compat_str(model_data['id']) | |
49cbe7c8 PP |
72 | |
73 | xml = self._download_xml('http://www.allocine.fr/ws/AcVisiondataV4.ashx?media=%s' % video_id, display_id) | |
74 | ||
dc4fe5c6 | 75 | video = xpath_element(xml, './/AcVisionVideo').attrib |
49cbe7c8 PP |
76 | quality = qualities(['ld', 'md', 'hd']) |
77 | ||
78 | formats = [] | |
79 | for k, v in video.items(): | |
80 | if re.match(r'.+_path', k): | |
81 | format_id = k.split('_')[0] | |
82 | formats.append({ | |
83 | 'format_id': format_id, | |
84 | 'quality': quality(format_id), | |
85 | 'url': v, | |
49cbe7c8 | 86 | }) |
49cbe7c8 PP |
87 | self._sort_formats(formats) |
88 | ||
89 | return { | |
90 | 'id': video_id, | |
91 | 'title': video['videoTitle'], | |
92 | 'thumbnail': self._og_search_thumbnail(webpage), | |
93 | 'formats': formats, | |
94 | 'description': self._og_search_description(webpage), | |
95 | } |