1 | """
|
---|
2 | flashx.tv urlresolver plugin
|
---|
3 | Copyright (C) 2015 tknorris
|
---|
4 |
|
---|
5 | This program is free software: you can redistribute it and/or modify
|
---|
6 | it under the terms of the GNU General Public License as published by
|
---|
7 | the Free Software Foundation, either version 3 of the License, or
|
---|
8 | (at your option) any later version.
|
---|
9 |
|
---|
10 | This program is distributed in the hope that it will be useful,
|
---|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | GNU General Public License for more details.
|
---|
14 |
|
---|
15 | You should have received a copy of the GNU General Public License
|
---|
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | """
|
---|
18 | import re
|
---|
19 | import urlparse
|
---|
20 | import urllib
|
---|
21 | from lib import helpers
|
---|
22 | #from urlresolver import common
|
---|
23 | #from urlresolver.resolver import ResolverError
|
---|
24 | from net import Net
|
---|
25 | import common
|
---|
26 |
|
---|
27 | SORT_KEY = {'High': 3, 'Middle': 2, 'Low': 1}
|
---|
28 | #net = common.Net()
|
---|
29 | net = Net()
|
---|
30 |
|
---|
31 | def 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 |
|
---|
71 | def 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 |
|
---|
82 | def 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)
|
---|