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.

99 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. import json
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_urlparse,
  8. compat_str,
  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>[0-9]+)'
  18. _TEST = {
  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. # reversed from jsoncrypto.prototype.decrypt() in einthusan-PGMovieWatcher.js
  30. def _decrypt(self, encrypted_data, video_id):
  31. return self._parse_json(base64.b64decode((
  32. encrypted_data[:10] + encrypted_data[-1] + encrypted_data[12:-1]
  33. ).encode('ascii')).decode('utf-8'), video_id)
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. webpage = self._download_webpage(url, video_id)
  37. title = self._html_search_regex(r'<h3>([^<]+)</h3>', webpage, 'title')
  38. player_params = extract_attributes(self._search_regex(
  39. r'(<section[^>]+id="UIVideoPlayer"[^>]+>)', webpage, 'player parameters'))
  40. page_id = self._html_search_regex(
  41. '<html[^>]+data-pageid="([^"]+)"', webpage, 'page ID')
  42. video_data = self._download_json(
  43. 'https://einthusan.tv/ajax/movie/watch/%s/' % video_id, video_id,
  44. data=urlencode_postdata({
  45. 'xEvent': 'UIVideoPlayer.PingOutcome',
  46. 'xJson': json.dumps({
  47. 'EJOutcomes': player_params['data-ejpingables'],
  48. 'NativeHLS': False
  49. }),
  50. 'arcVersion': 3,
  51. 'appVersion': 59,
  52. 'gorilla.csrf.Token': page_id,
  53. }))['Data']
  54. if isinstance(video_data, compat_str) and video_data.startswith('/ratelimited/'):
  55. raise ExtractorError(
  56. 'Download rate reached. Please try again later.', expected=True)
  57. ej_links = self._decrypt(video_data['EJLinks'], video_id)
  58. formats = []
  59. m3u8_url = ej_links.get('HLSLink')
  60. if m3u8_url:
  61. formats.extend(self._extract_m3u8_formats(
  62. m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native'))
  63. mp4_url = ej_links.get('MP4Link')
  64. if mp4_url:
  65. formats.append({
  66. 'url': mp4_url,
  67. })
  68. self._sort_formats(formats)
  69. description = get_elements_by_class('synopsis', webpage)[0]
  70. thumbnail = self._html_search_regex(
  71. r'''<img[^>]+src=(["'])(?P<url>(?!\1).+?/moviecovers/(?!\1).+?)\1''',
  72. webpage, 'thumbnail url', fatal=False, group='url')
  73. if thumbnail is not None:
  74. thumbnail = compat_urlparse.urljoin(url, thumbnail)
  75. return {
  76. 'id': video_id,
  77. 'title': title,
  78. 'formats': formats,
  79. 'thumbnail': thumbnail,
  80. 'description': description,
  81. }