Ivars 4 years ago
parent
commit
e01410dd1f
1 changed files with 23 additions and 42 deletions
  1. 23
    42
      ltcproxy.py

+ 23
- 42
ltcproxy.py View File

12
 __version__ = "0.1b"
12
 __version__ = "0.1b"
13
 
13
 
14
 import os, sys, time
14
 import os, sys, time
15
-import urllib
15
+import urllib,urlparse, urllib2, requests
16
 from urllib import unquote, quote
16
 from urllib import unquote, quote
17
-import urlparse
18
-import requests
19
-import re
20
-import json
17
+import re, json
21
 import ConfigParser, getopt
18
 import ConfigParser, getopt
22
 import arrow
19
 import arrow
23
 from diskcache import Cache
20
 from diskcache import Cache
24
 import daemonize
21
 import daemonize
25
 import bottle
22
 import bottle
26
 from bottle import Bottle, hook, response, route, request, run
23
 from bottle import Bottle, hook, response, route, request, run
27
-import urllib3
28
-urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
29
-
30
 
24
 
31
 cunicode = lambda s: s.decode("utf8") if isinstance(s, str) else s
25
 cunicode = lambda s: s.decode("utf8") if isinstance(s, str) else s
32
 cstr = lambda s: s.encode("utf8") if isinstance(s, unicode) else s
26
 cstr = lambda s: s.encode("utf8") if isinstance(s, unicode) else s
480
 Host: manstv.lattelecom.tv
474
 Host: manstv.lattelecom.tv
481
 """ )
475
 """ )
482
     try:
476
     try:
483
-        r = requests.post(url, data=params, headers=headers, verify=False)
477
+        r = urllib2.Request(url, data=params, headers=headers)
478
+        u = urllib2.urlopen(r)
479
+        content = u.read()
480
+        u.close()
484
     except Exception as ex:
481
     except Exception as ex:
485
         if DEBUG:
482
         if DEBUG:
486
-            print "Login exception - %s " % (str(ex))
487
-            if "hdrs" in dir(ex):
488
-                print ex.hdrs
489
-        return None
490
-    if not r.ok:
491
-        if DEBUG:
492
-            print "Login error - %s: %s" % (r.status_code, r.reason)
483
+            print "Login error: %s - %s" % (ex.code, ex.msg)
484
+            print ex.hdrs
493
         return None
485
         return None
494
-
495
-    content = r.content
496
-    if not "token" in content:
486
+    if u and "token" in content:
487
+        token = re.search('"token":"(.+?)"', content).group(1)
488
+        return token
489
+    else:
497
         if DEBUG:
490
         if DEBUG:
498
             print "Error searching token in response"
491
             print "Error searching token in response"
499
             print content
492
             print content
500
-        return None
501
-    token = re.search('"token":"(.+?)"', content).group(1)
502
-    return token
503
-
493
+        return False
504
 
494
 
505
 def refresh_token(token):
495
 def refresh_token(token):
506
     """Refresh"""
496
     """Refresh"""
511
 User-Agent: Shortcut.lv v2.9.1 / Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-G900FD Build/KOT49H)
501
 User-Agent: Shortcut.lv v2.9.1 / Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-G900FD Build/KOT49H)
512
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
502
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
513
 Host: manstv.lattelecom.tv
503
 Host: manstv.lattelecom.tv
514
-""")
504
+""" )
515
     try:
505
     try:
516
-        r = requests.post(url, data=params, headers=headers, verify = False)
506
+        r = urllib2.Request(url, data=params, headers=headers)
507
+        u = urllib2.urlopen(r)
508
+        content = u.read()
509
+        u.close()
517
     except Exception as ex:
510
     except Exception as ex:
518
-        if DEBUG:
519
-            print "Login exception - %s " % (str(ex))
520
-            if "hdrs" in dir(ex):
521
-                print ex.hdrs
522
-        return None
523
-    if not r.ok:
524
-        if DEBUG:
525
-            print "Login error - %s: %s" % (r.status_code, r.reason)
526
         return None
511
         return None
527
-
528
-    content = r.content
529
-    if not "token" in content:
530
-        if DEBUG:
531
-            print "Error searching token in response"
532
-            print content
533
-        return None
534
-    token2 = re.search('"token":"(.+?)"', content).group(1)
535
-    return token2
512
+    if r and "token" in content:
513
+        token2 = re.search('"token":"(.+?)"', content).group(1)
514
+        return token2
515
+    else:
516
+        return False
536
 
517
 
537
 def print_headers(headers):
518
 def print_headers(headers):
538
     for h in headers:
519
     for h in headers: