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.

125 lines
4.1 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)/(?: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. def _real_extract(self, url):
  42. def decrypt_src(encoded, val):
  43. ALPHABET = '=/+9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA'
  44. encoded = re.sub(r'[^A-Za-z0-9+/=]', '', encoded)
  45. decoded = ''
  46. sm = [None] * 4
  47. i = 0
  48. str_len = len(encoded)
  49. while i < str_len:
  50. for j in range(4):
  51. sm[j % 4] = ALPHABET.index(encoded[i])
  52. i += 1
  53. char_code = ((sm[0] << 0x2) | (sm[1] >> 0x4)) ^ val
  54. decoded += compat_chr(char_code)
  55. if sm[2] != 0x40:
  56. char_code = ((sm[1] & 0xf) << 0x4) | (sm[2] >> 0x2)
  57. decoded += compat_chr(char_code)
  58. if sm[3] != 0x40:
  59. char_code = ((sm[2] & 0x3) << 0x6) | sm[3]
  60. decoded += compat_chr(char_code)
  61. return decoded
  62. video_id = self._match_id(url)
  63. webpage = self._download_webpage(url, video_id)
  64. title = self._og_search_title(webpage, default=video_id)
  65. formats = []
  66. for format_ in re.findall(r'({[^}]*\bsrc\s*:\s*[^}]*})', webpage):
  67. mobj = re.search(r'(src\s*:\s*[^(]+\(([^)]*)\)[\s,]*)', format_)
  68. if mobj is None:
  69. continue
  70. format_ = format_.replace(mobj.group(0), '')
  71. video = self._parse_json(
  72. format_, video_id, transform_source=js_to_json,
  73. fatal=False) or {}
  74. mobj = re.search(
  75. r'([\'"])(?P<src>(?:(?!\1).)+)\1\s*,\s*(?P<val>\d+)',
  76. mobj.group(1))
  77. if mobj is None:
  78. continue
  79. src = decrypt_src(mobj.group('src'), int_or_none(mobj.group('val')))
  80. if not src:
  81. continue
  82. ext = determine_ext(src, default_ext=None)
  83. if video.get('type') == 'application/dash+xml' or ext == 'mpd':
  84. formats.extend(self._extract_mpd_formats(
  85. src, video_id, mpd_id='dash', fatal=False))
  86. else:
  87. formats.append({
  88. 'url': src,
  89. 'ext': ext or 'mp4',
  90. 'width': int_or_none(video.get('width')),
  91. 'height': int_or_none(video.get('height')),
  92. 'tbr': int_or_none(video.get('bitrate')),
  93. })
  94. if not formats:
  95. error = self._search_regex(
  96. r'<p[^>]+\bclass=["\']lead[^>]+>(.+?)</p>', webpage,
  97. 'error', default=None)
  98. if not error and '>Sorry' in webpage:
  99. error = 'Video %s is not available' % video_id
  100. if error:
  101. raise ExtractorError(error, expected=True)
  102. self._sort_formats(formats)
  103. return {
  104. 'id': video_id,
  105. 'url': url,
  106. 'title': title,
  107. 'formats': formats,
  108. }