You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. parse_iso8601,
  8. str_or_none,
  9. )
  10. class ShahidIE(InfoExtractor):
  11. _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P<id>\d+)/?'
  12. _TESTS = [{
  13. 'url': 'https://shahid.mbc.net/ar/episode/90574/%D8%A7%D9%84%D9%85%D9%84%D9%83-%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D9%84%D9%87-%D8%A7%D9%84%D8%A5%D9%86%D8%B3%D8%A7%D9%86-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-3.html',
  14. 'info_dict': {
  15. 'id': '90574',
  16. 'ext': 'mp4',
  17. 'title': 'الملك عبدالله الإنسان الموسم 1 كليب 3',
  18. 'description': 'الفيلم الوثائقي - الملك عبد الله الإنسان',
  19. 'duration': 2972,
  20. 'timestamp': 1422057420,
  21. 'upload_date': '20150123',
  22. },
  23. 'params': {
  24. # m3u8 download
  25. 'skip_download': True,
  26. }
  27. }, {
  28. # shahid plus subscriber only
  29. 'url': 'https://shahid.mbc.net/ar/episode/90511/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html',
  30. 'only_matching': True
  31. }]
  32. def _call_api(self, path, video_id, note):
  33. data = self._download_json(
  34. 'http://api.shahid.net/api/v1_1/' + path, video_id, note, query={
  35. 'apiKey': 'sh@hid0nlin3',
  36. 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=',
  37. }).get('data', {})
  38. error = data.get('error')
  39. if error:
  40. raise ExtractorError(
  41. '%s returned error: %s' % (self.IE_NAME, '\n'.join(error.values())),
  42. expected=True)
  43. return data
  44. def _real_extract(self, url):
  45. video_id = self._match_id(url)
  46. player = self._call_api(
  47. 'Content/Episode/%s' % video_id,
  48. video_id, 'Downloading player JSON')
  49. if player.get('drm'):
  50. raise ExtractorError('This video is DRM protected.', expected=True)
  51. formats = self._extract_m3u8_formats(player['url'], video_id, 'mp4')
  52. self._sort_formats(formats)
  53. video = self._call_api(
  54. 'episode/%s' % video_id, video_id,
  55. 'Downloading video JSON')['episode']
  56. title = video['title']
  57. categories = [
  58. category['name']
  59. for category in video.get('genres', []) if 'name' in category]
  60. return {
  61. 'id': video_id,
  62. 'title': title,
  63. 'description': video.get('description'),
  64. 'thumbnail': video.get('thumbnailUrl'),
  65. 'duration': int_or_none(video.get('duration')),
  66. 'timestamp': parse_iso8601(video.get('referenceDate')),
  67. 'categories': categories,
  68. 'series': video.get('showTitle') or video.get('showName'),
  69. 'season': video.get('seasonTitle'),
  70. 'season_number': int_or_none(video.get('seasonNumber')),
  71. 'season_id': str_or_none(video.get('seasonId')),
  72. 'episode_number': int_or_none(video.get('number')),
  73. 'episode_id': video_id,
  74. 'formats': formats,
  75. }