Ivars пре 5 година
родитељ
комит
c367cf4dd7
3 измењених фајлова са 74 додато и 2431 уклоњено
  1. 14
    4
      ltcproxy.py
  2. 60
    0
      mtwsgi.py
  3. 0
    2427
      project.wpr

+ 14
- 4
ltcproxy.py Прегледај датотеку

@@ -50,6 +50,7 @@ SERVER = "wsgiref"
50 50
 WORKERS = 10
51 51
 LTC_USER = "user"
52 52
 LTC_PASSWORD = "password"
53
+UID = "5136baee57505694"
53 54
 
54 55
 if not os.path.exists(proxy_cfg_file):
55 56
     config.add_section("ltcproxy")
@@ -442,7 +443,10 @@ def get_epg(ch, start):
442 443
 # Run WSGI server
443 444
 def start(server,port):
444 445
     print "*** Starting ltcproxy ***"
445
-    print "LTC_USER: %s"% LTC_USER
446
+    if login(LTC_USER, LTC_PASSWORD):
447
+        print "Logged in, user: %s" % LTC_USER
448
+    else:
449
+        print "Can not login %s" % (LTC_USER)
446 450
     options = {}
447 451
     if server == "mtwsgi":
448 452
         import mtwsgi
@@ -463,7 +467,7 @@ def login(user,password):
463 467
 
464 468
     # Dabūjam tokenu
465 469
     url = "https://manstv.lattelecom.tv/api/v1.7/post/user/users/%s" % user
466
-    params = "uid=5136baee57505694&password=%s&" % (password)
470
+    params = "uid=UID&password=%s&" % (password)
467 471
     headers = headers2dict("""
468 472
 User-Agent: Shortcut.lv v2.9.1 / Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-G900FD Build/KOT49H)
469 473
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
@@ -475,18 +479,24 @@ Host: manstv.lattelecom.tv
475 479
         content = u.read()
476 480
         u.close()
477 481
     except Exception as ex:
482
+        if DEBUG:
483
+            print "Login error: %s - %s" % (ex.code, ex.msg)
484
+            print ex.hdrs
478 485
         return None
479
-    if r and "token" in content:
486
+    if u and "token" in content:
480 487
         token = re.search('"token":"(.+?)"', content).group(1)
481 488
         return token
482 489
     else:
490
+        if DEBUG:
491
+            print "Error searching token in response"
492
+            print content
483 493
         return False
484 494
 
485 495
 def refresh_token(token):
486 496
     """Refresh"""
487 497
 
488 498
     url = "https://manstv.lattelecom.tv/api/v1.7/post/user/refresh-token/"
489
-    params = "uid=5136baee57505694&token=%s&" % (token)
499
+    params = "uid=UID&token=%s&" % (token)
490 500
     headers = headers2dict("""
491 501
 User-Agent: Shortcut.lv v2.9.1 / Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-G900FD Build/KOT49H)
492 502
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8

+ 60
- 0
mtwsgi.py Прегледај датотеку

@@ -0,0 +1,60 @@
1
+'''
2
+WSGI-compliant HTTP server.  Dispatches requests to a pool of threads.
3
+https://github.com/RonRothman/mtwsgi
4
+'''
5
+
6
+from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
7
+import multiprocessing.pool
8
+
9
+__all__ = ['ThreadPoolWSGIServer', 'make_server']
10
+
11
+import bottle
12
+
13
+class ThreadPoolWSGIServer(WSGIServer):
14
+    '''WSGI-compliant HTTP server.  Dispatches requests to a pool of threads.'''
15
+
16
+    def __init__(self, thread_count=None, *args, **kwargs):
17
+        '''If 'thread_count' == None, we'll use multiprocessing.cpu_count() threads.'''
18
+        WSGIServer.__init__(self, *args, **kwargs)
19
+        self.thread_count = thread_count
20
+        self.pool = multiprocessing.pool.ThreadPool(self.thread_count)
21
+
22
+    # Inspired by SocketServer.ThreadingMixIn.
23
+    def process_request_thread(self, request, client_address):
24
+        try:
25
+            self.finish_request(request, client_address)
26
+            self.shutdown_request(request)
27
+        except:
28
+            self.handle_error(request, client_address)
29
+            self.shutdown_request(request)
30
+
31
+    def process_request(self, request, client_address):
32
+        self.pool.apply_async(self.process_request_thread, args=(request, client_address))
33
+
34
+
35
+def make_server(host, port, app, thread_count=None, handler_class=WSGIRequestHandler):
36
+    '''Create a new WSGI server listening on `host` and `port` for `app`'''
37
+    httpd = ThreadPoolWSGIServer(thread_count, (host, port), handler_class)
38
+    httpd.set_app(app)
39
+    return httpd
40
+
41
+
42
+class MTServer(bottle.ServerAdapter):
43
+    def run(self, handler):
44
+        thread_count = self.options.pop('thread_count', None)
45
+        server = make_server(self.host, self.port, handler, thread_count, **self.options)
46
+        try:
47
+            server.serve_forever()
48
+        except KeyboardInterrupt:
49
+            server.server_close()  # Prevent ResourceWarning: unclosed socket
50
+            raise
51
+
52
+if __name__ == '__main__':
53
+    from wsgiref.simple_server import demo_app
54
+    httpd = make_server('', 8000, demo_app)
55
+    sa = httpd.socket.getsockname()
56
+    print "Serving HTTP on", sa[0], "port", sa[1], "..."
57
+    import webbrowser
58
+    webbrowser.open('http://localhost:8000/xyz?abc')
59
+    httpd.serve_forever()
60
+

+ 0
- 2427
project.wpr
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку