1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
7 from .common import InfoExtractor
8 from ..compat import compat_str
15 class AllocineIE(InfoExtractor):
16 _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)?'
19 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
20 'md5': '0c9fcf59a841f65635fa300ac43d8269',
24 'title': 'Astérix - Le Domaine des Dieux Teaser VF',
25 'description': 'md5:abcd09ce503c6560512c14ebfdb720d2',
26 'thumbnail': 're:http://.*\.jpg',
29 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html',
30 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0',
34 'title': 'Planes 2 Bande-annonce VF',
35 'description': 'Regardez la bande annonce du film Planes 2 (Planes 2 Bande-annonce VF). Planes 2, un film de Roberts Gannaway',
36 'thumbnail': 're:http://.*\.jpg',
39 'url': 'http://www.allocine.fr/film/fichefilm_gen_cfilm=181290.html',
40 'md5': '101250fb127ef9ca3d73186ff22a47ce',
44 'title': 'Dragons 2 - Bande annonce finale VF',
45 'description': 'md5:601d15393ac40f249648ef000720e7e3',
46 'thumbnail': 're:http://.*\.jpg',
49 'url': 'http://www.allocine.fr/video/video-19550147/',
50 'only_matching': True,
53 def _real_extract(self, url):
54 mobj = re.match(self._VALID_URL, url)
55 typ = mobj.group('typ')
56 display_id = mobj.group('id')
58 webpage = self._download_webpage(url, display_id)
61 video_id = self._search_regex(r'href="/video/player_gen_cmedia=([0-9]+).+"', webpage, 'video id')
63 player = self._search_regex(r'data-player=\'([^\']+)\'>', webpage, 'data player', default=None)
65 player_data = json.loads(player)
66 video_id = compat_str(player_data['refMedia'])
68 model = self._search_regex(r'data-model="([^"]+)">', webpage, 'data model')
69 model_data = self._parse_json(unescapeHTML(model), display_id)
70 video_id = compat_str(model_data['id'])
72 xml = self._download_xml('http://www.allocine.fr/ws/AcVisiondataV4.ashx?media=%s' % video_id, display_id)
74 video = xml.find('./AcVisionVideo').attrib
75 quality = qualities(['ld', 'md', 'hd'])
78 for k, v in video.items():
79 if re.match(r'.+_path', k):
80 format_id = k.split('_')[0]
82 'format_id': format_id,
83 'quality': quality(format_id),
86 self._sort_formats(formats)
90 'title': video['videoTitle'],
91 'thumbnail': self._og_search_thumbnail(webpage),
93 'description': self._og_search_description(webpage),