]> asedeno.scripts.mit.edu Git - youtube-dl.git/blob - youtube_dl/extractor/aljazeera.py
[eroprofile] Skip test
[youtube-dl.git] / youtube_dl / extractor / aljazeera.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7
8
9 class AlJazeeraIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:www\.)?aljazeera\.com/(?P<type>program/[^/]+|(?:feature|video)s)/\d{4}/\d{1,2}/\d{1,2}/(?P<id>[^/?&#]+)'
11
12     _TESTS = [{
13         'url': 'https://www.aljazeera.com/program/episode/2014/9/19/deliverance',
14         'info_dict': {
15             'id': '3792260579001',
16             'ext': 'mp4',
17             'title': 'The Slum - Episode 1: Deliverance',
18             'description': 'As a birth attendant advocating for family planning, Remy is on the frontline of Tondo\'s battle with overcrowding.',
19             'uploader_id': '665003303001',
20             'timestamp': 1411116829,
21             'upload_date': '20140919',
22         },
23         'add_ie': ['BrightcoveNew'],
24         'skip': 'Not accessible from Travis CI server',
25     }, {
26         'url': 'https://www.aljazeera.com/videos/2017/5/11/sierra-leone-709-carat-diamond-to-be-auctioned-off',
27         'only_matching': True,
28     }, {
29         'url': 'https://www.aljazeera.com/features/2017/8/21/transforming-pakistans-buses-into-art',
30         'only_matching': True,
31     }]
32     BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'
33
34     def _real_extract(self, url):
35         post_type, name = re.match(self._VALID_URL, url).groups()
36         post_type = {
37             'features': 'post',
38             'program': 'episode',
39             'videos': 'video',
40         }[post_type.split('/')[0]]
41         video = self._download_json(
42             'https://www.aljazeera.com/graphql', name, query={
43                 'operationName': 'SingleArticleQuery',
44                 'variables': json.dumps({
45                     'name': name,
46                     'postType': post_type,
47                 }),
48             }, headers={
49                 'wp-site': 'aje',
50             })['data']['article']['video']
51         video_id = video['id']
52         account_id = video.get('accountId') or '665003303001'
53         player_id = video.get('playerId') or 'BkeSH5BDb'
54         return self.url_result(
55             self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id),
56             'BrightcoveNew', video_id)