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