1 | |
---|
2 | import sys |
---|
3 | from lib.net import Net |
---|
4 | |
---|
5 | import re, urllib, json |
---|
6 | from lib import helpers |
---|
7 | import lib.common as common |
---|
8 | |
---|
9 | class StreamangoResolver(object): |
---|
10 | name = "streamango" |
---|
11 | domains = ['streamango.com', "streamcherry.com"] |
---|
12 | pattern = '(?://|\.)(stream(?:ango|cherry)\.com)/(?:v/d|f|embed)/([0-9a-zA-Z]+)' |
---|
13 | |
---|
14 | def __init__(self): |
---|
15 | # self.net = Net() |
---|
16 | # self.net = Net(cookie_file='/mnt/network/cookies', http_debug = True) |
---|
17 | self.net = Net(cookie_file='/mnt/network/cookies', http_debug = False) |
---|
18 | |
---|
19 | url = str(sys.argv[1]) |
---|
20 | host = self.get_host_and_id(url)[0] |
---|
21 | media_id = self.get_host_and_id(url)[1] |
---|
22 | |
---|
23 | return self.get_media_url(host, media_id) |
---|
24 | |
---|
25 | def get_host_and_id(self, url): |
---|
26 | r = re.search(self.pattern, url, re.I) |
---|
27 | if r: |
---|
28 | return r.groups() |
---|
29 | else: |
---|
30 | return False |
---|
31 | |
---|
32 | def get_media_url1(self, host, media_id): |
---|
33 | web_url = self.get_url(host, media_id) |
---|
34 | link = self.net.http_GET(web_url).content |
---|
35 | if 'FILE WAS DELETED' in link: |
---|
36 | print 'File deleted.' |
---|
37 | else: |
---|
38 | video_link = str(re.compile('file[: ]*"(.+?)"').findall(link)[0]) |
---|
39 | |
---|
40 | if len(video_link) > 0: |
---|
41 | print video_link |
---|
42 | else: |
---|
43 | print 'No playable video found.' |
---|
44 | |
---|
45 | def get_media_url(self, host, media_id): |
---|
46 | web_url = self.get_url(host, media_id) |
---|
47 | |
---|
48 | # headers = {'User-Agent': common.RAND_UA} |
---|
49 | headers = {'User-Agent': common.FF_USER_AGENT} |
---|
50 | |
---|
51 | html = self.net.http_GET(web_url, headers=headers).content |
---|
52 | |
---|
53 | if html: |
---|
54 | encoded = re.search('''srces\.push\({type:"video/mp4",src:\w+\('([^']+)',(\d+)''', html) |
---|
55 | if encoded: |
---|
56 | source = self.decode(encoded.group(1), int(encoded.group(2))) |
---|
57 | if source: |
---|
58 | source = "http:%s" % source if source.startswith("//") else source |
---|
59 | source = source.split("/") |
---|
60 | if not source[-1].isdigit(): |
---|
61 | source[-1] = re.sub('[^\d]', '', source[-1]) |
---|
62 | source = "/".join(source) |
---|
63 | headers.update({'Referer': web_url}) |
---|
64 | # return source + helpers.append_headers(headers) |
---|
65 | print source + helpers.append_headers(headers) |
---|
66 | |
---|
67 | # raise ResolverError("Unable to locate video") |
---|
68 | |
---|
69 | def decode(self, encoded, code): |
---|
70 | _0x59b81a = "" |
---|
71 | k = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' |
---|
72 | k = k[::-1] |
---|
73 | |
---|
74 | count = 0 |
---|
75 | |
---|
76 | for index in range(0, len(encoded) - 1): |
---|
77 | while count <= len(encoded) - 1: |
---|
78 | _0x4a2f3a = k.index(encoded[count]) |
---|
79 | count += 1 |
---|
80 | _0x29d5bf = k.index(encoded[count]) |
---|
81 | count += 1 |
---|
82 | _0x3b6833 = k.index(encoded[count]) |
---|
83 | count += 1 |
---|
84 | _0x426d70 = k.index(encoded[count]) |
---|
85 | count += 1 |
---|
86 | |
---|
87 | _0x2e4782 = ((_0x4a2f3a << 2) | (_0x29d5bf >> 4)) |
---|
88 | _0x2c0540 = (((_0x29d5bf & 15) << 4) | (_0x3b6833 >> 2)) |
---|
89 | _0x5a46ef = ((_0x3b6833 & 3) << 6) | _0x426d70 |
---|
90 | _0x2e4782 = _0x2e4782 ^ code |
---|
91 | |
---|
92 | _0x59b81a = str(_0x59b81a) + chr(_0x2e4782) |
---|
93 | |
---|
94 | if _0x3b6833 != 64: |
---|
95 | _0x59b81a = str(_0x59b81a) + chr(_0x2c0540) |
---|
96 | if _0x3b6833 != 64: |
---|
97 | _0x59b81a = str(_0x59b81a) + chr(_0x5a46ef) |
---|
98 | |
---|
99 | return _0x59b81a |
---|
100 | |
---|
101 | def get_url(self, host, media_id): |
---|
102 | return 'http://%s/embed/%s' % (host, media_id) |
---|
103 | |
---|
104 | sys.stdout = StreamangoResolver() |
---|