]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/allocine.py
Imported Upstream version 2015.11.10
[youtubedl] / youtube_dl / extractor / allocine.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5 import json
6
7 from .common import InfoExtractor
8 from ..compat import compat_str
9 from ..utils import (
10 qualities,
11 )
12
13
14 class AllocineIE(InfoExtractor):
15 _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)?'
16
17 _TESTS = [{
18 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
19 'md5': '0c9fcf59a841f65635fa300ac43d8269',
20 'info_dict': {
21 'id': '19546517',
22 'ext': 'mp4',
23 'title': 'Astérix - Le Domaine des Dieux Teaser VF',
24 'description': 'md5:abcd09ce503c6560512c14ebfdb720d2',
25 'thumbnail': 're:http://.*\.jpg',
26 },
27 }, {
28 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html',
29 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0',
30 'info_dict': {
31 'id': '19540403',
32 'ext': 'mp4',
33 'title': 'Planes 2 Bande-annonce VF',
34 'description': 'md5:eeaffe7c2d634525e21159b93acf3b1e',
35 'thumbnail': 're:http://.*\.jpg',
36 },
37 }, {
38 'url': 'http://www.allocine.fr/film/fichefilm_gen_cfilm=181290.html',
39 'md5': '101250fb127ef9ca3d73186ff22a47ce',
40 'info_dict': {
41 'id': '19544709',
42 'ext': 'mp4',
43 'title': 'Dragons 2 - Bande annonce finale VF',
44 'description': 'md5:71742e3a74b0d692c7fce0dd2017a4ac',
45 'thumbnail': 're:http://.*\.jpg',
46 },
47 }, {
48 'url': 'http://www.allocine.fr/video/video-19550147/',
49 'only_matching': True,
50 }]
51
52 def _real_extract(self, url):
53 mobj = re.match(self._VALID_URL, url)
54 typ = mobj.group('typ')
55 display_id = mobj.group('id')
56
57 webpage = self._download_webpage(url, display_id)
58
59 if typ == 'film':
60 video_id = self._search_regex(r'href="/video/player_gen_cmedia=([0-9]+).+"', webpage, 'video id')
61 else:
62 player = self._search_regex(r'data-player=\'([^\']+)\'>', webpage, 'data player')
63
64 player_data = json.loads(player)
65 video_id = compat_str(player_data['refMedia'])
66
67 xml = self._download_xml('http://www.allocine.fr/ws/AcVisiondataV4.ashx?media=%s' % video_id, display_id)
68
69 video = xml.find('.//AcVisionVideo').attrib
70 quality = qualities(['ld', 'md', 'hd'])
71
72 formats = []
73 for k, v in video.items():
74 if re.match(r'.+_path', k):
75 format_id = k.split('_')[0]
76 formats.append({
77 'format_id': format_id,
78 'quality': quality(format_id),
79 'url': v,
80 })
81 self._sort_formats(formats)
82
83 return {
84 'id': video_id,
85 'title': video['videoTitle'],
86 'thumbnail': self._og_search_thumbnail(webpage),
87 'formats': formats,
88 'description': self._og_search_description(webpage),
89 }