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.

128 lines
4.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_chr
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. int_or_none,
  10. js_to_json,
  11. )
  12. class StreamangoIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?(?:streamango\.com|fruithosts\.net|streamcherry\.com)/(?:f|embed)/(?P<id>[^/?#&]+)'
  14. _TESTS = [{
  15. 'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4',
  16. 'md5': 'e992787515a182f55e38fc97588d802a',
  17. 'info_dict': {
  18. 'id': 'clapasobsptpkdfe',
  19. 'ext': 'mp4',
  20. 'title': '20170315_150006.mp4',
  21. }
  22. }, {
  23. # no og:title
  24. 'url': 'https://streamango.com/embed/foqebrpftarclpob/asdf_asd_2_mp4',
  25. 'info_dict': {
  26. 'id': 'foqebrpftarclpob',
  27. 'ext': 'mp4',
  28. 'title': 'foqebrpftarclpob',
  29. },
  30. 'params': {
  31. 'skip_download': True,
  32. },
  33. 'skip': 'gone',
  34. }, {
  35. 'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'https://fruithosts.net/f/mreodparcdcmspsm/w1f1_r4lph_2018_brrs_720p_latino_mp4',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'https://streamcherry.com/f/clapasobsptpkdfe/',
  42. 'only_matching': True,
  43. }]
  44. def _real_extract(self, url):
  45. def decrypt_src(encoded, val):
  46. ALPHABET = '=/+9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA'
  47. encoded = re.sub(r'[^A-Za-z0-9+/=]', '', encoded)
  48. decoded = ''
  49. sm = [None] * 4
  50. i = 0
  51. str_len = len(encoded)
  52. while i < str_len:
  53. for j in range(4):
  54. sm[j % 4] = ALPHABET.index(encoded[i])
  55. i += 1
  56. char_code = ((sm[0] << 0x2) | (sm[1] >> 0x4)) ^ val
  57. decoded += compat_chr(char_code)
  58. if sm[2] != 0x40:
  59. char_code = ((sm[1] & 0xf) << 0x4) | (sm[2] >> 0x2)
  60. decoded += compat_chr(char_code)
  61. if sm[3] != 0x40:
  62. char_code = ((sm[2] & 0x3) << 0x6) | sm[3]
  63. decoded += compat_chr(char_code)
  64. return decoded
  65. video_id = self._match_id(url)
  66. webpage = self._download_webpage(url, video_id)
  67. title = self._og_search_title(webpage, default=video_id)
  68. formats = []
  69. for format_ in re.findall(r'({[^}]*\bsrc\s*:\s*[^}]*})', webpage):
  70. mobj = re.search(r'(src\s*:\s*[^(]+\(([^)]*)\)[\s,]*)', format_)
  71. if mobj is None:
  72. continue
  73. format_ = format_.replace(mobj.group(0), '')
  74. video = self._parse_json(
  75. format_, video_id, transform_source=js_to_json,
  76. fatal=False) or {}
  77. mobj = re.search(
  78. r'([\'"])(?P<src>(?:(?!\1).)+)\1\s*,\s*(?P<val>\d+)',
  79. mobj.group(1))
  80. if mobj is None:
  81. continue
  82. src = decrypt_src(mobj.group('src'), int_or_none(mobj.group('val')))
  83. if not src:
  84. continue
  85. ext = determine_ext(src, default_ext=None)
  86. if video.get('type') == 'application/dash+xml' or ext == 'mpd':
  87. formats.extend(self._extract_mpd_formats(
  88. src, video_id, mpd_id='dash', fatal=False))
  89. else:
  90. formats.append({
  91. 'url': src,
  92. 'ext': ext or 'mp4',
  93. 'width': int_or_none(video.get('width')),
  94. 'height': int_or_none(video.get('height')),
  95. 'tbr': int_or_none(video.get('bitrate')),
  96. })
  97. if not formats:
  98. error = self._search_regex(
  99. r'<p[^>]+\bclass=["\']lead[^>]+>(.+?)</p>', webpage,
  100. 'error', default=None)
  101. if not error and '>Sorry' in webpage:
  102. error = 'Video %s is not available' % video_id
  103. if error:
  104. raise ExtractorError(error, expected=True)
  105. self._sort_formats(formats)
  106. return {
  107. 'id': video_id,
  108. 'url': url,
  109. 'title': title,
  110. 'formats': formats,
  111. }