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

Add argument to specify custom save path

Cammy 6 роки тому
батько
коміт
4fd1d06f8e
3 змінених файлів з 23 додано та 7 видалено
  1. 1 1
      pyinstalive/downloader.py
  2. 20 5
      pyinstalive/initialize.py
  3. 2 1
      pyinstalive/settings.py

+ 1 - 1
pyinstalive/downloader.py

@@ -72,7 +72,7 @@ def start_multiple(instagram_api_arg, settings_arg, proc_arg):
 						if settings_arg.custom_ini_path == 'pyinstalive.ini':
 							start_result = run_command("{:s} -d {:s}".format(proc_arg, user))
 						else:
-							start_result = run_command("{:s} -d {:s} -ip '{:s}'".format(proc_arg, user, settings_arg.custom_ini_path))
+							start_result = run_command("{:s} -d {:s} -ip '{:s}' -sp '{:s}'".format(proc_arg, user, settings_arg.custom_ini_path, settings_arg.save_path))
 						if start_result:
 							log_info_green("Could not start processs: {:s}".format(str(start_result)))
 						else:

+ 20 - 5
pyinstalive/initialize.py

@@ -37,7 +37,7 @@ def check_pyinstalive():
 		return False
 
 
-def check_config_validity(config):
+def check_config_validity(config, args=None):
 	try:
 		has_thrown_errors = False
 		settings.username = config.get('pyinstalive', 'username')
@@ -145,7 +145,19 @@ def check_config_validity(config):
 			has_thrown_errors = True
 
 		try:
-			settings.save_path = config.get('pyinstalive', 'save_path')
+			if args:
+				if (args.savepath) and (os.path.exists(args.savepath)) and (args.savepath != config.get('pyinstalive', 'save_path')):
+					settings.save_path = args.savepath
+					log_info_blue("Overriding save path: {:s}".format(args.savepath))
+					log_seperator()
+				elif args.savepath != config.get('pyinstalive', 'save_path'):
+					log_warn("Custom save path does not exist, falling back to path specified in config.")
+					settings.save_path = config.get('pyinstalive', 'save_path')
+					log_seperator()
+				else:
+					settings.save_path = config.get('pyinstalive', 'save_path')
+			else:
+				settings.save_path = config.get('pyinstalive', 'save_path')
 
 			if (os.path.exists(settings.save_path)):
 				pass
@@ -373,6 +385,7 @@ def run():
 	parser.add_argument('-cl', '--clean', dest='clean', action='store_true', help="PyInstaLive will clean the current download folder of all leftover files.")
 	parser.add_argument('-df', '--downloadfollowing', dest='downloadfollowing', action='store_true', help="PyInstaLive will check for available livestreams and replays from users the account used to login follows.")
 	parser.add_argument('-ip', '--inipath', dest='inipath', type=str, required=False, help="Path to a PyInstaLive configuration file.")
+	parser.add_argument('-sp', '--savepath', dest='savepath', type=str, required=False, help="Path to folder where PyInstaLive should save livestreams and replays.")
 
 	# Workaround to 'disable' argument abbreviations
 	parser.add_argument('--usernamx', help=argparse.SUPPRESS, metavar='IGNORE')
@@ -423,7 +436,7 @@ def run():
 		log_info_blue("Overriding config path: {:s}".format(args.inipath))
 		log_seperator()
 	elif args.inipath and settings.custom_ini_path == 'pyinstalive.ini':
-		log_warn("Custom config path does not exist, falling back to default folder: {:s}".format(os.getcwd()))
+		log_warn("Custom config path does not exist, falling back to path: {:s}".format(os.getcwd()))
 		log_seperator()
 
 	if unknown_args:
@@ -447,7 +460,9 @@ def run():
 	args.config and not
 	args.noreplays and not
 	args.nolives and not
-	args.clean):
+	args.clean and not
+	args.inipath and not
+	args.savepath):
 		show_info(config)
 		sys.exit(0)
 	
@@ -466,7 +481,7 @@ def run():
 		sys.exit(1)
 
 
-	if check_config_validity(config):
+	if check_config_validity(config, args):
 		try:
 			if (args.clean):
 				clean_download_dir()

+ 2 - 1
pyinstalive/settings.py

@@ -1,10 +1,11 @@
 import time
+import os
 
 class settings:
 	user_to_download = ""
 	username = ""
 	password = ""
-	save_path = "/"
+	save_path = os.getcwd()
 	ffmpeg_path = None
 	show_cookie_expiry = "true"
 	clear_temp_files = "false"