source: titan/mediathek/localhoster/flashx.py @ 41179

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

[tithek] hoster fix flashx

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