logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

aljazeera.py (2228B)


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