Merge branch 'jukebox' of https://github.com/remitamine/youtube-dl into remitamine...
[youtube-dl] / youtube_dl / extractor / gameinformer.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import int_or_none
7
8
9 class GameInformerIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:www\.)?gameinformer\.com/(?:[^/]+/)*(?P<id>.+)\.aspx'
11     _TEST = {
12         'url': 'http://www.gameinformer.com/b/features/archive/2015/09/26/replay-animal-crossing.aspx',
13         'info_dict': {
14             'id': '4515472681001',
15             'ext': 'm3u8',
16             'title': 'Replay - Animal Crossing',
17             'description': 'md5:2e211891b215c85d061adc7a4dd2d930',
18             'timestamp': 1443457610706,
19         },
20         'params': {
21             # m3u8 download
22             'skip_download': True,
23         },
24     }
25
26     def _real_extract(self, url):
27         display_id = self._match_id(url)
28         webpage = self._download_webpage(url, display_id)
29
30         bc_api_url = self._search_regex(r"getVideo\('([^']+)'", webpage, 'brightcove api url')
31         json_data = self._download_json(
32             bc_api_url + '&video_fields=id,name,shortDescription,publishedDate,videoStillURL,length,IOSRenditions',
33             display_id)
34
35         return {
36             'id': compat_str(json_data['id']),
37             'display_id': display_id,
38             'url': json_data['IOSRenditions'][0]['url'],
39             'title': json_data['name'],
40             'description': json_data.get('shortDescription'),
41             'timestamp': int_or_none(json_data.get('publishedDate')),
42             'duration': int_or_none(json_data.get('length')),
43         }