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.

102 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_b64decode,
  7. compat_str,
  8. compat_urlparse,
  9. )
  10. from ..utils import (
  11. extract_attributes,
  12. ExtractorError,
  13. get_elements_by_class,
  14. urlencode_postdata,
  15. )
  16. class EinthusanIE(InfoExtractor):
  17. _VALID_URL = r'https?://einthusan\.tv/movie/watch/(?P<id>[^/?#&]+)'
  18. _TESTS = [{
  19. 'url': 'https://einthusan.tv/movie/watch/9097/',
  20. 'md5': 'ff0f7f2065031b8a2cf13a933731c035',
  21. 'info_dict': {
  22. 'id': '9097',
  23. 'ext': 'mp4',
  24. 'title': 'Ae Dil Hai Mushkil',
  25. 'description': 'md5:33ef934c82a671a94652a9b4e54d931b',
  26. 'thumbnail': r're:^https?://.*\.jpg$',
  27. }
  28. }, {
  29. 'url': 'https://einthusan.tv/movie/watch/51MZ/?lang=hindi',
  30. 'only_matching': True,
  31. }]
  32. # reversed from jsoncrypto.prototype.decrypt() in einthusan-PGMovieWatcher.js
  33. def _decrypt(self, encrypted_data, video_id):
  34. return self._parse_json(compat_b64decode((
  35. encrypted_data[:10] + encrypted_data[-1] + encrypted_data[12:-1]
  36. )).decode('utf-8'), video_id)
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(url, video_id)
  40. title = self._html_search_regex(r'<h3>([^<]+)</h3>', webpage, 'title')
  41. player_params = extract_attributes(self._search_regex(
  42. r'(<section[^>]+id="UIVideoPlayer"[^>]+>)', webpage, 'player parameters'))
  43. page_id = self._html_search_regex(
  44. '<html[^>]+data-pageid="([^"]+)"', webpage, 'page ID')
  45. video_data = self._download_json(
  46. 'https://einthusan.tv/ajax/movie/watch/%s/' % video_id, video_id,
  47. data=urlencode_postdata({
  48. 'xEvent': 'UIVideoPlayer.PingOutcome',
  49. 'xJson': json.dumps({
  50. 'EJOutcomes': player_params['data-ejpingables'],
  51. 'NativeHLS': False
  52. }),
  53. 'arcVersion': 3,
  54. 'appVersion': 59,
  55. 'gorilla.csrf.Token': page_id,
  56. }))['Data']
  57. if isinstance(video_data, compat_str) and video_data.startswith('/ratelimited/'):
  58. raise ExtractorError(
  59. 'Download rate reached. Please try again later.', expected=True)
  60. ej_links = self._decrypt(video_data['EJLinks'], video_id)
  61. formats = []
  62. m3u8_url = ej_links.get('HLSLink')
  63. if m3u8_url:
  64. formats.extend(self._extract_m3u8_formats(
  65. m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native'))
  66. mp4_url = ej_links.get('MP4Link')
  67. if mp4_url:
  68. formats.append({
  69. 'url': mp4_url,
  70. })
  71. self._sort_formats(formats)
  72. description = get_elements_by_class('synopsis', webpage)[0]
  73. thumbnail = self._html_search_regex(
  74. r'''<img[^>]+src=(["'])(?P<url>(?!\1).+?/moviecovers/(?!\1).+?)\1''',
  75. webpage, 'thumbnail url', fatal=False, group='url')
  76. if thumbnail is not None:
  77. thumbnail = compat_urlparse.urljoin(url, thumbnail)
  78. return {
  79. 'id': video_id,
  80. 'title': title,
  81. 'formats': formats,
  82. 'thumbnail': thumbnail,
  83. 'description': description,
  84. }