]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/metacritic.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / metacritic.py
CommitLineData
7e772752 1import re
7e772752
JMF
2
3from .common import InfoExtractor
18258362 4from ..utils import (
5aafe895 5 fix_xml_ampersands,
18258362 6)
7e772752
JMF
7
8
9class MetacriticIE(InfoExtractor):
92519402 10 _VALID_URL = r'https?://(?:www\.)?metacritic\.com/.+?/trailers/(?P<id>\d+)'
7e772752 11
86475d59 12 _TESTS = [{
9c631286 13 'url': 'http://www.metacritic.com/game/playstation-4/infamous-second-son/trailers/3698222',
9c631286 14 'info_dict': {
87a25660
JMF
15 'id': '3698222',
16 'ext': 'mp4',
9c631286
PH
17 'title': 'inFamous: Second Son - inSide Sucker Punch: Smoke & Mirrors',
18 'description': 'Take a peak behind-the-scenes to see how Sucker Punch brings smoke into the universe of inFAMOUS Second Son on the PS4.',
19 'duration': 221,
7e772752 20 },
86475d59
YCH
21 'skip': 'Not providing trailers anymore',
22 }, {
23 'url': 'http://www.metacritic.com/game/playstation-4/tales-from-the-borderlands-a-telltale-game-series/trailers/5740315',
24 'info_dict': {
25 'id': '5740315',
26 'ext': 'mp4',
27 'title': 'Tales from the Borderlands - Finale: The Vault of the Traveler',
28 'description': 'In the final episode of the season, all hell breaks loose. Jack is now in control of Helios\' systems, and he\'s ready to reclaim his rightful place as king of Hyperion (with or without you).',
29 'duration': 114,
30 },
31 }]
7e772752
JMF
32
33 def _real_extract(self, url):
5ad28e7f 34 mobj = self._match_valid_url(url)
7e772752
JMF
35 video_id = mobj.group('id')
36 webpage = self._download_webpage(url, video_id)
37 # The xml is not well formatted, there are raw '&'
18258362 38 info = self._download_xml('http://www.metacritic.com/video_data?video=' + video_id,
9e1a5b84 39 video_id, 'Downloading info xml', transform_source=fix_xml_ampersands)
7e772752
JMF
40
41 clip = next(c for c in info.findall('playList/clip') if c.find('id').text == video_id)
42 formats = []
add96eb9 43 for video_file in clip.findall('httpURI/videoFile'):
44 rate_str = video_file.find('rate').text
45 video_url = video_file.find('filePath').text
7e772752
JMF
46 formats.append({
47 'url': video_url,
48 'ext': 'mp4',
49 'format_id': rate_str,
9c631286 50 'tbr': int(rate_str),
7e772752 51 })
7e772752
JMF
52
53 description = self._html_search_regex(r'<b>Description:</b>(.*?)</p>',
9e1a5b84 54 webpage, 'description', flags=re.DOTALL)
7e772752 55
fb7abb31 56 return {
7e772752
JMF
57 'id': video_id,
58 'title': clip.find('title').text,
59 'formats': formats,
60 'description': description,
61 'duration': int(clip.find('duration').text),
62 }