Selaa lähdekoodia

Some var name changes, show missing stream time when done downloading

notcammy 7 vuotta sitten
vanhempi
commit
55cf57cd3e
2 muutettua tiedostoa jossa 17 lisäystä ja 12 poistoa
  1. 7 7
      pyinstalive/comments.py
  2. 10 5
      pyinstalive/downloader.py

+ 7 - 7
pyinstalive/comments.py

@@ -98,7 +98,7 @@ class CommentsDownloader(object):
 			json.dump(broadcast, outfile, indent=2)
 
 	@staticmethod
-	def generate_log(comments, download_start_time, srt_file, comments_delay=10.0):
+	def generate_log(comments, download_start_time, log_file, comments_delay=10.0):
 		python_version = sys.version.split(' ')[0]
 		subtitles_timeline = {}
 		for i, c in enumerate(comments):
@@ -121,14 +121,14 @@ class CommentsDownloader(object):
 				if clip_start < 0:
 					clip_start = 0
 
-				srt = ''
+				log = ''
 				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']))
+							log += '{}{}\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']))
+							log += '{}{}\n\n'.format(time.strftime('%H:%M:%S\n', time.gmtime(clip_start)), '{}: {}'.format(c['user']['username'], c['text']))
 
-				subs.append(srt)
+				subs.append(log)
 
-			with codecs.open(srt_file, 'w', 'utf-8-sig') as srt_outfile:
-				srt_outfile.write(''.join(subs))
+			with codecs.open(log_file, 'w', 'utf-8-sig') as log_outfile:
+				log_outfile.write(''.join(subs))

+ 10 - 5
pyinstalive/downloader.py

@@ -44,9 +44,14 @@ def run_script(file):
 
 
 
-def get_stream_duration(compare_time):
+def get_stream_duration(compare_time, broadcast=None):
 	try:
-		stream_started_mins, stream_started_secs = divmod((int(time.time()) - int(compare_time)), 60)
+		if broadcast:
+			record_time = int(time.time()) - int(compare_time)
+			stream_time = int(time.time()) - int(broadcast['published_time'])
+			stream_started_mins, stream_started_secs = divmod(stream_time - record_time, 60)
+		else:
+			stream_started_mins, stream_started_secs = divmod((int(time.time()) - int(compare_time)), 60)
 		stream_duration_str = '%d minutes' % stream_started_mins
 		if stream_started_secs:
 			stream_duration_str += ' and %d seconds' % stream_started_secs
@@ -64,7 +69,7 @@ def record_stream(broadcast):
 			if sep:
 				seperator("GREEN")
 			log('[I] Viewers     : ' + str(int(viewers)) + " watching", "GREEN")
-			log('[I] Airing time : ' + get_stream_duration(broadcast['published_time']).title(), "GREEN")
+			log('[I] Airing time : ' + get_stream_duration(broadcast['published_time']), "GREEN")
 			log('[I] Status      : ' + heartbeat_info['broadcast_status'].title(), "GREEN")
 
 			return heartbeat_info['broadcast_status'] not in ['active', 'interrupted'] 
@@ -117,12 +122,12 @@ def record_stream(broadcast):
 				log('[E] An error occurred while checking comments: ' + e, "RED")
 		dl.run()
 		seperator("GREEN")
-		log('[I] The livestream has ended.\n[I] Time recorded   : {}\n[I] Stream duration : {}'.format(get_stream_duration(int(settings.current_time)), get_stream_duration(broadcast['published_time'])), "YELLOW")
+		log('[I] The livestream has ended.\n[I] Time recorded   : {}\n[I] Stream duration : {}\n[I] Missed time     : {}'.format(get_stream_duration(int(settings.current_time)), get_stream_duration(broadcast['published_time']), get_stream_duration(int(settings.current_time), broadcast)), "YELLOW")
 		seperator("GREEN")
 		stitch_video(dl, broadcast, comment_thread_worker)
 	except KeyboardInterrupt:
 		seperator("GREEN")
-		log('[I] Download has been aborted by the user.\n[I] Time recorded   : {}\n[I] Stream duration : {}'.format(get_stream_duration(int(settings.current_time)), get_stream_duration(broadcast['published_time'])), "YELLOW")
+		log('[I] Download has been aborted by the user.\n[I] Time recorded   : {}\n[I] Stream duration : {}\n[I] Missed time     : {}'.format(get_stream_duration(int(settings.current_time)), get_stream_duration(broadcast['published_time']), get_stream_duration(int(settings.current_time), broadcast)), "YELLOW")
 		seperator("GREEN")
 		if not dl.is_aborted:
 			dl.stop()