1 | |
---|
2 | import re, time |
---|
3 | from lib import jsunpack |
---|
4 | import sys |
---|
5 | from lib.net import Net |
---|
6 | import lib.common as common |
---|
7 | |
---|
8 | class FlashxResolver(object): |
---|
9 | name = "flashx" |
---|
10 | domains = ["flashx.tv"] |
---|
11 | pattern = '(?://|\.)(flashx\.tv)/(?:embed-|dl\?|embed.php\?c=)?([0-9a-zA-Z/-]+)' |
---|
12 | |
---|
13 | def __init__(self): |
---|
14 | self.net = Net() |
---|
15 | url = str(sys.argv[1]) |
---|
16 | host = self.get_host_and_id(url)[0] |
---|
17 | media_id = self.get_host_and_id(url)[1] |
---|
18 | |
---|
19 | return self.get_media_url(host, media_id) |
---|
20 | |
---|
21 | def get_host_and_id(self, url): |
---|
22 | r = re.search(self.pattern, url, re.I) |
---|
23 | if r: |
---|
24 | return r.groups() |
---|
25 | else: |
---|
26 | return False |
---|
27 | |
---|
28 | def get_media_url(self, host, media_id): |
---|
29 | web_url = self.get_url(host, media_id) |
---|
30 | resp = self.net.http_GET(web_url) |
---|
31 | html = resp.content |
---|
32 | cfdcookie = resp._response.info()['set-cookie'] |
---|
33 | cfduid = re.search('cfduid=(.*?);', cfdcookie).group(1) |
---|
34 | file_id = re.search("'file_id', '(.*?)'", html).group(1) |
---|
35 | aff = re.search("'aff', '(.*?)'", html).group(1) |
---|
36 | headers = {'User-Agent': common.IE_USER_AGENT, |
---|
37 | 'Referer': web_url, |
---|
38 | 'Cookie': '__cfduid=' + cfduid + '; lang=1'} |
---|
39 | surl = re.search('src="(.*?' + file_id + ')', html, re.IGNORECASE).group(1) |
---|
40 | dummy = self.net.http_GET(url=surl, headers=headers).content |
---|
41 | headers = {'User-Agent': common.IE_USER_AGENT, |
---|
42 | 'Referer': web_url, |
---|
43 | 'Cookie': '__cfduid=' + cfduid + '; lang=1; file_id=' + file_id + '; aff=' + aff} |
---|
44 | html = self.net.http_GET(url=web_url, headers=headers).content |
---|
45 | fname = re.search('name="fname" value="(.*?)"', html).group(1) |
---|
46 | hash = re.search('name="hash" value="(.*?)"', html).group(1) |
---|
47 | fdata = {'op': 'download1', |
---|
48 | 'usr_login': '', |
---|
49 | 'id': media_id, |
---|
50 | 'fname': fname, |
---|
51 | 'referer': '', |
---|
52 | 'hash': hash, |
---|
53 | 'imhuman': 'Proceed to video'} |
---|
54 | furl = 'http://www.flashx.tv/dl'# + media_id |
---|
55 | time.sleep(5) |
---|
56 | html = self.net.http_POST(url=furl, form_data=fdata, headers=headers).content |
---|
57 | |
---|
58 | js_data = re.findall('(eval\(function.*?)</script>', html.replace('\n', '')) |
---|
59 | |
---|
60 | for i in js_data: |
---|
61 | try: html += jsunpack.unpack(i) |
---|
62 | except: pass |
---|
63 | |
---|
64 | print self.get_best_source(html) |
---|
65 | |
---|
66 | def get_url(self, host, media_id): |
---|
67 | return 'http://www.flashx.tv/%s.html' % media_id |
---|
68 | |
---|
69 | |
---|
70 | def get_best_source(self, html): |
---|
71 | stream = re.search('file:"([^"]*/high.*)",label', html) |
---|
72 | if stream: |
---|
73 | return re.search('file:"([^"]*/high.*)",label', html).group(1) |
---|
74 | else: |
---|
75 | stream = re.search('file:"([^"]*/normal.*)",label', html) |
---|
76 | if stream: |
---|
77 | return re.search('file:"([^"]*/normal.*)",label', html).group(1) |
---|
78 | else: |
---|
79 | stream = re.search('file:"([^"]*/low.*)",label', html) |
---|
80 | if stream: |
---|
81 | return re.search('file:"([^"]*/low.*)",label', html).group(1) |
---|
82 | else: |
---|
83 | stream = re.search('file:"([^"]*)",label', html) |
---|
84 | if stream: |
---|
85 | return re.search('file:"([^"]*)",label', html).group(1) |
---|
86 | |
---|
87 | sys.stdout = FlashxResolver() |
---|