]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/allocine.py
Update changelog
[youtubedl] / youtube_dl / extractor / allocine.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 remove_end,
7 qualities,
8 url_basename,
9 )
10
11
12 class AllocineIE(InfoExtractor):
13 _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)?'
14
15 _TESTS = [{
16 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
17 'md5': '0c9fcf59a841f65635fa300ac43d8269',
18 'info_dict': {
19 'id': '19546517',
20 'display_id': '18635087',
21 'ext': 'mp4',
22 'title': 'Astérix - Le Domaine des Dieux Teaser VF',
23 'description': 'md5:4a754271d9c6f16c72629a8a993ee884',
24 'thumbnail': 're:http://.*\.jpg',
25 },
26 }, {
27 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html',
28 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0',
29 'info_dict': {
30 'id': '19540403',
31 'display_id': '19540403',
32 'ext': 'mp4',
33 'title': 'Planes 2 Bande-annonce VF',
34 'description': 'Regardez la bande annonce du film Planes 2 (Planes 2 Bande-annonce VF). Planes 2, un film de Roberts Gannaway',
35 'thumbnail': 're:http://.*\.jpg',
36 },
37 }, {
38 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19544709&cfilm=181290.html',
39 'md5': '101250fb127ef9ca3d73186ff22a47ce',
40 'info_dict': {
41 'id': '19544709',
42 'display_id': '19544709',
43 'ext': 'mp4',
44 'title': 'Dragons 2 - Bande annonce finale VF',
45 'description': 'md5:6cdd2d7c2687d4c6aafe80a35e17267a',
46 'thumbnail': 're:http://.*\.jpg',
47 },
48 }, {
49 'url': 'http://www.allocine.fr/video/video-19550147/',
50 'md5': '3566c0668c0235e2d224fd8edb389f67',
51 'info_dict': {
52 'id': '19550147',
53 'ext': 'mp4',
54 'title': 'Faux Raccord N°123 - Les gaffes de Cliffhanger',
55 'description': 'md5:bc734b83ffa2d8a12188d9eb48bb6354',
56 'thumbnail': 're:http://.*\.jpg',
57 },
58 }]
59
60 def _real_extract(self, url):
61 display_id = self._match_id(url)
62
63 webpage = self._download_webpage(url, display_id)
64
65 formats = []
66 quality = qualities(['ld', 'md', 'hd'])
67
68 model = self._html_search_regex(
69 r'data-model="([^"]+)"', webpage, 'data model', default=None)
70 if model:
71 model_data = self._parse_json(model, display_id)
72
73 for video_url in model_data['sources'].values():
74 video_id, format_id = url_basename(video_url).split('_')[:2]
75 formats.append({
76 'format_id': format_id,
77 'quality': quality(format_id),
78 'url': video_url,
79 })
80
81 title = model_data['title']
82 else:
83 video_id = display_id
84 media_data = self._download_json(
85 'http://www.allocine.fr/ws/AcVisiondataV5.ashx?media=%s' % video_id, display_id)
86 for key, value in media_data['video'].items():
87 if not key.endswith('Path'):
88 continue
89
90 format_id = key[:-len('Path')]
91 formats.append({
92 'format_id': format_id,
93 'quality': quality(format_id),
94 'url': value,
95 })
96
97 title = remove_end(self._html_search_regex(
98 r'(?s)<title>(.+?)</title>', webpage, 'title'
99 ).strip(), ' - AlloCiné')
100
101 self._sort_formats(formats)
102
103 return {
104 'id': video_id,
105 'display_id': display_id,
106 'title': title,
107 'thumbnail': self._og_search_thumbnail(webpage),
108 'formats': formats,
109 'description': self._og_search_description(webpage),
110 }