source: titan/mediathek/localhoster/lib/ol_gmu.py @ 39352

Last change on this file since 39352 was 39352, checked in by obi, 5 years ago

fix flashx.py

File size: 4.8 KB
Line 
1# -*- coding: utf-8 -*-
2"""
3openload.io urlresolver plugin
4Copyright (C) 2015 tknorris
5
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18"""
19import urllib
20import re
21import urllib2
22from aa_decoder import AADecoder
23from jjdecode import JJDecoder
24from HTMLParser import HTMLParser
25from net import Net
26
27net = Net()
28MAX_SIZE = 33 * 1024 * 1024
29MIN_SIZE = 30 * 1024 * 1024
30
31def caesar_shift(s, shift=13):
32    s2 = ''
33    for c in s:
34        if c.isalpha():
35            limit = 90 if c <= 'Z' else 122
36            new_code = ord(c) + shift
37            if new_code > limit:
38                new_code -= 26
39            s2 += chr(new_code)
40        else:
41            s2 += c
42    return s2
43
44def unpack(html):
45    strings = re.findall('{\s*var\s+a\s*=\s*"([^"]+)', html)
46    shifts = re.findall('\)\);}\((\d+)\)', html)
47    for s, shift in zip(strings, shifts):
48        s = caesar_shift(s, int(shift))
49        s = urllib.unquote(s)
50        for i, replace in enumerate(['j', '_', '__', '___']):
51            s = s.replace(str(i), replace)
52        html += '<script>%s</script>' % (s)
53    return html
54
55def get_media_url(url):
56    try:
57        HTTP_HEADER = {
58            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0',
59            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
60            'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
61            'Accept-Encoding': 'none',
62            'Accept-Language': 'en-US,en;q=0.8',
63            'Referer': url}  # 'Connection': 'keep-alive'
64
65        html = net.http_GET(url, headers=HTTP_HEADER).content
66        try: html = html.encode('utf-8')
67        except: pass
68        html = unpack(html)
69       
70        decodes = []
71        hidden_id = ''
72        for match in re.finditer('<script[^>]*>(.*?)</script>', html, re.DOTALL):
73            decode = ''
74            encoded = match.group(1)
75            match = re.search("(゚ω゚ノ.*?\('_'\);)", encoded, re.DOTALL)
76            if match:
77                decode = AADecoder(match.group(1)).decode()
78                decodes.append(decode)
79               
80            match = re.search('(.=~\[\].*\(\);)', encoded, re.DOTALL)
81            if match:
82                decode = JJDecoder(match.group(1)).decode()
83                decodes.append(decode)
84           
85            match = re.search(r'=\s*\$\("#([^"]+)"', decode, re.DOTALL | re.IGNORECASE)
86            if match:
87                hidden_id = match.group(1)
88
89        if not hidden_id:
90            print 'Hidden ID Not Found. Deleted?'
91
92        hidden_url = ''       
93        match = re.search(r'<span[^>]+id\s*="%s"[^>]*>([^<]+)' % (hidden_id), html, re.DOTALL | re.IGNORECASE)
94        if match:
95            hidden_url = match.group(1)
96        else:
97            print 'Stream Url Not Found. Deleted?'
98
99        if not decodes:
100            print 'No Encoded Section Found. Deleted?'
101       
102        hiddenurl = HTMLParser().unescape(hidden_url)
103        magic_number = 0
104        for decode in decodes:
105            match = re.search('charCodeAt\(\d+\)\s*\+\s*(\d+)\)', decode, re.DOTALL | re.I)
106            if match:
107                magic_number = match.group(1)
108                break
109
110        s = []
111        for idx, i in enumerate(hiddenurl):
112            j = ord(i)
113            if (j >= 33 & j <= 126):
114                j = 33 + ((j + 14) % 94)
115               
116            if idx == len(hiddenurl) - 1:
117                j += int(magic_number)
118            s.append(chr(j))
119        res = ''.join(s)
120       
121        videoUrl = 'https://openload.co/stream/{0}?mime=true'.format(res)
122        dtext = videoUrl.replace('https', 'http')
123        headers = {'User-Agent': HTTP_HEADER['User-Agent']}
124        req = urllib2.Request(dtext, None, headers)
125        res = urllib2.urlopen(req)
126        videourl = res.geturl()
127        if MIN_SIZE < int(res.headers['Content-Length']) < MAX_SIZE:
128            print 'Openload.co resolve failed. Pigeons? (%s)' % (res.headers['Content-Length'])
129        res.close()
130       
131        return videourl
132    except Exception as e:
133#        common.log_utils.log_debug('Exception during openload resolve parse: %s' % e)
134        raise
135
136    print 'Unable to resolve openload.io link. Filelink not found.'
Note: See TracBrowser for help on using the repository browser.