Merge pull request #1565 from rzhxeo/rtmpdump_test
[youtube-dl] / youtube_dl / extractor / gamespot.py
1 import re
2 import xml.etree.ElementTree
3
4 from .common import InfoExtractor
5 from ..utils import (
6     unified_strdate,
7     compat_urllib_parse,
8 )
9
10 class GameSpotIE(InfoExtractor):
11     _WORKING = False
12     _VALID_URL = r'(?:http://)?(?:www\.)?gamespot\.com/.*-(?P<page_id>\d+)/?'
13     _TEST = {
14         u"url": u"http://www.gamespot.com/arma-iii/videos/arma-iii-community-guide-sitrep-i-6410818/",
15         u"file": u"6410818.mp4",
16         u"md5": u"b2a30deaa8654fcccd43713a6b6a4825",
17         u"info_dict": {
18             u"title": u"Arma 3 - Community Guide: SITREP I",
19             u"upload_date": u"20130627", 
20         }
21     }
22
23
24     def _real_extract(self, url):
25         mobj = re.match(self._VALID_URL, url)
26         page_id = mobj.group('page_id')
27         webpage = self._download_webpage(url, page_id)
28         video_id = self._html_search_regex([r'"og:video" content=".*?\?id=(\d+)"',
29                                             r'http://www\.gamespot\.com/videoembed/(\d+)'],
30                                            webpage, 'video id')
31         data = compat_urllib_parse.urlencode({'id': video_id, 'newplayer': '1'})
32         info_url = 'http://www.gamespot.com/pages/video_player/xml.php?' + data
33         info_xml = self._download_webpage(info_url, video_id)
34         doc = xml.etree.ElementTree.fromstring(info_xml)
35         clip_el = doc.find('./playList/clip')
36
37         http_urls = [{'url': node.find('filePath').text,
38                       'rate': int(node.find('rate').text)}
39             for node in clip_el.find('./httpURI')]
40         best_quality = sorted(http_urls, key=lambda f: f['rate'])[-1]
41         video_url = best_quality['url']
42         title = clip_el.find('./title').text
43         ext = video_url.rpartition('.')[2]
44         thumbnail_url = clip_el.find('./screenGrabURI').text
45         view_count = int(clip_el.find('./views').text)
46         upload_date = unified_strdate(clip_el.find('./postDate').text)
47
48         return [{
49             'id'          : video_id,
50             'url'         : video_url,
51             'ext'         : ext,
52             'title'       : title,
53             'thumbnail'   : thumbnail_url,
54             'upload_date' : upload_date,
55             'view_count'  : view_count,
56         }]