Browse Source

Add option to toggle livestream saving

Cammy 7 năm trước cách đây
mục cha
commit
52cd2bde45

+ 6 - 1
MOREHELP.md

@@ -15,6 +15,8 @@
 
 
 - ```-nr``` or ```--noreplays```  **—**  When this argument is passed, PyInstaLive will not download any available replays. Overrides the configuration file.
 - ```-nr``` or ```--noreplays```  **—**  When this argument is passed, PyInstaLive will not download any available replays. Overrides the configuration file.
 
 
+- ```-nl``` or ```--nolives```  **—**  When this argument is passed, PyInstaLive will not download livestreams. Overrides the configuration file.
+
 - ```-cl``` or ```--clean```  **—**  When this argument is passed, PyInstaLive clean the current download folder by deleting folders ending in `_downloads`. Any folders that contain a `folder.lock` file (e.g. folders for ongoing downloads) will be skipped.
 - ```-cl``` or ```--clean```  **—**  When this argument is passed, PyInstaLive clean the current download folder by deleting folders ending in `_downloads`. Any folders that contain a `folder.lock` file (e.g. folders for ongoing downloads) will be skipped.
 
 
 
 
@@ -27,6 +29,7 @@ password = grapefruits
 save_path = 
 save_path = 
 show_cookie_expiry = true
 show_cookie_expiry = true
 clear_temp_files = false
 clear_temp_files = false
+save_lives = true
 save_replays = true
 save_replays = true
 run_at_start =
 run_at_start =
 run_at_finish =
 run_at_finish =
@@ -44,7 +47,9 @@ log_to_file = false
 
 
 ```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.
 ```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.
 
 
-```save_replays```  **—**  When set to True, PyInstaLive will check for and download any available replays.
+```save_lives```  **—**  When set to True, PyInstaLive will download livestreams.
+
+```save_replays```  **—**  When set to True, PyInstaLive will download any available replays.
 
 
 ```run_at_start```  **—**  Command to run when PyInstaLive starts downloading a livestream. Leave empty to disable. (Experimental, use at own risk.)
 ```run_at_start```  **—**  Command to run when PyInstaLive starts downloading a livestream. Leave empty to disable. (Experimental, use at own risk.)
 
 

+ 1 - 0
README.md

@@ -94,6 +94,7 @@ password = grapefruits
 save_path = 
 save_path = 
 show_cookie_expiry = true
 show_cookie_expiry = true
 clear_temp_files = false
 clear_temp_files = false
+save_lives = true
 save_replays = true
 save_replays = true
 run_at_start =
 run_at_start =
 run_at_finish =
 run_at_finish =

+ 11 - 3
pyinstalive/downloader.py

@@ -269,10 +269,16 @@ def get_broadcasts_info(user_id):
 		livestream = broadcasts.get('broadcast')
 		livestream = broadcasts.get('broadcast')
 		replays = broadcasts.get('post_live_item', {}).get('broadcasts', [])
 		replays = broadcasts.get('post_live_item', {}).get('broadcasts', [])
 
 
-		if livestream:
-			download_livestream(livestream)
+		if settings.save_lives.title() == "True":
+			if livestream:
+				download_livestream(livestream)
+			else:
+				log('[I] There are no available livestreams.', "YELLOW")
 		else:
 		else:
-			log('[I] There are no available livestreams.', "YELLOW")
+			seperator("GREEN")
+			log("[I] Livestream saving is disabled either with an argument or in the config file.", "BLUE")
+			
+
 		if settings.save_replays.title() == "True":
 		if settings.save_replays.title() == "True":
 			if replays:
 			if replays:
 				seperator("GREEN")
 				seperator("GREEN")
@@ -282,7 +288,9 @@ def get_broadcasts_info(user_id):
 			else:
 			else:
 				log('[I] There are no available replays.', "YELLOW")
 				log('[I] There are no available replays.', "YELLOW")
 		else:
 		else:
+			seperator("GREEN")
 			log("[I] Replay saving is disabled either with an argument or in the config file.", "BLUE")
 			log("[I] Replay saving is disabled either with an argument or in the config file.", "BLUE")
+
 		seperator("GREEN")
 		seperator("GREEN")
 	except Exception as e:
 	except Exception as e:
 		log('[E] Could not finish checking: {:s}'.format(str(e)), "RED")
 		log('[E] Could not finish checking: {:s}'.format(str(e)), "RED")

+ 29 - 6
pyinstalive/initialize.py

@@ -71,6 +71,17 @@ def check_config_validity(config):
 			settings.save_replays = 'true'
 			settings.save_replays = 'true'
 			has_thrown_errors = True
 			has_thrown_errors = True
 
 
+		try:
+			settings.save_lives = config.get('pyinstalive', 'save_lives').title()
+			if not settings.save_lives in bool_values:
+				log("[W] Invalid or missing setting detected for 'save_lives', using default value (True)", "YELLOW")
+				settings.save_lives = 'true'
+				has_thrown_errors = True
+		except:
+			log("[W] Invalid or missing setting detected for 'save_lives', using default value (True)", "YELLOW")
+			settings.save_lives = 'true'
+			has_thrown_errors = True
+
 
 
 
 
 		try:
 		try:
@@ -234,7 +245,7 @@ def new_config():
 		else:
 		else:
 			try:
 			try:
 				log("[W] Could not find configuration file, creating a default one...", "YELLOW")
 				log("[W] Could not find configuration file, creating a default one...", "YELLOW")
-				config_template = "[pyinstalive]\nusername = johndoe\npassword = grapefruits\nsave_path = {:s}\nshow_cookie_expiry = true\nclear_temp_files = false\nsave_replays = true\nrun_at_start = \nrun_at_finish = \nsave_comments = false\nlog_to_file = false\n".format(os.getcwd())
+				config_template = "[pyinstalive]\nusername = johndoe\npassword = grapefruits\nsave_path = {:s}\nshow_cookie_expiry = true\nclear_temp_files = false\nsave_lives = true\nsave_replays = true\nrun_at_start = \nrun_at_finish = \nsave_comments = false\nlog_to_file = false\n".format(os.getcwd())
 				config_file = open("pyinstalive.ini", "w")
 				config_file = open("pyinstalive.ini", "w")
 				config_file.write(config_template)
 				config_file.write(config_template)
 				config_file.close()
 				config_file.close()
@@ -319,6 +330,7 @@ def run():
 	parser.add_argument('-i', '--info', dest='info', action='store_true', help="View information about PyInstaLive.")
 	parser.add_argument('-i', '--info', dest='info', action='store_true', help="View information about PyInstaLive.")
 	parser.add_argument('-c', '--config', dest='config', action='store_true', help="Create a default configuration file if it doesn't exist.")
 	parser.add_argument('-c', '--config', dest='config', action='store_true', help="Create a default configuration file if it doesn't exist.")
 	parser.add_argument('-nr', '--noreplays', dest='noreplays', action='store_true', help="When used, do not check for any available replays.")
 	parser.add_argument('-nr', '--noreplays', dest='noreplays', action='store_true', help="When used, do not check for any available replays.")
+	parser.add_argument('-nl', '--nolives', dest='nolives', action='store_true', help="When used, do not check for any available livestreams.")
 	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('-cl', '--clean', dest='clean', action='store_true', help="PyInstaLive will clean the current download folder of all leftover files.")
 
 
 	# Workaround to 'disable' argument abbreviations
 	# Workaround to 'disable' argument abbreviations
@@ -330,6 +342,7 @@ def run():
 	parser.add_argument('--noreplayx', help=argparse.SUPPRESS, metavar='IGNORE') 
 	parser.add_argument('--noreplayx', help=argparse.SUPPRESS, metavar='IGNORE') 
 	parser.add_argument('--cleax', help=argparse.SUPPRESS, metavar='IGNORE')
 	parser.add_argument('--cleax', help=argparse.SUPPRESS, metavar='IGNORE')
 	parser.add_argument('-cx', help=argparse.SUPPRESS, metavar='IGNORE')
 	parser.add_argument('-cx', help=argparse.SUPPRESS, metavar='IGNORE')
+	parser.add_argument('-nx', help=argparse.SUPPRESS, metavar='IGNORE')
 
 
 
 
 	args, unknown = parser.parse_known_args()
 	args, unknown = parser.parse_known_args()
@@ -378,6 +391,7 @@ def run():
 	args.info and not
 	args.info and not
 	args.config and not
 	args.config and not
 	args.noreplays and not
 	args.noreplays and not
+	args.nolives and not
 	args.clean):
 	args.clean):
 		show_info(config)
 		show_info(config)
 		sys.exit(0)
 		sys.exit(0)
@@ -408,18 +422,27 @@ def run():
 			seperator("GREEN")
 			seperator("GREEN")
 			sys.exit(1)
 			sys.exit(1)
 
 
-		if (args.download == None):
-			log("[E] Missing --download argument. Please specify an Instagram username.", "RED")
+		if (args.noreplays):
+			settings.save_replays = "False"
+
+		if (args.nolives):
+			settings.save_lives = "False"
+
+		if settings.save_lives == "False" and settings.save_replays == "False":
+			log("[W] Script will not run because both live and replay saving is disabled.", "YELLOW")
+			seperator("GREEN")
+			sys.exit(1)
+
+		if not args.download:
+			log("[W] Missing --download argument. Please specify an Instagram username.", "YELLOW")
 			seperator("GREEN")
 			seperator("GREEN")
 			sys.exit(1)
 			sys.exit(1)
 
 
-		if (args.noreplays):
-			settings.save_replays = "false"
 
 
 		if (args.username is not None) and (args.password is not None):
 		if (args.username is not None) and (args.password is not None):
 			api = login(args.username, args.password, settings.show_cookie_expiry, True)
 			api = login(args.username, args.password, settings.show_cookie_expiry, True)
 		elif (args.username is not None) or (args.password is not None):
 		elif (args.username is not None) or (args.password is not None):
-			log("[W] Missing -u or -p arguments, falling back to config file...", "YELLOW")
+			log("[W] Missing --username or --password argument, falling back to config file...", "YELLOW")
 			if (not len(settings.username) > 0) or (not len(settings.password) > 0):
 			if (not len(settings.username) > 0) or (not len(settings.password) > 0):
 				log("[E] Username or password are missing. Please check your configuration settings and try again.", "RED")
 				log("[E] Username or password are missing. Please check your configuration settings and try again.", "RED")
 				seperator("GREEN")
 				seperator("GREEN")

+ 1 - 0
pyinstalive/settings.py

@@ -10,6 +10,7 @@ class settings:
 	current_time = str(int(time.time()))
 	current_time = str(int(time.time()))
 	current_date = time.strftime("%Y%m%d")
 	current_date = time.strftime("%Y%m%d")
 	save_replays = "true"
 	save_replays = "true"
+	save_lives = "true"
 	run_at_start = "None"
 	run_at_start = "None"
 	run_at_finish = "None"
 	run_at_finish = "None"
 	save_comments = "true"
 	save_comments = "true"