Forráskód Böngészése

Readd comment downloading for py3 only, minor text layout improvements

notcammy 7 éve
szülő
commit
9d2d986d28
4 módosított fájl, 55 hozzáadás és 35 törlés
  1. 2 2
      pyinstalive/auth.py
  2. 6 14
      pyinstalive/comments.py
  3. 16 13
      pyinstalive/downloader.py
  4. 31 6
      pyinstalive/initialize.py

+ 2 - 2
pyinstalive/auth.py

@@ -93,9 +93,9 @@ def login(username, password, show_cookie_expiry, ignore_existing_cookie):
 		seperator("GREEN")
 		sys.exit(99)
 
-	log('[I] Login to "' + api.authenticated_user_name + '" OK!', "GREEN")
+	log('[I] Logging in to user "' + api.authenticated_user_name + '" successful.', "GREEN")
 	if show_cookie_expiry.title() == 'True' and ignore_existing_cookie == False:
 		cookie_expiry = api.cookie_jar.expires_earliest
-		log('[I] Login cookie expiry date: {0!s}'.format(datetime.datetime.fromtimestamp(cookie_expiry).strftime('%Y-%m-%d at %H:%M:%S')), "GREEN")
+		log('[I] Login cookie expiry date: {0!s}'.format(datetime.datetime.fromtimestamp(cookie_expiry).strftime('%Y-%m-%d at %I:%M:%S %p')), "GREEN")
 
 	return api

+ 6 - 14
pyinstalive/comments.py

@@ -54,12 +54,12 @@ class CommentsDownloader(object):
 			self.comments = comments_collected
 
 		except (SSLError, timeout, URLError, HTTPException, SocketError) as e:
-			log('[W] Comment collection error: %s' % e, "YELLOW")
+			log('[W] Comment downloading error: %s' % e, "YELLOW")
 		except ClientError as e:
 			if e.code == 500:
-				log('[W] Comment collection ClientError: %d %s' % (e.code, e.error_response), "YELLOW")
+				log('[W] Comment downloading ClientError: %d %s' % (e.code, e.error_response), "YELLOW")
 			elif e.code == 400 and not e.msg:
-				log('[W] Comment collection ClientError: %d %s' % (e.code, e.error_response), "YELLOW")
+				log('[W] Comment downloading ClientError: %d %s' % (e.code, e.error_response), "YELLOW")
 			else:
 				raise e
 		finally:
@@ -119,19 +119,11 @@ class CommentsDownloader(object):
 					clip_start = 0
 
 				srt = ''
-
-				if sys.version.split(' ')[0].startswith('2'):
-					for c in t:
+				for c in t:
 						if (c['user']['is_verified']):
-							srt += '{}{}\n\n'.format(time.strftime('%H:%M:%S\n', time.gmtime(clip_start)), '{} {}: {}'.format(c['user']['username'], "(V)", c['text'].encode('ascii', 'xmlcharrefreplace')))
+							srt += '{}{}\n\n'.format(time.strftime('%H:%M:%S\n', time.gmtime(clip_start)), '{} {}: {}'.format(c['user']['username'], "(v)", c['text']))
 						else:
-							srt += '{}{}\n\n'.format(time.strftime('%H:%M:%S\n', time.gmtime(clip_start)), '{}: {}'.format(c['user']['username'], c['text'].encode('ascii', 'xmlcharrefreplace')))
-				else:
-					for c in t:
-							if (c['user']['is_verified']):
-								srt += '{}{}\n\n'.format(time.strftime('%H:%M:%S\n', time.gmtime(clip_start)), '{} {}: {}'.format(c['user']['username'], "(v)", c['text']))
-							else:
-								srt += '{}{}\n\n'.format(time.strftime('%H:%M:%S\n', time.gmtime(clip_start)), '{}: {}'.format(c['user']['username'], c['text']))
+							srt += '{}{}\n\n'.format(time.strftime('%H:%M:%S\n', time.gmtime(clip_start)), '{}: {}'.format(c['user']['username'], c['text']))
 
 				subs.append(srt)
 

+ 16 - 13
pyinstalive/downloader.py

@@ -53,11 +53,12 @@ def record_stream(broadcast):
 		def print_status(sep=True):
 			heartbeat_info = api.broadcast_heartbeat_and_viewercount(broadcast['id'])
 			viewers = broadcast.get('viewer_count', 0)
+			if sep:
+				seperator("GREEN")
 			log('[I] Viewers     : ' + str(int(viewers)) + " watching", "GREEN")
 			log('[I] Airing time : ' + get_stream_duration(broadcast).title(), "GREEN")
 			log('[I] Status      : ' + heartbeat_info['broadcast_status'].title(), "GREEN")
-			if sep:
-				seperator("GREEN")
+
 			return heartbeat_info['broadcast_status'] not in ['active', 'interrupted'] 
 
 		mpd_url = (broadcast.get('dash_manifest')
@@ -80,8 +81,8 @@ def record_stream(broadcast):
 		seperator("GREEN")
 		sys.exit(1)
 	try:
-		seperator("GREEN")
 		log('[I] Livestream downloading started...', "GREEN")
+		seperator("GREEN")
 		log('[I] Username    : ' + record, "GREEN")
 		print_status(False)
 		log('[I] MPD URL     : ' + mpd_url, "GREEN")
@@ -98,11 +99,10 @@ def record_stream(broadcast):
 				log('[W] Could not run file: ' + str(e), "YELLOW")
 
 
-
+		comment_thread_worker = None
 		if settings.save_comments.title() == "True":
 			try:
 				comments_json_file = settings.save_path + '{}_{}_{}_{}_live_comments.json'.format(settings.current_date, record, broadcast['id'], settings.current_time)
-				comment_thread_worker = None
 				comment_thread_worker = threading.Thread(target=get_live_comments, args=(api, broadcast, comments_json_file, dl,))
 				comment_thread_worker.start()
 			except Exception as e:
@@ -111,8 +111,9 @@ def record_stream(broadcast):
 
 
 		dl.run()
+		seperator("GREEN")
 		log('[I] The livestream has ended. (Duration: ' + get_stream_duration(broadcast) + ")", "GREEN")
-
+		seperator("GREEN")
 		stitch_video(dl, broadcast, comment_thread_worker)
 	except KeyboardInterrupt:
 		seperator("GREEN")
@@ -126,6 +127,7 @@ def stitch_video(dl, broadcast, comment_thread_worker):
 	if comment_thread_worker and comment_thread_worker.is_alive():
 		log("[I] Ending comment saving process...", "GREEN")
 		comment_thread_worker.join()
+
 	if (settings.run_at_finish is not "None"):
 		try:
 			thread = threading.Thread(target=run_script, args=(settings.run_at_finish,))
@@ -178,7 +180,7 @@ def get_livestreams(user_id):
 		else:
 			record_stream(broadcast)
 	except NoLivestreamException as e:
-		log('[I] ' + str(e), "BLUE")
+		log('[I] ' + str(e), "YELLOW")
 	except Exception as e:
 		if (e.__class__.__name__ is not NoLivestreamException):
 			log('[E] Could not get livestreams info: ' + str(e), "RED")
@@ -201,7 +203,7 @@ def get_replays(user_id):
 			raise NoReplayException('There are no replays available.')
 		else:
 			log("[I] Available replays have been found to download, press [CTRL+C] to abort.", "GREEN")
-			log("", "GREEN")
+			seperator("GREEN")
 			for index, broadcast in enumerate(broadcasts):
 				exists = False
 
@@ -232,20 +234,21 @@ def get_replays(user_id):
 					if (len(replay_saved) == 1):
 						log("[I] Finished downloading replay " + str(current) + " of "  + str(len(broadcasts)) + ".", "GREEN")
 						seperator("GREEN")
+					else:
+						log("[W] No output video file was made, please merge the files manually.", "YELLOW")
+						log("[W] Check if ffmpeg is available by running ffmpeg in your terminal.", "YELLOW")
+						log("", "GREEN")
+
 					if settings.save_comments.title() == "True":
 						log("[I] Checking for available comments to save...", "GREEN")
 						comments_json_file = settings.save_path + '{}_{}_{}_{}_replay_comments.json'.format(settings.current_date, record, broadcast['id'], settings.current_time)
 						get_replay_comments(api, broadcast, comments_json_file, dl)
 
-					else:
-						log("[W] No output video file was made, please merge the files manually.", "RED")
-						log("[W] Check if ffmpeg is available by running ffmpeg in your terminal.", "RED")
-						log("", "GREEN")
 		log("[I] Finished downloading available replays.", "GREEN")
 		seperator("GREEN")
 		sys.exit(0)
 	except NoReplayException as e:
-		log('[I] ' + str(e), "BLUE")
+		log('[I] ' + str(e), "YELLOW")
 		seperator("GREEN")
 		sys.exit(0)
 	except Exception as e:

+ 31 - 6
pyinstalive/initialize.py

@@ -26,6 +26,7 @@ def check_ffmpeg():
 
 def check_config_validity(config):
 	try:
+		has_thrown_errors = False
 		settings.username = config.get('pyinstalive', 'username')
 		settings.password = config.get('pyinstalive', 'password')
 
@@ -34,9 +35,11 @@ def check_config_validity(config):
 			if not settings.show_cookie_expiry in bool_values:
 				log("[W] Invalid or missing setting detected for 'show_cookie_expiry', using default value (True)", "YELLOW")
 				settings.show_cookie_expiry = 'true'
+				has_thrown_errors = True
 		except:
 			log("[W] Invalid or missing setting detected for 'show_cookie_expiry', using default value (True)", "YELLOW")
 			settings.show_cookie_expiry = 'true'
+			has_thrown_errors = True
 
 
 
@@ -45,9 +48,11 @@ def check_config_validity(config):
 			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'
+				has_thrown_errors = True
 		except:
 			log("[W] Invalid or missing setting detected for 'clear_temp_files', using default value (True)", "YELLOW")
 			settings.clear_temp_files = 'true'
+			has_thrown_errors = True
 
 
 
@@ -56,9 +61,11 @@ def check_config_validity(config):
 			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'
+				has_thrown_errors = True
 		except:
 			log("[W] Invalid or missing setting detected for 'save_replays', using default value (True)", "YELLOW")
 			settings.save_replays = 'true'
+			has_thrown_errors = True
 
 
 
@@ -68,15 +75,18 @@ def check_config_validity(config):
 				if not os.path.isfile(settings.run_at_start):
 					log("[W] Path to file given for 'run_at_start' does not exist, using default value (None)", "YELLOW")
 					settings.run_at_start = "None"
+					has_thrown_errors = True
 				else:
 					if not settings.run_at_start.split('.')[-1] == 'py':
 						log("[W] File given for 'run_at_start' is not a Python script, using default value (None)", "YELLOW")
 						settings.run_at_start = "None"
+						has_thrown_errors = True
 			else:
 				settings.run_at_start = "None"
 		except:
 			log("[W] Invalid or missing settings detected for 'run_at_start', using default value (None)", "YELLOW")
 			settings.run_at_start = "None"
+			has_thrown_errors = True
 
 
 
@@ -86,26 +96,36 @@ def check_config_validity(config):
 				if not os.path.isfile(settings.run_at_finish):
 					log("[W] Path to file given for 'run_at_finish' does not exist, using default value (None)", "YELLOW")
 					settings.run_at_finish = "None"
+					has_thrown_errors = True
 				else:
 					if not settings.run_at_finish.split('.')[-1] == 'py':
 						log("[W] File given for 'run_at_finish' is not a Python script, using default value (None)", "YELLOW")
 						settings.run_at_finish = "None"
+						has_thrown_errors = True
 			else:
 				settings.run_at_finish = "None"
 
 		except:
 			log("[W] Invalid or missing settings detected for 'run_at_finish', using default value (None)", "YELLOW")
 			settings.run_at_finish = "None"
+			has_thrown_errors = True
 
 
 		try:
 			settings.save_comments = config.get('pyinstalive', 'save_comments').title()
-			if not settings.show_cookie_expiry in bool_values:
-				log("[W] Invalid or missing setting detected for 'save_comments', using default value (True)", "YELLOW")
-				settings.save_comments = 'true'
+			if sys.version.split(' ')[0].startswith('2') and settings.save_comments == "True":
+				log("[W] Comment saving is not supported in Python 2 and will be ignored.", "YELLOW")
+				settings.save_comments = 'false'
+				has_thrown_errors = True
+			else:
+				if not settings.show_cookie_expiry in bool_values:
+					log("[W] Invalid or missing setting detected for 'save_comments', using default value (False)", "YELLOW")
+					settings.save_comments = 'false'
+					has_thrown_errors = True
 		except:
-			log("[W] Invalid or missing setting detected for 'save_comments', using default value (True)", "YELLOW")
-			settings.save_comments = 'true'
+			log("[W] Invalid or missing setting detected for 'save_comments', using default value (False)", "YELLOW")
+			settings.save_comments = 'false'
+			has_thrown_errors = True
 
 
 		try:
@@ -116,12 +136,17 @@ def check_config_validity(config):
 			else:
 				log("[W] Invalid or missing setting detected for 'save_path', falling back to path: " + os.getcwd(), "YELLOW")
 				settings.save_path = os.getcwd()
+				has_thrown_errors = True
 
 			if not settings.save_path.endswith('/'):
 				settings.save_path = settings.save_path + '/'
 		except:
 			log("[W] Invalid or missing setting detected for 'save_path', falling back to path: " + os.getcwd(), "YELLOW")
 			settings.save_path = os.getcwd()
+			has_thrown_errors = True
+
+		if has_thrown_errors:
+			seperator("GREEN")
 
 		if not (len(settings.username) > 0):
 			log("[E] Invalid or missing setting detected for 'username'.", "RED")
@@ -239,7 +264,7 @@ def new_config():
 
 def run():
 	seperator("GREEN")
-	log('PYINSTALIVE (SCRIPT V{} - PYTHON V{}) - {}'.format(script_version, python_version, time.strftime('%H:%M:%S %p')), "GREEN")
+	log('PYINSTALIVE (SCRIPT V{} - PYTHON V{}) - {}'.format(script_version, python_version, time.strftime('%I:%M:%S %p')), "GREEN")
 	seperator("GREEN")
 
 	logging.disable(logging.CRITICAL)