]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/metacritic.py
Update changelog.
[youtubedl] / youtube_dl / extractor / metacritic.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 fix_xml_ampersands,
8 )
9
10
11 class MetacriticIE(InfoExtractor):
12 _VALID_URL = r'https?://www\.metacritic\.com/.+?/trailers/(?P<id>\d+)'
13
14 _TEST = {
15 'url': 'http://www.metacritic.com/game/playstation-4/infamous-second-son/trailers/3698222',
16 'info_dict': {
17 'id': '3698222',
18 'ext': 'mp4',
19 'title': 'inFamous: Second Son - inSide Sucker Punch: Smoke & Mirrors',
20 'description': 'Take a peak behind-the-scenes to see how Sucker Punch brings smoke into the universe of inFAMOUS Second Son on the PS4.',
21 'duration': 221,
22 },
23 }
24
25 def _real_extract(self, url):
26 mobj = re.match(self._VALID_URL, url)
27 video_id = mobj.group('id')
28 webpage = self._download_webpage(url, video_id)
29 # The xml is not well formatted, there are raw '&'
30 info = self._download_xml('http://www.metacritic.com/video_data?video=' + video_id,
31 video_id, 'Downloading info xml', transform_source=fix_xml_ampersands)
32
33 clip = next(c for c in info.findall('playList/clip') if c.find('id').text == video_id)
34 formats = []
35 for videoFile in clip.findall('httpURI/videoFile'):
36 rate_str = videoFile.find('rate').text
37 video_url = videoFile.find('filePath').text
38 formats.append({
39 'url': video_url,
40 'ext': 'mp4',
41 'format_id': rate_str,
42 'tbr': int(rate_str),
43 })
44 self._sort_formats(formats)
45
46 description = self._html_search_regex(r'<b>Description:</b>(.*?)</p>',
47 webpage, 'description', flags=re.DOTALL)
48
49 return {
50 'id': video_id,
51 'title': clip.find('title').text,
52 'formats': formats,
53 'description': description,
54 'duration': int(clip.find('duration').text),
55 }