[38996] | 1 | |
---|
| 2 | import re, time |
---|
| 3 | from lib import jsunpack |
---|
| 4 | import sys |
---|
| 5 | from lib.net import Net |
---|
[39075] | 6 | import lib.common as common |
---|
[39352] | 7 | import lib.fx_gmu as fx_gmu |
---|
| 8 | import lib.fx_gmu as fx_gmu |
---|
[38996] | 9 | |
---|
[39352] | 10 | FX_SOURCE = 'https://offshoregit.com/tvaresolvers/fx_gmu.py' |
---|
| 11 | FX_PATH = '' |
---|
| 12 | |
---|
[38996] | 13 | class FlashxResolver(object): |
---|
| 14 | name = "flashx" |
---|
| 15 | domains = ["flashx.tv"] |
---|
| 16 | pattern = '(?://|\.)(flashx\.tv)/(?:embed-|dl\?|embed.php\?c=)?([0-9a-zA-Z/-]+)' |
---|
| 17 | |
---|
| 18 | def __init__(self): |
---|
| 19 | self.net = Net() |
---|
| 20 | url = str(sys.argv[1]) |
---|
| 21 | host = self.get_host_and_id(url)[0] |
---|
| 22 | media_id = self.get_host_and_id(url)[1] |
---|
| 23 | |
---|
| 24 | return self.get_media_url(host, media_id) |
---|
| 25 | |
---|
| 26 | def get_host_and_id(self, url): |
---|
| 27 | r = re.search(self.pattern, url, re.I) |
---|
| 28 | if r: |
---|
| 29 | return r.groups() |
---|
| 30 | else: |
---|
| 31 | return False |
---|
| 32 | |
---|
[39352] | 33 | def get_fx_code(self): |
---|
| 34 | try: |
---|
| 35 | headers = self.net.http_HEAD(FX_SOURCE).get_headers(as_dict=True) |
---|
| 36 | old_etag = self.get_setting('etag') |
---|
| 37 | new_etag = headers.get('Etag', '') |
---|
| 38 | old_len = self.__old_length() |
---|
| 39 | new_len = int(headers.get('Content-Length', 0)) |
---|
| 40 | if old_etag != new_etag or old_len != new_len: |
---|
| 41 | self.set_setting('etag', new_etag) |
---|
| 42 | new_py = self.net.http_GET(FX_SOURCE).content |
---|
| 43 | if new_py: |
---|
| 44 | with open(FX_PATH, 'w') as f: |
---|
| 45 | f.write(new_py) |
---|
| 46 | else: |
---|
| 47 | print 'Reusing existing fx_gmu.py: |%s|%s|%s|%s|' % (old_etag, new_etag, old_len, new_len) |
---|
| 48 | except Exception as e: |
---|
| 49 | print 'Exception during flashx code retrieve: %s' % e |
---|
| 50 | |
---|
| 51 | def __old_length(self): |
---|
| 52 | try: |
---|
| 53 | with open(FX_PATH, 'r') as f: |
---|
| 54 | old_py = f.read() |
---|
| 55 | old_len = len(old_py) |
---|
| 56 | except: |
---|
| 57 | old_len = 0 |
---|
| 58 | return old_len |
---|
| 59 | |
---|
[38996] | 60 | def get_media_url(self, host, media_id): |
---|
[39352] | 61 | # try: |
---|
| 62 | # if self.get_setting('auto_update') == 'true': |
---|
| 63 | # self.get_fx_code() |
---|
| 64 | # with open(FX_PATH, 'r') as f: |
---|
| 65 | # py_data = f.read() |
---|
| 66 | # import fx_gmu |
---|
| 67 | web_url = self.get_url(host, media_id) |
---|
| 68 | print fx_gmu.get_media_url(web_url) |
---|
| 69 | # except Exception as e: |
---|
| 70 | # print 'error' |
---|
| 71 | |
---|
[39076] | 72 | def get_url(self, host, media_id): |
---|
[39352] | 73 | return 'http://%s/embed.php?c=%s' % (host, media_id) |
---|
[39076] | 74 | |
---|
[38996] | 75 | sys.stdout = FlashxResolver() |
---|