]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/allocine.py
[ign] Fix extraction of video in articles
[youtube-dl.git] / 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 ..utils import (
9     compat_str,
10     qualities,
11     determine_ext,
12 )
13
14
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=)(?P<id>[0-9]+)(?:\.html)?'
17
18     _TESTS = [{
19         'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
20         'md5': '0c9fcf59a841f65635fa300ac43d8269',
21         'info_dict': {
22             'id': '19546517',
23             'ext': 'mp4',
24             'title': 'Astérix - Le Domaine des Dieux Teaser VF',
25             'description': 'md5:4a754271d9c6f16c72629a8a993ee884',
26             'thumbnail': 're:http://.*\.jpg',
27         },
28     }, {
29         'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html',
30         'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0',
31         'info_dict': {
32             'id': '19540403',
33             'ext': 'mp4',
34             'title': 'Planes 2 Bande-annonce VF',
35             'description': 'md5:eeaffe7c2d634525e21159b93acf3b1e',
36             'thumbnail': 're:http://.*\.jpg',
37         },
38     }, {
39         'url': 'http://www.allocine.fr/film/fichefilm_gen_cfilm=181290.html',
40         'md5': '101250fb127ef9ca3d73186ff22a47ce',
41         'info_dict': {
42             'id': '19544709',
43             'ext': 'mp4',
44             'title': 'Dragons 2 - Bande annonce finale VF',
45             'description': 'md5:71742e3a74b0d692c7fce0dd2017a4ac',
46             'thumbnail': 're:http://.*\.jpg',
47         },
48     }]
49
50     def _real_extract(self, url):
51         mobj = re.match(self._VALID_URL, url)
52         typ = mobj.group('typ')
53         display_id = mobj.group('id')
54
55         webpage = self._download_webpage(url, display_id)
56
57         if typ == 'film':
58             video_id = self._search_regex(r'href="/video/player_gen_cmedia=([0-9]+).+"', webpage, 'video id')
59         else:
60             player = self._search_regex(r'data-player=\'([^\']+)\'>', webpage, 'data player')
61
62             player_data = json.loads(player)
63             video_id = compat_str(player_data['refMedia'])
64
65         xml = self._download_xml('http://www.allocine.fr/ws/AcVisiondataV4.ashx?media=%s' % video_id, display_id)
66
67         video = xml.find('.//AcVisionVideo').attrib
68         quality = qualities(['ld', 'md', 'hd'])
69
70         formats = []
71         for k, v in video.items():
72             if re.match(r'.+_path', k):
73                 format_id = k.split('_')[0]
74                 formats.append({
75                     'format_id': format_id,
76                     'quality': quality(format_id),
77                     'url': v,
78                     'ext': determine_ext(v),
79                 })
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         }