|
@@ -5,7 +5,7 @@ import shutil
|
|
|
|
|
|
from instagram_private_api_extensions import live, replay
|
|
from instagram_private_api_extensions import live, replay
|
|
|
|
|
|
-import logger
|
|
|
|
|
|
+from .logger import log, seperator
|
|
|
|
|
|
|
|
|
|
class NoLivestreamException(Exception):
|
|
class NoLivestreamException(Exception):
|
|
@@ -38,10 +38,10 @@ def record_stream(broadcast):
|
|
started_label = '%d minutes' % started_mins
|
|
started_label = '%d minutes' % started_mins
|
|
if started_secs:
|
|
if started_secs:
|
|
started_label += ' and %d seconds' % started_secs
|
|
started_label += ' and %d seconds' % started_secs
|
|
- logger.log('[I] Viewers : ' + str(int(viewers)) + " watching", "GREEN")
|
|
|
|
- logger.log('[I] Airing time : ' + started_label, "GREEN")
|
|
|
|
- logger.log('[I] Status : ' + heartbeat_info['broadcast_status'].title(), "GREEN")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[I] Viewers : ' + str(int(viewers)) + " watching", "GREEN")
|
|
|
|
+ log('[I] Airing time : ' + started_label, "GREEN")
|
|
|
|
+ log('[I] Status : ' + heartbeat_info['broadcast_status'].title(), "GREEN")
|
|
|
|
+ seperator("GREEN")
|
|
return heartbeat_info['broadcast_status'] not in ['active', 'interrupted']
|
|
return heartbeat_info['broadcast_status'] not in ['active', 'interrupted']
|
|
|
|
|
|
mpd_url = (broadcast.get('dash_manifest')
|
|
mpd_url = (broadcast.get('dash_manifest')
|
|
@@ -60,91 +60,91 @@ def record_stream(broadcast):
|
|
mpd_download_timeout=5,
|
|
mpd_download_timeout=5,
|
|
download_timeout=10)
|
|
download_timeout=10)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.log('[E] Could not start recording livestream: ' + str(e), "RED")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[E] Could not start recording livestream: ' + str(e), "RED")
|
|
|
|
+ seperator("GREEN")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
try:
|
|
try:
|
|
- logger.log('[I] Starting livestream recording:', "GREEN")
|
|
|
|
- logger.log('[I] Username : ' + record, "GREEN")
|
|
|
|
- logger.log('[I] MPD URL : ' + mpd_url, "GREEN")
|
|
|
|
|
|
+ log('[I] Starting livestream recording:', "GREEN")
|
|
|
|
+ log('[I] Username : ' + record, "GREEN")
|
|
|
|
+ log('[I] MPD URL : ' + mpd_url, "GREEN")
|
|
print_status()
|
|
print_status()
|
|
- logger.log('[I] Recording livestream... press [CTRL+C] to abort.', "GREEN")
|
|
|
|
|
|
+ log('[I] Recording livestream... press [CTRL+C] to abort.', "GREEN")
|
|
dl.run()
|
|
dl.run()
|
|
stitch_video(dl, broadcast)
|
|
stitch_video(dl, broadcast)
|
|
except KeyboardInterrupt:
|
|
except KeyboardInterrupt:
|
|
- logger.log("", "GREEN")
|
|
|
|
- logger.log('[W] Download has been aborted.', "YELLOW")
|
|
|
|
- logger.log("", "GREEN")
|
|
|
|
|
|
+ log("", "GREEN")
|
|
|
|
+ log('[W] Download has been aborted.', "YELLOW")
|
|
|
|
+ log("", "GREEN")
|
|
if not dl.is_aborted:
|
|
if not dl.is_aborted:
|
|
dl.stop()
|
|
dl.stop()
|
|
stitch_video(dl, broadcast)
|
|
stitch_video(dl, broadcast)
|
|
|
|
|
|
def stitch_video(dl, broadcast):
|
|
def stitch_video(dl, broadcast):
|
|
- logger.log('[I] Stitching downloaded files into video...', "GREEN")
|
|
|
|
|
|
+ log('[I] Stitching downloaded files into video...', "GREEN")
|
|
output_file = save_path + '{}_{}_{}_{}_live.mp4'.format(current_date, record, broadcast['id'], current_time)
|
|
output_file = save_path + '{}_{}_{}_{}_live.mp4'.format(current_date, record, broadcast['id'], current_time)
|
|
try:
|
|
try:
|
|
dl.stitch(output_file, cleartempfiles=False)
|
|
dl.stitch(output_file, cleartempfiles=False)
|
|
- logger.log('[I] Successfully stitched downloaded files.', "GREEN")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[I] Successfully stitched downloaded files.', "GREEN")
|
|
|
|
+ seperator("GREEN")
|
|
sys.exit(0)
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.log('[E] Could not stitch downloaded files: ' + str(e), "RED")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[E] Could not stitch downloaded files: ' + str(e), "RED")
|
|
|
|
+ seperator("GREEN")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
def get_user_info(record):
|
|
def get_user_info(record):
|
|
try:
|
|
try:
|
|
- logger.log('[I] Getting required user info for user "' + record + '"...', "GREEN")
|
|
|
|
|
|
+ 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']
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.log('[E] Could not get user info: ' + str(e), "RED")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[E] Could not get user info: ' + str(e), "RED")
|
|
|
|
+ seperator("GREEN")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
get_livestreams(user_id)
|
|
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 for ongoing livestreams...', "GREEN")
|
|
|
|
|
|
+ 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 livestreams available.')
|
|
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")
|
|
|
|
|
|
+ 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 livestreams info: ' + str(e), "RED")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[E] Could not get livestreams info: ' + str(e), "RED")
|
|
|
|
+ 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")
|
|
|
|
|
|
+ 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:
|
|
- logger.log('[E] Could not get replay info: ' + str(e), "RED")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[E] Could not get replay info: ' + str(e), "RED")
|
|
|
|
+ seperator("GREEN")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
try:
|
|
try:
|
|
if (len(broadcasts) == 0):
|
|
if (len(broadcasts) == 0):
|
|
raise NoReplayException('There are no replays available.')
|
|
raise NoReplayException('There are no replays available.')
|
|
else:
|
|
else:
|
|
- logger.log("[I] Available replays have been found to download, press [CTRL+C] to abort.", "GREEN")
|
|
|
|
- logger.log("", "GREEN")
|
|
|
|
|
|
+ log("[I] Available replays have been found to download, press [CTRL+C] to abort.", "GREEN")
|
|
|
|
+ log("", "GREEN")
|
|
for index, broadcast in enumerate(broadcasts):
|
|
for index, broadcast in enumerate(broadcasts):
|
|
exists = False
|
|
exists = False
|
|
for directory in (os.walk(save_path).next()[1]):
|
|
for directory in (os.walk(save_path).next()[1]):
|
|
if (str(broadcast['id']) in directory) and ("_live_" not in directory):
|
|
if (str(broadcast['id']) in directory) and ("_live_" not in directory):
|
|
- logger.log("[W] Already downloaded a replay with ID '" + str(broadcast['id']) + "', skipping...", "GREEN")
|
|
|
|
|
|
+ log("[W] Already downloaded a replay with ID '" + str(broadcast['id']) + "', skipping...", "GREEN")
|
|
exists = True
|
|
exists = True
|
|
if exists is False:
|
|
if exists is False:
|
|
current = index + 1
|
|
current = index + 1
|
|
- logger.log("[I] Downloading replay " + str(current) + " of " + str(len(broadcasts)) + " with ID '" + str(broadcast['id']) + "'...", "GREEN")
|
|
|
|
|
|
+ log("[I] Downloading replay " + str(current) + " of " + str(len(broadcasts)) + " with ID '" + str(broadcast['id']) + "'...", "GREEN")
|
|
current_time = str(int(time.time()))
|
|
current_time = str(int(time.time()))
|
|
output_dir = save_path + '{}_{}_{}_{}_replay_downloads'.format(current_date, record, broadcast['id'], current_time)
|
|
output_dir = save_path + '{}_{}_{}_{}_replay_downloads'.format(current_date, record, broadcast['id'], current_time)
|
|
dl = replay.Downloader(
|
|
dl = replay.Downloader(
|
|
@@ -153,29 +153,29 @@ def get_replays(user_id):
|
|
user_agent=api.user_agent)
|
|
user_agent=api.user_agent)
|
|
replay_saved = dl.download(save_path + '{}_{}_{}_{}_replay.mp4'.format(current_date, record, broadcast['id'], current_time), cleartempfiles=False)
|
|
replay_saved = dl.download(save_path + '{}_{}_{}_{}_replay.mp4'.format(current_date, record, broadcast['id'], current_time), cleartempfiles=False)
|
|
if (len(replay_saved) == 1):
|
|
if (len(replay_saved) == 1):
|
|
- logger.log("[I] Finished downloading replay " + str(current) + " of " + str(len(broadcasts)) + ".", "GREEN")
|
|
|
|
- logger.log("", "GREEN")
|
|
|
|
|
|
+ log("[I] Finished downloading replay " + str(current) + " of " + str(len(broadcasts)) + ".", "GREEN")
|
|
|
|
+ log("", "GREEN")
|
|
else:
|
|
else:
|
|
- logger.log("[W] No output video file was made, please merge the files manually.", "RED")
|
|
|
|
- logger.log("[W] Check if ffmpeg is available by running ffmpeg in your terminal.", "RED")
|
|
|
|
- logger.log("", "GREEN")
|
|
|
|
- logger.log("[I] Finished downloading available replays.", "GREEN")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ 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)
|
|
sys.exit(0)
|
|
except NoReplayException as e:
|
|
except NoReplayException as e:
|
|
- logger.log('[W] ' + str(e), "YELLOW")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[W] ' + str(e), "YELLOW")
|
|
|
|
+ seperator("GREEN")
|
|
sys.exit(0)
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.log('[E] Could not save replay: ' + str(e), "RED")
|
|
|
|
- logger.seperator("GREEN")
|
|
|
|
|
|
+ log('[E] Could not save replay: ' + str(e), "RED")
|
|
|
|
+ seperator("GREEN")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
except KeyboardInterrupt:
|
|
except KeyboardInterrupt:
|
|
- logger.log("", "GREEN")
|
|
|
|
- logger.log('[W] Download has been aborted.', "YELLOW")
|
|
|
|
|
|
+ log("", "GREEN")
|
|
|
|
+ log('[W] Download has been aborted.', "YELLOW")
|
|
try:
|
|
try:
|
|
shutil.rmtree(output_dir)
|
|
shutil.rmtree(output_dir)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.log("[E] Could not remove temp folder: " + str(e), "RED")
|
|
|
|
|
|
+ log("[E] Could not remove temp folder: " + str(e), "RED")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
sys.exit(0)
|
|
sys.exit(0)
|