| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  | from ..compat import compat_chr | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     determine_ext, | 
					
						
							| 
									
										
										
										
											2018-02-25 18:34:52 +07:00
										 |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  |     int_or_none, | 
					
						
							|  |  |  |     js_to_json, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class StreamangoIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2019-01-20 05:24:21 -04:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?(?:streamango\.com|fruithosts\.net)/(?:f|embed)/(?P<id>[^/?#&]+)' | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4', | 
					
						
							|  |  |  |         'md5': 'e992787515a182f55e38fc97588d802a', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'clapasobsptpkdfe', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': '20170315_150006.mp4', | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-06-05 20:17:43 +02:00
										 |  |  |     }, { | 
					
						
							| 
									
										
										
										
											2017-06-07 21:53:13 +07:00
										 |  |  |         # no og:title | 
					
						
							| 
									
										
										
										
											2017-06-05 20:17:43 +02:00
										 |  |  |         'url': 'https://streamango.com/embed/foqebrpftarclpob/asdf_asd_2_mp4', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'foqebrpftarclpob', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'foqebrpftarclpob', | 
					
						
							| 
									
										
										
										
											2017-06-07 21:53:13 +07:00
										 |  |  |         }, | 
					
						
							|  |  |  |         'params': { | 
					
						
							|  |  |  |             'skip_download': True, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2018-02-25 18:36:25 +07:00
										 |  |  |         'skip': 'gone', | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2019-01-20 05:24:21 -04:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://fruithosts.net/f/mreodparcdcmspsm/w1f1_r4lph_2018_brrs_720p_latino_mp4', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |         def decrypt_src(encoded, val): | 
					
						
							|  |  |  |             ALPHABET = '=/+9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA' | 
					
						
							|  |  |  |             encoded = re.sub(r'[^A-Za-z0-9+/=]', '', encoded) | 
					
						
							|  |  |  |             decoded = '' | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  |             sm = [None] * 4 | 
					
						
							|  |  |  |             i = 0 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |             str_len = len(encoded) | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  |             while i < str_len: | 
					
						
							|  |  |  |                 for j in range(4): | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |                     sm[j % 4] = ALPHABET.index(encoded[i]) | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  |                     i += 1 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |                 char_code = ((sm[0] << 0x2) | (sm[1] >> 0x4)) ^ val | 
					
						
							|  |  |  |                 decoded += compat_chr(char_code) | 
					
						
							|  |  |  |                 if sm[2] != 0x40: | 
					
						
							|  |  |  |                     char_code = ((sm[1] & 0xf) << 0x4) | (sm[2] >> 0x2) | 
					
						
							|  |  |  |                     decoded += compat_chr(char_code) | 
					
						
							|  |  |  |                 if sm[3] != 0x40: | 
					
						
							|  |  |  |                     char_code = ((sm[2] & 0x3) << 0x6) | sm[3] | 
					
						
							|  |  |  |                     decoded += compat_chr(char_code) | 
					
						
							|  |  |  |             return decoded | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-05 20:17:43 +02:00
										 |  |  |         title = self._og_search_title(webpage, default=video_id) | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  |         formats = [] | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |         for format_ in re.findall(r'({[^}]*\bsrc\s*:\s*[^}]*})', webpage): | 
					
						
							|  |  |  |             mobj = re.search(r'(src\s*:\s*[^(]+\(([^)]*)\)[\s,]*)', format_) | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  |             if mobj is None: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  |             format_ = format_.replace(mobj.group(0), '') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  |             video = self._parse_json( | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |                 format_, video_id, transform_source=js_to_json, | 
					
						
							|  |  |  |                 fatal=False) or {} | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |             mobj = re.search( | 
					
						
							|  |  |  |                 r'([\'"])(?P<src>(?:(?!\1).)+)\1\s*,\s*(?P<val>\d+)', | 
					
						
							|  |  |  |                 mobj.group(1)) | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  |             if mobj is None: | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             src = decrypt_src(mobj.group('src'), int_or_none(mobj.group('val'))) | 
					
						
							| 
									
										
										
										
											2018-02-25 18:25:40 +07:00
										 |  |  |             if not src: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 21:50:15 +07:00
										 |  |  |             ext = determine_ext(src, default_ext=None) | 
					
						
							|  |  |  |             if video.get('type') == 'application/dash+xml' or ext == 'mpd': | 
					
						
							|  |  |  |                 formats.extend(self._extract_mpd_formats( | 
					
						
							|  |  |  |                     src, video_id, mpd_id='dash', fatal=False)) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 formats.append({ | 
					
						
							|  |  |  |                     'url': src, | 
					
						
							|  |  |  |                     'ext': ext or 'mp4', | 
					
						
							|  |  |  |                     'width': int_or_none(video.get('width')), | 
					
						
							|  |  |  |                     'height': int_or_none(video.get('height')), | 
					
						
							|  |  |  |                     'tbr': int_or_none(video.get('bitrate')), | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2018-02-25 18:34:52 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if not formats: | 
					
						
							|  |  |  |             error = self._search_regex( | 
					
						
							|  |  |  |                 r'<p[^>]+\bclass=["\']lead[^>]+>(.+?)</p>', webpage, | 
					
						
							|  |  |  |                 'error', default=None) | 
					
						
							|  |  |  |             if not error and '>Sorry' in webpage: | 
					
						
							|  |  |  |                 error = 'Video %s is not available' % video_id | 
					
						
							|  |  |  |             if error: | 
					
						
							|  |  |  |                 raise ExtractorError(error, expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 19:18:23 +02:00
										 |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'url': url, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } |