ソースを参照

Clarify possible cookie error, added save_replays config entry, bugfixes

Cammy 7 年 前
コミット
059ceaf19a
5 ファイル変更40 行追加18 行削除
  1. 2 1
      .gitignore
  2. 5 1
      pyinstalive/auth.py
  3. 7 1
      pyinstalive/downloader.py
  4. 24 14
      pyinstalive/initialize.py
  5. 2 1
      pyinstalive/settings.py

+ 2 - 1
.gitignore

@@ -25,4 +25,5 @@ wheels/
 *.egg-info/
 .installed.cfg
 *.egg
-MANIFEST
+MANIFEST
+*.json

+ 5 - 1
pyinstalive/auth.py

@@ -80,7 +80,11 @@ def login(username, password, show_cookie_expiry):
 		log('[E] ClientError: {0!s}'.format(e), "RED")
 		sys.exit(9)
 	except Exception as e:
-		log('[E] Unexpected Exception: {0!s}'.format(e), "RED")
+		if (str(e).startswith("unsupported pickle protocol")):
+			log("[W] This cookie file is not compatible with Python {}.".format(sys.version.split(' ')[0][0]), "YELLOW")
+			log("[W] Please delete your cookie file 'credentials.json' and try again.", "YELLOW")
+		else:
+			log('[E] Unexpected Exception: {0!s}'.format(e), "RED")
 		sys.exit(99)
 
 	log('[I] Login to "' + api.authenticated_user_name + '" OK!', "GREEN")

+ 7 - 1
pyinstalive/downloader.py

@@ -99,7 +99,13 @@ def get_user_info(record):
 		seperator("GREEN")
 		sys.exit(1)
 	get_livestreams(user_id)
-	get_replays(user_id)
+	if settings.save_replays.title() == "True": 
+		get_replays(user_id)
+	else:
+		log("", "BLUE")
+		log("[I] Replay saving is disabled in the config file.", "BLUE")
+		seperator("GREEN")
+		sys.exit(0)
 
 def get_livestreams(user_id):
 	try:

+ 24 - 14
pyinstalive/initialize.py

@@ -34,22 +34,32 @@ def check_config_validity(config):
 		try:
 			settings.show_cookie_expiry = config.get('pyinstalive', 'show_cookie_expiry').title()
 			if not settings.show_cookie_expiry in bool_values:
-				log("[W] Invalid setting detected for 'show_cookie_expiry', falling back to default value (True)", "YELLOW")
+				log("[W] Invalid or missing setting detected for 'show_cookie_expiry', using default value (True)", "YELLOW")
 				settings.show_cookie_expiry = 'true'
 		except:
-			log("[W] Invalid setting detected for 'show_cookie_expiry', falling back to default value (True)", "YELLOW")
+			log("[W] Invalid or missing setting detected for 'show_cookie_expiry', using default value (True)", "YELLOW")
 			settings.show_cookie_expiry = 'true'
 
 
 
 		try:
 			settings.clear_temp_files = config.get('pyinstalive', 'clear_temp_files').title()
-			if not settings.show_cookie_expiry in bool_values:
-				log("[W] Invalid setting detected for 'clear_temp_files', falling back to default value (True)", "YELLOW")
-				settings.show_cookie_expiry = 'true'
+			if not settings.clear_temp_files in bool_values:
+				log("[W] Invalid or missing setting detected for 'clear_temp_files', using default value (True)", "YELLOW")
+				settings.clear_temp_files = 'true'
 		except:
-			log("[W] Invalid setting detected for 'clear_temp_files', falling back to default value (True)", "YELLOW")
-			settings.show_cookie_expiry = 'true'
+			log("[W] Invalid or missing setting detected for 'clear_temp_files', using default value (True)", "YELLOW")
+			settings.clear_temp_files = 'true'
+
+
+		try:
+			settings.save_replays = config.get('pyinstalive', 'save_replays').title()
+			if not settings.save_replays in bool_values:
+				log("[W] Invalid or missing setting detected for 'save_replays', using default value (True)", "YELLOW")
+				settings.save_replays = 'true'
+		except:
+			log("[W] Invalid or missing setting detected for 'save_replays', using default value (True)", "YELLOW")
+			settings.save_replays = 'true'
 
 
 
@@ -59,21 +69,21 @@ def check_config_validity(config):
 			if (os.path.exists(settings.save_path)):
 				pass
 			else:
-				log("[W] Invalid setting detected for 'save_path', falling back to location: " + os.getcwd(), "YELLOW")
+				log("[W] Invalid or missing setting detected for 'save_path', falling back to path: " + os.getcwd(), "YELLOW")
 				settings.save_path = os.getcwd()
 
 			if not settings.save_path.endswith('/'):
 				settings.save_path = settings.save_path + '/'
 		except:
-			log("[W] Invalid setting detected for 'save_path', falling back to location: " + os.getcwd(), "YELLOW")
+			log("[W] Invalid or missing setting detected for 'save_path', falling back to path: " + os.getcwd(), "YELLOW")
 			settings.save_path = os.getcwd()
 
 		if not (len(settings.username) > 0):
-			log("[E] Invalid setting detected for 'username'.", "RED")
+			log("[E] Invalid or missing setting detected for 'username'.", "RED")
 			return False
 
 		if not (len(settings.password) > 0):
-			log("[E] Invalid setting detected for 'password'.", "RED")
+			log("[E] Invalid or missing setting detected for 'password'.", "RED")
 			return False
 
 		return True
@@ -122,7 +132,7 @@ def new_config():
 		else:
 			try:
 				log("[W] Could not find configuration file, creating a default one ...", "YELLOW")
-				config_template = "[pyinstalive]\nusername = johndoe\npassword = grapefruits\nsave_path = /\nshow_cookie_expiry = true\nclear_temp_files = false"
+				config_template = "[pyinstalive]\nusername = johndoe\npassword = grapefruits\nsave_path = /\nshow_cookie_expiry = true\nclear_temp_files = false\nsave_replays = true"
 				config_file = open("pyinstalive.ini", "w")
 				config_file.write(config_template)
 				config_file.close()
@@ -139,8 +149,8 @@ def new_config():
 				log("", "GREEN")
 	except Exception as e:
 		log("[E] An error occurred: " + str(e), "RED")
-		log("[W] If you don't have a configuration file,", "YELLOW")
-		log("    you must manually create and edit it with the following template: ", "YELLOW")
+		log("[W] If you don't have a configuration file, you must", "YELLOW")
+		log("    manually create and edit it with the following template: ", "YELLOW")
 		log("", "GREEN")
 		log(config_template, "YELLOW")
 		log("", "GREEN")

+ 2 - 1
pyinstalive/settings.py

@@ -7,4 +7,5 @@ class settings:
 	show_cookie_expiry = "true"
 	clear_temp_files = "false"
 	current_time = str(int(time.time()))
-	current_date = time.strftime("%Y%m%d")
+	current_date = time.strftime("%Y%m%d")
+	save_replays = "true"