]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/jeuxvideo.py
update changelog.
[youtubedl] / youtube_dl / extractor / jeuxvideo.py
1 # coding: utf-8
2
3 import json
4 import re
5 import xml.etree.ElementTree
6
7 from .common import InfoExtractor
8
9
10 class JeuxVideoIE(InfoExtractor):
11 _VALID_URL = r'http://.*?\.jeuxvideo\.com/.*/(.*?)-\d+\.htm'
12
13 _TEST = {
14 u'url': u'http://www.jeuxvideo.com/reportages-videos-jeux/0004/00046170/tearaway-playstation-vita-gc-2013-tearaway-nous-presente-ses-papiers-d-identite-00115182.htm',
15 u'file': u'5182.mp4',
16 u'md5': u'046e491afb32a8aaac1f44dd4ddd54ee',
17 u'info_dict': {
18 u'title': u'GC 2013 : Tearaway nous présente ses papiers d\'identité',
19 u'description': u'Lorsque les développeurs de LittleBigPlanet proposent un nouveau titre, on ne peut que s\'attendre à un résultat original et fort attrayant.\n',
20 },
21 }
22
23 def _real_extract(self, url):
24 mobj = re.match(self._VALID_URL, url)
25 title = re.match(self._VALID_URL, url).group(1)
26 webpage = self._download_webpage(url, title)
27 xml_link = self._html_search_regex(
28 r'<param name="flashvars" value="config=(.*?)" />',
29 webpage, u'config URL')
30
31 video_id = self._search_regex(
32 r'http://www\.jeuxvideo\.com/config/\w+/\d+/(.*?)/\d+_player\.xml',
33 xml_link, u'video ID')
34
35 xml_config = self._download_webpage(
36 xml_link, title, u'Downloading XML config')
37 config = xml.etree.ElementTree.fromstring(xml_config.encode('utf-8'))
38 info_json = self._search_regex(
39 r'(?sm)<format\.json>(.*?)</format\.json>',
40 xml_config, u'JSON information')
41 info = json.loads(info_json)['versions'][0]
42
43 video_url = 'http://video720.jeuxvideo.com/' + info['file']
44
45 return {
46 'id': video_id,
47 'title': config.find('titre_video').text,
48 'ext': 'mp4',
49 'url': video_url,
50 'description': self._og_search_description(webpage),
51 'thumbnail': config.find('image').text,
52 }