Merge remote-tracking branch 'rzhxeo/crunchyroll'
[youtube-dl] / youtube_dl / extractor / jeuxvideo.py
1 # coding: utf-8
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7
8
9 class JeuxVideoIE(InfoExtractor):
10     _VALID_URL = r'http://.*?\.jeuxvideo\.com/.*/(.*?)-\d+\.htm'
11
12     _TEST = {
13         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',
14         u'file': u'5182.mp4',
15         u'md5': u'046e491afb32a8aaac1f44dd4ddd54ee',
16         u'info_dict': {
17             u'title': u'GC 2013 : Tearaway nous présente ses papiers d\'identité',
18             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',
19         },
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url)
24         title = mobj.group(1)
25         webpage = self._download_webpage(url, title)
26         xml_link = self._html_search_regex(
27             r'<param name="flashvars" value="config=(.*?)" />',
28             webpage, u'config URL')
29         
30         video_id = self._search_regex(
31             r'http://www\.jeuxvideo\.com/config/\w+/\d+/(.*?)/\d+_player\.xml',
32             xml_link, u'video ID')
33
34         config = self._download_xml(
35             xml_link, title, u'Downloading XML config')
36         info_json = config.find('format.json').text
37         info = json.loads(info_json)['versions'][0]
38         
39         video_url = 'http://video720.jeuxvideo.com/' + info['file']
40
41         return {
42             'id': video_id,
43             'title': config.find('titre_video').text,
44             'ext': 'mp4',
45             'url': video_url,
46             'description': self._og_search_description(webpage),
47             'thumbnail': config.find('image').text,
48         }