Переглянути джерело

Merge pull request #32 from wivb0/proxy

Add proxy support
Cammy 6 роки тому
батько
коміт
ba5155968f
5 змінених файлів з 19 додано та 3 видалено
  1. 5 0
      MOREHELP.md
  2. 3 3
      pyinstalive/auth.py
  3. 1 0
      pyinstalive/constants.py
  4. 2 0
      pyinstalive/pil.py
  5. 8 0
      pyinstalive/startup.py

+ 5 - 0
MOREHELP.md

@@ -45,6 +45,7 @@ run_at_finish =
 use_locks = True
 clear_temp_files = False
 do_heartbeat = True
+proxy = 
 ```
 
 ```username```  **—**  Instagram username to login with.
@@ -74,3 +75,7 @@ do_heartbeat = True
 ```clear_temp_files```  **—**  When set to True, PyInstaLive will delete all temporary files that were downloaded as well as the folders which contained these files. Replay folders created by PyInstaLive will not be deleted because they are used to determine if a replay has already been downloaded.
 
 ```do_heartbeat```  **—**  When set to True, PyInstaLive will check the livestream's active status. If set to False no checks will be conducted, and the logged in user will not show up as a viewer during the livestream. May cause degraded performance.
+
+```proxy```  **—**  When set, PyInstaLive will use the specified HTTP proxy. The format should be similar to http://user:pass@proxy.com:12345
+
+

+ 3 - 3
pyinstalive/auth.py

@@ -60,7 +60,7 @@ def authenticate(username, password, force_use_login_args=False):
             # login new
             ig_api = Client(
                 username, password,
-                on_login=lambda x: onlogin_callback(x, cookie_file))
+                on_login=lambda x: onlogin_callback(x, cookie_file), proxy=pil.proxy)
         else:
             with open(cookie_file) as file_data:
                 cached_settings = json.load(file_data, object_hook=from_json)
@@ -71,7 +71,7 @@ def authenticate(username, password, force_use_login_args=False):
             try:
                 ig_api = Client(
                     username, password,
-                    settings=cached_settings)
+                    settings=cached_settings, proxy=pil.proxy)
 
             except ClientCookieExpiredError as e:
                 logger.warn('The current cookie file has expired, creating a new one.')
@@ -79,7 +79,7 @@ def authenticate(username, password, force_use_login_args=False):
                 ig_api = Client(
                     username, password,
                     device_id=device_id,
-                    on_login=lambda x: onlogin_callback(x, cookie_file))
+                    on_login=lambda x: onlogin_callback(x, cookie_file), proxy=pil.proxy)
 
     except (ClientLoginError, ClientError) as e:
         logger.separator()

+ 1 - 0
pyinstalive/constants.py

@@ -20,4 +20,5 @@ run_at_finish =
 use_locks = True
 clear_temp_files = False
 do_heartbeat = False
+proxy =
     """

+ 2 - 0
pyinstalive/pil.py

@@ -43,6 +43,7 @@ def initialize():
     global clear_temp_files
     global has_guest
     global do_heartbeat
+    global proxy
     ig_api = None
     ig_user = ""
     ig_pass = ""
@@ -74,3 +75,4 @@ def initialize():
     clear_temp_files = False
     has_guest = None
     do_heartbeat = False
+    proxy = None

+ 8 - 0
pyinstalive/startup.py

@@ -4,6 +4,7 @@ import os
 import logging
 import platform
 import subprocess
+from urllib.parse import urlparse
 
 try:
     import pil
@@ -82,6 +83,7 @@ def validate_inputs(config, args, unknown_args):
         pil.ffmpeg_path = config.get('pyinstalive', 'ffmpeg_path')
         pil.args = args
         pil.config = config
+        pil.proxy = config.get('pyinstalive', 'proxy', fallback=None)
 
         if args.configpath:
             pil.config_path = args.configpath
@@ -188,6 +190,12 @@ def validate_inputs(config, args, unknown_args):
                 logger.warn("Custom config path is invalid, falling back to default path: {:s}".format(pil.dl_path))
                 logger.separator()
 
+        if pil.proxy != None and pil.proxy != '':
+            parsed_url = urlparse(pil.proxy)
+            if (not parsed_url.netloc or not parsed_url.scheme):
+                error_arr.append(['proxy', 'None'])
+                pil.proxy = None
+
         if error_arr:
             for error in error_arr:
                 logger.warn("Invalid value for '{:s}'. Using default value: {:s}".format(error[0], error[1]))