source: titan/mediathek/localhoster/streamango.py @ 41179

Last change on this file since 41179 was 41179, checked in by obi, 4 years ago

streamago add file not found msg

File size: 4.2 KB
Line 
1
2import sys
3from lib.net import Net
4
5import re, urllib, json
6from lib import helpers
7import lib.common as common
8
9class 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 'errormsg=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#        print "html", html.encode('utf8')
53
54        if html:
55            if re.search('>Sorry!<', html):
56                print "errormsg=Sorry!\n%s" % (str(re.compile('<p class="lead">*(.+?)</p>').findall(html)[0]))
57#                print 'errormsg=File was deleted.'
58            else:
59                encoded = re.search('''srces\.push\({type:"video/mp4",src:\w+\('([^']+)',(\d+)''', html)
60                if encoded:
61                    source = self.decode(encoded.group(1), int(encoded.group(2)))
62                    if source:
63                        source = "http:%s" % source if source.startswith("//") else source
64                        source = source.split("/")
65                        if not source[-1].isdigit():
66                          source[-1] = re.sub('[^\d]', '', source[-1])
67                        source = "/".join(source)
68                        headers.update({'Referer': web_url})
69#                        return source + helpers.append_headers(headers)
70                        print source + helpers.append_headers(headers)
71       
72#        raise ResolverError("Unable to locate video")
73                else:
74                    print 'errormsg=Unable to locate encoded video'
75        else:
76            print 'errormsg=Error 404 Website not found !'
77
78#<h1 style="text-align: center !important;">Sorry!</h1>
79#<p class="lead">We are unable to find the video you're looking for. There could be several reasons for this, for example it got removed by the owner.</p>
80#</div>
81#</div>
82
83    def decode(self, encoded, code):
84        _0x59b81a = ""
85        k = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
86        k = k[::-1]
87
88        count = 0
89
90        for index in range(0, len(encoded) - 1):
91            while count <= len(encoded) - 1:
92                _0x4a2f3a = k.index(encoded[count])
93                count += 1
94                _0x29d5bf = k.index(encoded[count])
95                count += 1
96                _0x3b6833 = k.index(encoded[count])
97                count += 1
98                _0x426d70 = k.index(encoded[count])
99                count += 1
100
101                _0x2e4782 = ((_0x4a2f3a << 2) | (_0x29d5bf >> 4))
102                _0x2c0540 = (((_0x29d5bf & 15) << 4) | (_0x3b6833 >> 2))
103                _0x5a46ef = ((_0x3b6833 & 3) << 6) | _0x426d70
104                _0x2e4782 = _0x2e4782 ^ code
105
106                _0x59b81a = str(_0x59b81a) + chr(_0x2e4782)
107
108                if _0x3b6833 != 64:
109                    _0x59b81a = str(_0x59b81a) + chr(_0x2c0540)
110                if _0x3b6833 != 64:
111                    _0x59b81a = str(_0x59b81a) + chr(_0x5a46ef)
112
113        return _0x59b81a
114
115    def get_url(self, host, media_id):
116        return 'http://%s/embed/%s' % (host, media_id)
117
118sys.stdout = StreamangoResolver()
Note: See TracBrowser for help on using the repository browser.