]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/metacritic.py
debian/NEWS: Write news about new behavior of youtube-dl.
[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 '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,
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 '&'
29 info = self._download_xml('http://www.metacritic.com/video_data?video=' + video_id,
30 video_id, 'Downloading info xml', transform_source=fix_xml_ampersands)
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,
41 'tbr': int(rate_str),
42 })
43 self._sort_formats(formats)
44
45 description = self._html_search_regex(r'<b>Description:</b>(.*?)</p>',
46 webpage, 'description', flags=re.DOTALL)
47
48 return {
49 'id': video_id,
50 'title': clip.find('title').text,
51 'formats': formats,
52 'description': description,
53 'duration': int(clip.find('duration').text),
54 }