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

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

fix flashx.py

File size: 3.7 KB
Line 
1"""
2flashx.tv urlresolver plugin
3Copyright (C) 2015 tknorris
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17"""
18import re
19import urlparse
20import urllib
21from lib import helpers
22#from urlresolver import common
23#from urlresolver.resolver import ResolverError
24from net import Net
25import common
26
27SORT_KEY = {'High': 3, 'Middle': 2, 'Low': 1}
28#net = common.Net()
29net = Net()
30
31def get_media_url(url):
32    try:
33        hostname = urlparse.urlparse(url).hostname
34        headers = {'User-Agent': common.FF_USER_AGENT}
35        html = net.http_GET(url, headers=headers).content
36        headers.update({'Referer': url})
37        for match in re.finditer('''<script[^>]*src=["']([^'"]+)''', html):
38            _html = get_js(match.group(1), headers, hostname)
39               
40        match = re.search('''href=['"]([^'"]+)''', html)
41        if match:
42            playvid_url = match.group(1)
43            html = net.http_GET(playvid_url, headers=headers).content
44            headers.update({'Referer': playvid_url})
45            for match in re.finditer('''<script[^>]*src=["']([^'"]+)''', html):
46                js = get_js(match.group(1), headers, hostname)
47                match = re.search('''!=\s*null.*?get\(['"]([^'"]+).*?\{([^:]+)''', js, re.DOTALL)
48                if match:
49                    fx_url, fx_param = match.groups()
50                    fx_url = resolve_url(urlparse.urljoin('http://www.flashx.tv', fx_url) + '?' + urllib.urlencode({fx_param: 1}))
51#                    common.log_utils.log('fxurl: %s' % (fx_url))
52                    _html = net.http_GET(fx_url, headers=headers).content
53                   
54            headers.update({'Referer': url})
55            html = net.http_GET(playvid_url, headers=headers).content
56            html = helpers.add_packed_data(html)
57       
58#        common.log_utils.log(html)
59        sources = helpers.parse_sources_list(html)
60        try: sources.sort(key=lambda x: SORT_KEY.get(x[0], 0), reverse=True)
61        except: pass
62        source = helpers.pick_source(sources)
63        return source + helpers.append_headers(headers)
64       
65    except Exception as e:
66#        common.log_utils.log_debug('Exception during flashx resolve parse: %s' % e)
67        raise
68   
69    raise ResolverError('Unable to resolve flashx link. Filelink not found.')
70
71def get_js(js_url, headers, hostname):
72    js = ''
73    if not js_url.startswith('http'):
74        base_url = 'http://' + hostname
75        js_url = urlparse.urljoin(base_url, js_url)
76   
77    if hostname in js_url:
78#        common.log_utils.log('Getting JS: |%s| - |%s|' % (js_url, headers))
79        js = net.http_GET(js_url, headers=headers).content
80    return js
81   
82def resolve_url(url):
83    parts = list(urlparse.urlsplit(url))
84    segments = parts[2].split('/')
85    segments = [segment + '/' for segment in segments[:-1]] + [segments[-1]]
86    resolved = []
87    for segment in segments:
88        if segment in ('../', '..'):
89            if resolved[1:]:
90                resolved.pop()
91        elif segment not in ('./', '.'):
92            resolved.append(segment)
93    parts[2] = ''.join(resolved)
94    return urlparse.urlunsplit(parts)
Note: See TracBrowser for help on using the repository browser.