瀏覽代碼

Improved logging, config validation, gitignore and readme

dirk-vh 7 年之前
父節點
當前提交
97741eddd4
共有 4 個文件被更改,包括 47 次插入17 次删除
  1. 19 0
      .gitignore
  2. 8 2
      README.md
  3. 8 6
      pyinstalive/downloader.py
  4. 12 9
      pyinstalive/initialize.py

+ 19 - 0
.gitignore

@@ -7,3 +7,22 @@ looper\.sh
 credentials\.json
 credentials\.json
 
 
 pyinstalive\.ini
 pyinstalive\.ini
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST

+ 8 - 2
README.md

@@ -1,8 +1,14 @@
 # PyInstaLive
 # PyInstaLive
 This script enables you to record Instagram livestreams as well as download any available replays. It is based on [another script](https://github.com/taengstagram/instagram-livestream-downloader) that has now been discontinued. 
 This script enables you to record Instagram livestreams as well as download any available replays. It is based on [another script](https://github.com/taengstagram/instagram-livestream-downloader) that has now been discontinued. 
 
 
+
 ## Installation
 ## Installation
 
 
+#### Prerequisites
+You need [ffmpeg](https://ffmpeg.org/download.html), [Git](https://git-scm.com/downloads) and [Python 2.7.x](https://www.python.org/downloads/release/python-2713/) with [pip](https://pip.pypa.io/en/stable/installing/) and [setuptools](https://packaging.python.org/tutorials/installing-packages/#install-pip-setuptools-and-wheel) installed before you can install and use this script.
+
+#### Installing
+
 Run the following command in command line (as administrator in Windows) / terminal:
 Run the following command in command line (as administrator in Windows) / terminal:
 ```bash
 ```bash
 pip install git+https://github.com/notcammy/PyInstaLive.git@2.2.1 --process-dependency-links
 pip install git+https://github.com/notcammy/PyInstaLive.git@2.2.1 --process-dependency-links
@@ -26,8 +32,6 @@ pip install git+https://github.com/notcammy/PyInstaLive.git@2.1.0 --process-depe
 
 
 Use the version number you want after the **@** symbol (e.g **2.1.0**).
 Use the version number you want after the **@** symbol (e.g **2.1.0**).
 
 
-#### Note
-You need [ffmpeg](https://ffmpeg.org/download.html), [Git](https://git-scm.com/downloads) and [Python 2.7.x](https://www.python.org/downloads/release/python-2713/) with [Pip](https://pip.pypa.io/en/stable/installing/) installed before you can install and use this script.
 
 
 ## Usage
 ## Usage
 Make sure there is a configuration file called ``pyinstalive.ini`` in the directory you want to run PyInstaLive from.
 Make sure there is a configuration file called ``pyinstalive.ini`` in the directory you want to run PyInstaLive from.
@@ -54,6 +58,7 @@ The `username` and `password` parameters are not required when you have specifie
 
 
 If the script is ran and there are available replays as well as an ongoing Instagram livestream, only the livestream will be downloaded. Run the script again after the livestream has ended to download the available replays.
 If the script is ran and there are available replays as well as an ongoing Instagram livestream, only the livestream will be downloaded. Run the script again after the livestream has ended to download the available replays.
 
 
+
 ## Example
 ## Example
 ```bash
 ```bash
 pyinstalive -u "johndoe" -p "grapefruits" -r "janedoe"
 pyinstalive -u "johndoe" -p "grapefruits" -r "janedoe"
@@ -83,6 +88,7 @@ PYINSTALIVE DOWNLOADER (SCRIPT v1.0)
 [I] Successfully stitched downloaded files!
 [I] Successfully stitched downloaded files!
 ```
 ```
 
 
+
 ## Help
 ## Help
 If you have a bug to report please open [an issue](https://github.com/notcammy/PyInstaLive/issues) in the appropriate format:
 If you have a bug to report please open [an issue](https://github.com/notcammy/PyInstaLive/issues) in the appropriate format:
 
 

+ 8 - 6
pyinstalive/downloader.py

@@ -82,34 +82,36 @@ def stitch_video(dl, broadcast):
 
 
 def get_user_info(record):
 def get_user_info(record):
 	try:
 	try:
+		logger.log('[I] Getting required user info for user "' + record + '"...', "GREEN")
 		user_res = api.username_info(record)
 		user_res = api.username_info(record)
 		user_id = user_res['user']['pk']
 		user_id = user_res['user']['pk']
-		get_livestreams(user_id)
 	except Exception as e:
 	except Exception as e:
-		logger.log('[E] Could not get livestream info for "' + record + '" : ' + str(e), "RED")
+		logger.log('[E] Could not get user info: ' + str(e), "RED")
 		logger.seperator("GREEN")
 		logger.seperator("GREEN")
 		sys.exit(1)
 		sys.exit(1)
+	get_livestreams(user_id)
 	get_replays(user_id)
 	get_replays(user_id)
 
 
 def get_livestreams(user_id):
 def get_livestreams(user_id):
 	try:
 	try:
-		logger.log('[I] Checking livestreams and replays for "' + record + '"...', "GREEN")
+		logger.log('[I] Checking for ongoing livestreams...', "GREEN")
 		broadcast = api.user_broadcast(user_id)
 		broadcast = api.user_broadcast(user_id)
 		if (broadcast is None):
 		if (broadcast is None):
-			raise NoLivestreamException('There are no current livestreams.')
+			raise NoLivestreamException('There are no livestreams available.')
 		else:
 		else:
 			record_stream(broadcast)
 			record_stream(broadcast)
 	except NoLivestreamException as e:
 	except NoLivestreamException as e:
 		logger.log('[W] ' + str(e), "YELLOW")
 		logger.log('[W] ' + str(e), "YELLOW")
 	except Exception as e:
 	except Exception as e:
 		if (e.__class__.__name__ is not NoLivestreamException):
 		if (e.__class__.__name__ is not NoLivestreamException):
-			logger.log('[E] Could not get required info: ' + str(e), "RED")
+			logger.log('[E] Could not get livestreams info: ' + str(e), "RED")
 			logger.seperator("GREEN")
 			logger.seperator("GREEN")
 			sys.exit(1)
 			sys.exit(1)
 
 
 
 
 def get_replays(user_id):
 def get_replays(user_id):
 	try:
 	try:
+		logger.log('[I] Checking for available replays...', "GREEN")
 		user_story_feed = api.user_story_feed(user_id)
 		user_story_feed = api.user_story_feed(user_id)
 		broadcasts = user_story_feed.get('post_live_item', {}).get('broadcasts', [])
 		broadcasts = user_story_feed.get('post_live_item', {}).get('broadcasts', [])
 	except Exception as e:
 	except Exception as e:
@@ -118,7 +120,7 @@ def get_replays(user_id):
 		sys.exit(1)
 		sys.exit(1)
 	try:
 	try:
 		if (len(broadcasts) == 0):
 		if (len(broadcasts) == 0):
-			raise NoReplayException('There are no saved replays.')
+			raise NoReplayException('There are no replays available.')
 		else:
 		else:
 			for index, broadcast in enumerate(broadcasts):
 			for index, broadcast in enumerate(broadcasts):
 				exists = False
 				exists = False

+ 12 - 9
pyinstalive/initialize.py

@@ -7,18 +7,21 @@ import sys
 import auth, downloader, logger
 import auth, downloader, logger
 
 
 def check_config_validity(config):
 def check_config_validity(config):
-	username = config['pyinstalive']['username']
-	password = config['pyinstalive']['password']
+	try:
+		username = config['pyinstalive']['username']
+		password = config['pyinstalive']['password']
 
 
-	if not (len(username) > 0):
-		logger.log("[E] Invalid setting detected for 'username'.", "RED")
-		return False
+		if not (len(username) > 0):
+			logger.log("[E] Invalid setting detected for 'username'.", "RED")
+			return False
 
 
-	if not (len(password) > 0):
-		logger.log("[E] Invalid setting detected for 'password'.", "RED")
-		return False
+		if not (len(password) > 0):
+			logger.log("[E] Invalid setting detected for 'password'.", "RED")
+			return False
 
 
-	return True
+		return True
+	except KeyError as e:
+		return False
 
 
 
 
 def run():
 def run():