Quellcode durchsuchen

Add option to show cookie expiry, change camelCase vars to more readable format, improve setup

Cammy vor 7 Jahren
Ursprung
Commit
9471983e13
5 geänderte Dateien mit 41 neuen und 41 gelöschten Zeilen
  1. 1 0
      README.md
  2. 6 5
      pyinstalive/auth.py
  3. 23 23
      pyinstalive/downloader.py
  4. 9 9
      pyinstalive/initialize.py
  5. 2 4
      setup.py

+ 1 - 0
README.md

@@ -16,6 +16,7 @@ Here is an example of a valid configuration file:
 username = johndoe
 password = grapefruits
 save_path = C:\Instagram_Livestream_Downloads
+show_cookie_expiry = true
 ```
 
 #### Updating

+ 6 - 5
pyinstalive/auth.py

@@ -1,7 +1,7 @@
 import codecs
 import json
 import os.path
-
+import datetime
 import logger
 
 try:
@@ -38,7 +38,7 @@ def onlogin_callback(api, settings_file):
 		logger.log('[I] New auth cookie file was made: {0!s}'.format(settings_file), "GREEN")
 
 
-def login(username, password):
+def login(username, password, show_cookie_expiry):
 	device_id = None
 	try:
 		
@@ -82,8 +82,9 @@ def login(username, password):
 		logger.log('[E] Unexpected Exception: {0!s}'.format(e), "RED")
 		sys.exit(99)
 
-	# Show when login expires
-	# cookie_expiry = api.cookie_jar.expires_earliest
-	# print('[I] Cookie Expiry: {0!s}'.format(datetime.datetime.fromtimestamp(cookie_expiry).strftime('%Y-%m-%dT%H:%M:%S')), "WHITE")
 	logger.log('[I] Login to "' + username + '" OK!', "GREEN")
+	if show_cookie_expiry == 'True':
+		cookie_expiry = api.cookie_jar.expires_earliest
+		logger.log('[I] Login cookie expiry date: {0!s}'.format(datetime.datetime.fromtimestamp(cookie_expiry).strftime('%Y-%m-%d at %H:%M:%S')), "GREEN")
+
 	return api

+ 23 - 23
pyinstalive/downloader.py

@@ -9,32 +9,32 @@ import logger
 class NoBroadcastException(Exception):
 	pass
 
-def main(apiArg, recordArg, savePathArg):
+def main(api_arg, record_arg, save_path_arg):
 	global api
 	global record
-	global savePath
-	global currentDate
-	global currentTime
+	global save_path
+	global current_date
+	global current_time
 	global broadcast
 	global mpd_url
-	currentTime = str(int(time.time()))
-	currentDate = time.strftime("%Y%m%d")
-	api = apiArg
-	record = recordArg
-	savePath = savePathArg
-	getUserInfo(record)
+	current_time = str(int(time.time()))
+	current_date = time.strftime("%Y%m%d")
+	api = api_arg
+	record = record_arg
+	save_path = save_path_arg
+	get_user_info(record)
 
-def recordStream(broadcast):
+def record_stream(broadcast):
 	try:
 		def check_status():
-			printStatus()
+			print_status()
 			return heartbeat_info['broadcast_status'] not in ['active', 'interrupted']
 
 		mpd_url = (broadcast.get('dash_manifest')
 				   or broadcast.get('dash_abr_playback_url')
 				   or broadcast['dash_playback_url'])
 
-		outputDir = savePath + '{}_{}_{}_{}_downloads'.format(currentDate ,record, broadcast['id'], currentTime)
+		outputDir = save_path + '{}_{}_{}_{}_downloads'.format(current_date, record, broadcast['id'], current_time)
 
 		dl = live.Downloader(
 			mpd=mpd_url,
@@ -63,20 +63,20 @@ def recordStream(broadcast):
 		last_stream.close()
 		logger.log('[I] Username    : ' + record, "GREEN")
 		logger.log('[I] MPD URL     : ' + mpd_url, "GREEN")
-		printStatus(api, broadcast)
+		print_status(api, broadcast)
 		logger.log('[I] Recording broadcast... press [CTRL+C] to abort.', "GREEN")
 		dl.run()
-		stitchVideo(dl, broadcast)
+		stitch_video(dl, broadcast)
 	except KeyboardInterrupt:
 		logger.log('', "GREEN")
 		logger.log('[I] Aborting broadcast recording...', "GREEN")
 		if not dl.is_aborted:
 			dl.stop()
-			stitchVideo(dl, broadcast)
+			stitch_video(dl, broadcast)
 
-def stitchVideo(dl, broadcast):
+def stitch_video(dl, broadcast):
 		logger.log('[I] Stitching downloaded files into video...', "GREEN")
-		output_file = savePath + '{}_{}_{}_{}.mp4'.format(currentDate ,record, broadcast['id'], currentTime)
+		output_file = save_path + '{}_{}_{}_{}.mp4'.format(current_date, record, broadcast['id'], current_time)
 		try:
 			dl.stitch(output_file, cleartempfiles=False)
 			logger.log('[I] Successfully stitched downloaded files!', "GREEN")
@@ -87,25 +87,25 @@ def stitchVideo(dl, broadcast):
 			logger.seperator("GREEN")
 			sys.exit(0)
 
-def getUserInfo(record):
+def get_user_info(record):
 	try:
 		user_res = api.username_info(record)
 		user_id = user_res['user']['pk']
-		getBroadcast(user_id)
+		get_broadcast(user_id)
 	except Exception as e:
 		logger.log('[E] Could not get user info for "' + record + '" : ' + str(e), "RED")
 		logger.seperator("GREEN")
 		sys.exit(0)
 
 
-def getBroadcast(user_id):
+def get_broadcast(user_id):
 	try:
 		logger.log('[I] Checking broadcast for "' + record + '"...', "GREEN")
 		broadcast = api.user_broadcast(user_id)
 		if (broadcast is None):
 			raise NoBroadcastException('No broadcast available.')
 		else:
-			recordStream(broadcast)
+			record_stream(broadcast)
 	except NoBroadcastException as e:
 		logger.log('[W] ' + str(e), "YELLOW")
 		logger.seperator("GREEN")
@@ -116,7 +116,7 @@ def getBroadcast(user_id):
 			logger.seperator("GREEN")
 			sys.exit(0)
 
-def printStatus(api, broadcast):
+def print_status(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)

+ 9 - 9
pyinstalive/initialize.py

@@ -8,9 +8,9 @@ import auth, downloader, logger
 
 def run():
 
-	scriptVersion = "2.1.5"
+	script_version = "2.1.5"
 
-	logger.log('PYINSTALIVE DOWNLOADER (SCRIPT v{0!s})'.format(scriptVersion), "GREEN")
+	logger.log('PYINSTALIVE DOWNLOADER (SCRIPT v{0!s})'.format(script_version), "GREEN")
 	logger.seperator("GREEN")
 
 	logging.disable(logging.CRITICAL)
@@ -36,16 +36,16 @@ def run():
 	args = parser.parse_args()
 
 	if (args.username is not None) and (args.password is not None):
-		api = auth.login(args.username, args.password)
+		api = auth.login(args.username, args.password, config['pyinstalive']['show_cookie_expiry'].title())
 	else:
-		api = auth.login(config['pyinstalive']['username'], config['pyinstalive']['password'])
+		api = auth.login(config['pyinstalive']['username'], config['pyinstalive']['password'], config['pyinstalive']['show_cookie_expiry'].title())
 	
-	savePath = config['pyinstalive']['save_path']
-	if not savePath.endswith('/'):
-		savePath = savePath + '/'
+	save_path = config['pyinstalive']['save_path']
+	if not save_path.endswith('/'):
+		save_path = save_path + '/'
 
-	if (os.path.exists(savePath)):
-		downloader.main(api, args.record, savePath)
+	if (os.path.exists(save_path)):
+		downloader.main(api, args.record, save_path)
 	else:
 		logger.log("[W] Invalid save path was specified! Falling back to location: " + os.getcwd(), "RED")
 		downloader.main(api, args.record, os.getcwd())

+ 2 - 4
setup.py

@@ -24,9 +24,7 @@ setup(
 	},
 	install_requires=[ 
 		'instagram_private_api==%(api)s' % {'api': _api_version},
-		'instagram_private_api_extensions==%(ext)s' % {'ext': _api_extensions_version},
-		'argparse',
-		'configparser'
+		'instagram_private_api_extensions==%(ext)s' % {'ext': _api_extensions_version}
 	],
 	dependency_links=[
 		'https://github.com/ping/instagram_private_api/archive/%(api)s.tar.gz'
@@ -37,7 +35,7 @@ setup(
 	include_package_data=True,
 	platforms='any',
 	long_description=long_description,
-	keywords='instagram livestream downloader pyinstalive',
+	keywords='instagram-livestream-recorder record-instagram-livestreams live instagram record livestream video recorder downloader download save',
 	description='This script enables you to record Instagram livestreams.',
 	classifiers=[
 		'Environment :: Console',