shahid.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. js_to_json,
  4. ExtractorError,
  5. int_or_none
  6. )
  7. class ShahidIE(InfoExtractor):
  8. _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P<id>\d+)/?'
  9. _TESTS = [
  10. {
  11. 'url': 'https://shahid.mbc.net/ar/episode/108084/%D8%AE%D9%88%D8%A7%D8%B7%D8%B1-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-11-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html',
  12. 'info_dict': {
  13. 'id': '108084',
  14. 'ext': 'm3u8',
  15. 'title': 'خواطر الموسم 11 الحلقة 1',
  16. 'description': 'بسم الله',
  17. 'duration': 1166,
  18. },
  19. 'params': {
  20. # m3u8 download
  21. 'skip_download': True,
  22. }
  23. },
  24. {
  25. #shahid plus subscriber only
  26. 'url': 'https://shahid.mbc.net/ar/series/90497/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011.html',
  27. 'only_matching': True
  28. }
  29. ]
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. player_info = ''
  34. for line in self._search_regex( 'var flashvars = ({[^}]+})', webpage, 'flashvars').splitlines():
  35. if '+' not in line and '(' not in line and ')' not in line:
  36. player_info += line
  37. player_info = self._parse_json(js_to_json(player_info), video_id)
  38. video_id = player_info['id']
  39. player_type = player_info['playerType']
  40. video_info = self._download_json(
  41. player_info['url'] + '/' + player_type + '/' + video_id +
  42. '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D',
  43. video_id
  44. )['data']
  45. if video_info['error']:
  46. for error in video_info['error']:
  47. raise ExtractorError(error)
  48. video_info = video_info[player_type]
  49. if video_info.get('availabilities').get('plus'):
  50. raise ExtractorError('plus members only')
  51. title = video_info['title']
  52. thumbnail = video_info.get('thumbnailUrl')
  53. categories = [category['name'] for category in video_info.get('genres')]
  54. description = video_info.get('description')
  55. duration = int_or_none(video_info.get('duration'))
  56. player_json_data = self._download_json(
  57. 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-' + video_id + '.type-' + player_info['type'] + '.html',
  58. video_id
  59. )['data']
  60. if 'url' in player_json_data:
  61. m3u8_url = player_json_data['url']
  62. else:
  63. for error in player_json_data['error'].values():
  64. raise ExtractorError(error)
  65. return
  66. formats = self._extract_m3u8_formats(m3u8_url, video_id)
  67. return {
  68. 'id': video_id,
  69. 'title': title,
  70. 'thumbnail': thumbnail,
  71. 'categories': categories,
  72. 'description': description,
  73. 'duration': duration,
  74. 'formats': formats,
  75. }