logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

streamsb.py (2227B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import binascii
  4. import random
  5. import re
  6. import string
  7. from .common import InfoExtractor
  8. from ..utils import urljoin, url_basename
  9. def to_ascii_hex(str1):
  10. return binascii.hexlify(str1.encode('utf-8')).decode('ascii')
  11. def generate_random_string(length):
  12. return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
  13. class StreamsbIE(InfoExtractor):
  14. _DOMAINS = ('viewsb.com', )
  15. _VALID_URL = r'https://(?P<domain>%s)/(?P<id>.+)' % '|'.join(_DOMAINS)
  16. _TEST = {
  17. 'url': 'https://viewsb.com/dxfvlu4qanjx',
  18. 'md5': '488d111a63415369bf90ea83adc8a325',
  19. 'info_dict': {
  20. 'id': 'dxfvlu4qanjx',
  21. 'ext': 'mp4',
  22. 'title': 'Sintel'
  23. }
  24. }
  25. def _real_extract(self, url):
  26. domain, video_id = re.match(self._VALID_URL, url).group('domain', 'id')
  27. webpage = self._download_webpage(url, video_id)
  28. iframe_rel_url = self._search_regex(r'''(?i)<iframe\b[^>]+\bsrc\s*=\s*('|")(?P<path>/.*\.html)\1''', webpage, 'iframe', group='path')
  29. iframe_url = urljoin('https://' + domain, iframe_rel_url)
  30. iframe_data = self._download_webpage(iframe_url, video_id)
  31. app_version = self._search_regex(r'''<script\b[^>]+\bsrc\s*=\s*["|'].*/app\.min\.(\d+)\.js''', iframe_data, 'app version', fatal=False) or '50'
  32. video_code = url_basename(iframe_url).rsplit('.')[0]
  33. length = 12
  34. req = '||'.join((generate_random_string(length), video_code, generate_random_string(length), 'streamsb'))
  35. ereq = 'https://{0}/sources{1}/{2}'.format(domain, app_version, to_ascii_hex(req))
  36. video_data = self._download_webpage(ereq, video_id, headers={
  37. 'Referer': iframe_url,
  38. 'watchsb': 'sbstream',
  39. })
  40. player_data = self._parse_json(video_data, video_id)
  41. title = player_data['stream_data']['title']
  42. formats = self._extract_m3u8_formats(player_data['stream_data']['file'], video_id, ext='mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
  43. return {
  44. 'id': video_id,
  45. 'formats': formats,
  46. 'title': title,
  47. }