[gameinformer] Add new extractor
[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         'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
14         'info_dict': {
15             'id': '4515472681001',
16             'ext': 'm3u8',
17             'title': 'Replay - Animal Crossing',
18             'description': 'md5:2e211891b215c85d061adc7a4dd2d930',
19             'timestamp': 1443457610706,
20         },
21         'params': {
22             # m3u8 download
23             'skip_download': True,
24         },
25     }
26
27     def _real_extract(self, url):
28         display_id = self._match_id(url)
29         webpage = self._download_webpage(url, display_id)
30
31         bc_api_url = self._search_regex(r"getVideo\('([^']+)'", webpage, 'brightcove api url')
32         json_data = self._download_json(bc_api_url + '&video_fields=id,name,shortDescription,publishedDate,videoStillURL,length,IOSRenditions', display_id)
33
34         return {
35             'id': compat_str(json_data['id']),
36             'display_id': display_id,
37             'url': json_data['IOSRenditions'][0]['url'],
38             'title': json_data['name'],
39             'description': json_data.get('shortDescription'),
40             'timestamp': int_or_none(json_data.get('publishedDate')),
41             'duration': int_or_none(json_data.get('length')),
42         }