shemaroome.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import base64
  2. from .common import InfoExtractor
  3. from ..aes import aes_cbc_decrypt, unpad_pkcs7
  4. from ..utils import (
  5. ExtractorError,
  6. bytes_to_intlist,
  7. intlist_to_bytes,
  8. unified_strdate,
  9. )
  10. class ShemarooMeIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?shemaroome\.com/(?:movies|shows)/(?P<id>[^?#]+)'
  12. _TESTS = [{
  13. 'url': 'https://www.shemaroome.com/movies/dil-hai-tumhaara',
  14. 'info_dict': {
  15. 'id': 'dil-hai-tumhaara',
  16. 'ext': 'mp4',
  17. 'title': 'Dil Hai Tumhaara',
  18. 'release_date': '20020906',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. 'description': 'md5:2782c4127807103cf5a6ae2ca33645ce',
  21. },
  22. 'params': {
  23. 'skip_download': True,
  24. },
  25. }, {
  26. 'url': 'https://www.shemaroome.com/shows/jurm-aur-jazbaat/laalach',
  27. 'info_dict': {
  28. 'id': 'jurm-aur-jazbaat_laalach',
  29. 'ext': 'mp4',
  30. 'title': 'Laalach',
  31. 'description': 'md5:92b79c2dcb539b0ab53f9fa5a048f53c',
  32. 'thumbnail': r're:^https?://.*\.jpg$',
  33. 'release_date': '20210507',
  34. },
  35. 'params': {
  36. 'skip_download': True,
  37. },
  38. 'skip': 'Premium videos cannot be downloaded yet.',
  39. }, {
  40. 'url': 'https://www.shemaroome.com/shows/jai-jai-jai-bajrang-bali/jai-jai-jai-bajrang-bali-episode-99',
  41. 'info_dict': {
  42. 'id': 'jai-jai-jai-bajrang-bali_jai-jai-jai-bajrang-bali-episode-99',
  43. 'ext': 'mp4',
  44. 'title': 'Jai Jai Jai Bajrang Bali Episode 99',
  45. 'description': 'md5:850d127a18ee3f9529d7fbde2f49910d',
  46. 'thumbnail': r're:^https?://.*\.jpg$',
  47. 'release_date': '20110101',
  48. },
  49. 'params': {
  50. 'skip_download': True,
  51. },
  52. }]
  53. def _real_extract(self, url):
  54. video_id = self._match_id(url).replace('/', '_')
  55. webpage = self._download_webpage(url, video_id)
  56. title = self._search_regex(r'id=\"ma_title\" value=\"([^\"]+)', webpage, 'title')
  57. thumbnail = self._og_search_thumbnail(webpage)
  58. content_def = self._search_regex(r'id=\"content_definition\" value=\"([^\"]+)', webpage, 'content_def')
  59. catalog_id = self._search_regex(r'id=\"catalog_id\" value=\"([^\"]+)', webpage, 'catalog_id')
  60. item_category = self._search_regex(r'id=\"item_category\" value=\"([^\"]+)', webpage, 'item_category')
  61. content_id = self._search_regex(r'id=\"content_id\" value=\"([^\"]+)', webpage, 'content_id')
  62. data = f'catalog_id={catalog_id}&content_id={content_id}&category={item_category}&content_def={content_def}'
  63. data_json = self._download_json('https://www.shemaroome.com/users/user_all_lists', video_id, data=data.encode())
  64. if not data_json.get('status'):
  65. raise ExtractorError('Premium videos cannot be downloaded yet.', expected=True)
  66. url_data = bytes_to_intlist(base64.b64decode(data_json['new_play_url']))
  67. key = bytes_to_intlist(base64.b64decode(data_json['key']))
  68. iv = [0] * 16
  69. m3u8_url = unpad_pkcs7(intlist_to_bytes(aes_cbc_decrypt(url_data, key, iv))).decode('ascii')
  70. headers = {'stream_key': data_json['stream_key']}
  71. formats, m3u8_subs = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, fatal=False, headers=headers)
  72. for fmt in formats:
  73. fmt['http_headers'] = headers
  74. release_date = self._html_search_regex(
  75. (r'itemprop="uploadDate">\s*([\d-]+)', r'id="release_date" value="([\d-]+)'),
  76. webpage, 'release date', fatal=False)
  77. subtitles = {}
  78. sub_url = data_json.get('subtitle')
  79. if sub_url:
  80. subtitles.setdefault('EN', []).append({
  81. 'url': self._proto_relative_url(sub_url),
  82. })
  83. subtitles = self._merge_subtitles(subtitles, m3u8_subs)
  84. description = self._html_search_regex(r'(?s)>Synopsis(</.+?)</', webpage, 'description', fatal=False)
  85. return {
  86. 'id': video_id,
  87. 'formats': formats,
  88. 'title': title,
  89. 'thumbnail': thumbnail,
  90. 'release_date': unified_strdate(release_date),
  91. 'description': description,
  92. 'subtitles': subtitles,
  93. }