2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_chr
15 class StreamangoIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?streamango\.com/(?:f|embed)/(?P<id>[^/?#&]+)'
18 'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4',
19 'md5': 'e992787515a182f55e38fc97588d802a',
21 'id': 'clapasobsptpkdfe',
23 'title': '20170315_150006.mp4',
27 'url': 'https://streamango.com/embed/foqebrpftarclpob/asdf_asd_2_mp4',
29 'id': 'foqebrpftarclpob',
31 'title': 'foqebrpftarclpob',
34 'skip_download': True,
37 'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4',
38 'only_matching': True,
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)
48 str_len = len(encoded)
51 sm[j % 4] = ALPHABET.index(encoded[i])
53 char_code = ((sm[0] << 0x2) | (sm[1] >> 0x4)) ^ val
54 decoded += compat_chr(char_code)
56 char_code = ((sm[1] & 0xf) << 0x4) | (sm[2] >> 0x2)
57 decoded += compat_chr(char_code)
59 char_code = ((sm[2] & 0x3) << 0x6) | sm[3]
60 decoded += compat_chr(char_code)
63 video_id = self._match_id(url)
65 webpage = self._download_webpage(url, video_id)
67 title = self._og_search_title(webpage, default=video_id)
70 for format_ in re.findall(r'({[^}]*\bsrc\s*:\s*[^}]*})', webpage):
71 mobj = re.search(r'(src\s*:\s*[^(]+\(([^)]*)\)[\s,]*)', format_)
75 format_ = format_.replace(mobj.group(0), '')
77 video = self._parse_json(
78 format_, video_id, transform_source=js_to_json,
82 r'([\'"])(?P<src>(?:(?!\1).)+)\1\s*,\s*(?P<val>\d+)',
87 src = decrypt_src(mobj.group('src'), int_or_none(mobj.group('val')))
91 ext = determine_ext(src, default_ext=None)
92 if video.get('type') == 'application/dash+xml' or ext == 'mpd':
93 formats.extend(self._extract_mpd_formats(
94 src, video_id, mpd_id='dash', fatal=False))
99 'width': int_or_none(video.get('width')),
100 'height': int_or_none(video.get('height')),
101 'tbr': int_or_none(video.get('bitrate')),
103 self._sort_formats(formats)