Ver Fonte

Update gitignore to ignore html info file, improve status reporting

Cammy há 7 anos atrás
pai
commit
63cf0fbfb1
2 ficheiros alterados com 21 adições e 7 exclusões
  1. 2 0
      .gitignore
  2. 19 7
      cDownloader.py

+ 2 - 0
.gitignore

@@ -3,3 +3,5 @@
 credentials\.json
 
 setup\.py
+
+last_stream\.html

+ 19 - 7
cDownloader.py

@@ -26,6 +26,8 @@ def main(apiArg, recordArg):
 	global isRecording
 	global currentDate
 	global currentTime
+	global broadcast
+	global mpd_url
 	currentTime = str(int(time.time()))
 	currentDate = time.strftime("%Y%m%d")
 	isRecording = False
@@ -36,8 +38,7 @@ def main(apiArg, recordArg):
 def recordStream(broadcast):
 	try:
 		def check_status():
-			heartbeat_info = api.broadcast_heartbeat_and_viewercount(broadcast['id'])
-			cLogger.log('[I] Broadcast status: %s' % heartbeat_info['broadcast_status'], "GREEN")
+			printStatus()
 			return heartbeat_info['broadcast_status'] not in ['active', 'interrupted']
 
 		mpd_url = (broadcast.get('dash_manifest')
@@ -71,10 +72,9 @@ def recordStream(broadcast):
 		last_stream.write('<b>Username:</b> {}<br><b>MPD URL:</b> <a href="{}">LINK</a><br><b>Viewers:</b> {}<br><b>Missing:</b> {}'
 			.format(record, mpd_url, str(int(viewers)), started_label))
 		last_stream.close()
-		cLogger.log('[I] Username : ' + record, "GREEN")
-		cLogger.log('[I] MPD URL  : ' + mpd_url, "GREEN")
-		cLogger.log('[I] Viewers  : ' + str(int(viewers)) + " watching", "GREEN")
-		cLogger.log('[I] Missing  : ' + started_label, "GREEN")
+		cLogger.log('[I] Username    : ' + record, "GREEN")
+		cLogger.log('[I] MPD URL     : ' + mpd_url, "GREEN")
+		printStatus(api, broadcast)
 		cLogger.log('[I] Recording broadcast...', "GREEN")
 		dl.run()
 		stitchVideo(dl, broadcast)
@@ -121,4 +121,16 @@ def getBroadcast(user_id):
 		if (e.__name__ is not NoBroadcastException):
 			cLogger.log('[E] Could not get broadcast info: ' + str(e), "RED")
 			cLogger.seperator("GREEN")
-			sys.exit(0)
+			sys.exit(0)
+
+def printStatus(api, broadcast):
+	heartbeat_info = api.broadcast_heartbeat_and_viewercount(broadcast['id'])
+	viewers = broadcast.get('viewer_count', 0)
+	started_mins, started_secs = divmod((int(time.time()) - broadcast['published_time']), 60)
+	started_label = '%d minutes and ' % started_mins
+	if started_secs:
+		started_label += '%d seconds' % started_secs
+	cLogger.log('[I] Viewers     : ' + str(int(viewers)) + " watching", "GREEN")
+	cLogger.log('[I] Airing time : ' + started_label, "GREEN")
+	cLogger.log('[I] Status      : ' + heartbeat_info['broadcast_status'].title(), "GREEN")
+	cLogger.log('', "GREEN")