Quellcode durchsuchen

Remove FTP Upload function

Cammy vor 7 Jahren
Ursprung
Commit
1996507f63
5 geänderte Dateien mit 11 neuen und 117 gelöschten Zeilen
  1. 1 20
      MOREHELP.md
  2. 5 12
      README.md
  3. 2 60
      pyinstalive/downloader.py
  4. 2 19
      pyinstalive/initialize.py
  5. 1 6
      pyinstalive/settings.py

+ 1 - 20
MOREHELP.md

@@ -29,13 +29,6 @@ save_replays = true
 run_at_start =
 run_at_finish =
 save_comments = false
-
-[ftp]
-ftp_enabled = false
-ftp_host = 
-ftp_save_path = 
-ftp_username = 
-ftp_password = 
 ```
 
 ```username```  **—**  Instagram username to login with.
@@ -54,16 +47,4 @@ ftp_password =
 
 ```run_at_finish```  **—**  Command to run when PyInstaLive finishes recording a livestream. Leave empty to disable. (Experimental, use at own risk.) 
  
-```save_comments```  **—**  When set to true, PyInstaLive will try to save comments from a livestream or replay to a log file. Verified users have *(v)* next to their name. (Experimental, use at own risk.)
-
-#
-
-```ftp_enabled```  **—** When set to true, PyInstaLive will upload downloaded files to the configured FTP server. (Experimental, use at own risk.)
-
-```ftp_host```  **—** Host IP or URL for the FTP server.
-
-```ftp_save_path```  **—** FTP server save path to upload the downloaded files to.
-
-```ftp_username```  **—** FTP username to login with.
-
-```ftp_password```  **—** FTP password to login with.
+```save_comments```  **—**  When set to true, PyInstaLive will try to save comments from a livestream or replay to a log file. Verified users have *(v)* next to their name. (Experimental, use at own risk.)

+ 5 - 12
README.md

@@ -10,7 +10,6 @@ This script enables you to download any ongoing Instagram livestreams as well as
 - Download available replays
 - Download livestream and replay comments
 - Run a command when starting and/or finishing a download (Experimental)
-- Upload the downloaded livestream or replay to an FTP server (Experimental)
 
 ## Quickstart
 
@@ -71,13 +70,6 @@ save_replays = true
 run_at_start =
 run_at_finish =
 save_comments = false
-
-[ftp]
-ftp_enabled = false
-ftp_host = 
-ftp_save_path = 
-ftp_username = 
-ftp_password = 
 ```
 
 Use the following command to run PyInstaLive:
@@ -103,12 +95,13 @@ Below is an example of PyInstaLive's output after downloading a livestream:
 ----------------------------------------------------------------------
 PYINSTALIVE (SCRIPT V2.5.0 - PYTHON V3.6.3) - 06:45:30 PM
 ----------------------------------------------------------------------
-[I] Logging in to user "johndoe" successful.
+[I] Using cached login cookie for "johndoe".
 [I] Login cookie expiry date: 2018-01-31 at 10:30:00 PM
-[I] Checking user "janedoe"...
+[I] Getting info for "janedoe" successful.
+----------------------------------------------------------------------
+[I] Checking for livestreams and replays...
 ----------------------------------------------------------------------
-[I] Checking for ongoing livestreams...
-[I] Livestream downloading started...
+[I] Livestream found, beginning download...
 ----------------------------------------------------------------------
 [I] Username    : janedoe
 [I] Viewers     : 100 watching

+ 2 - 60
pyinstalive/downloader.py

@@ -1,4 +1,3 @@
-import ftplib
 import os
 import shutil
 import subprocess
@@ -7,9 +6,6 @@ import threading
 import time
 import shlex
 
-from glob import glob
-from tqdm import tqdm
-
 from instagram_private_api import ClientConnectionError
 from instagram_private_api import ClientError
 from instagram_private_api import ClientThrottledError
@@ -168,16 +164,10 @@ def stitch_video(broadcast_downloader, broadcast, comment_thread_worker):
 
 		live_mp4_file = settings.save_path + '{}_{}_{}_{}_live.mp4'.format(settings.current_date, user_to_record, broadcast.get('id'), settings.current_time)
 		live_folder_path = live_mp4_file.split('.mp4')[0] + "_downloads"
-		live_json_file = os.path.join(settings.save_path, live_folder_path, '{}_{}_{}_{}_live_comments.json'.format(settings.current_date, user_to_record, broadcast.get('id'), settings.current_time))
-		live_comments_file = live_mp4_file.replace(".mp4", "_live_comments.log")
-
-		live_files = [live_mp4_file]
-
 
 		if comment_thread_worker and comment_thread_worker.is_alive():
 			log("[I] Stopping comment downloading and saving comments (if any)...", "GREEN")
 			comment_thread_worker.join()
-			live_files.extend([live_json_file, live_comments_file])
 
 		if (settings.run_at_finish is not "None"):
 			try:
@@ -204,12 +194,6 @@ def stitch_video(broadcast_downloader, broadcast, comment_thread_worker):
 					shutil.rmtree(live_folder_path)
 				except Exception as e:
 					log("[E] Could not remove temp folder: {:s}".format(str(e)), "RED")
-			if settings.ftp_enabled:
-				try:
-					seperator("GREEN")
-					upload_ftp_files(live_files)
-				except Exception as e:
-					log("[E] Could not upload livestream files to FTP server: {:s}".format(str(e)), "RED")
 			seperator("GREEN")
 			sys.exit(0)
 		except ValueError as e:
@@ -320,9 +304,6 @@ def download_replays(broadcasts):
 				open(os.path.join(output_dir,'folder.lock'), 'a').close()
 				replay_mp4_file = settings.save_path + '{}_{}_{}_{}_replay.mp4'.format(settings.current_date, user_to_record, broadcast.get('id'), settings.current_time)
 				replay_json_file = os.path.join(output_dir, '{}_{}_{}_{}_replay_comments.json'.format(settings.current_date, user_to_record, broadcast.get('id'), settings.current_time))
-				replay_comments_file = replay_json_file.replace(".json", ".log")
-
-				replay_files = [replay_mp4_file]
 
 				if settings.clear_temp_files.title() == "True":
 					replay_saved = broadcast_downloader.download(replay_mp4_file, cleartempfiles=True)
@@ -331,8 +312,7 @@ def download_replays(broadcasts):
 
 				if settings.save_comments.title() == "True":
 					log("[I] Checking for available comments to save...", "GREEN")
-					if get_replay_comments(instagram_api, broadcast, replay_json_file, broadcast_downloader):
-						replay_files.extend([replay_json_file, replay_comments_file])
+					get_replay_comments(instagram_api, broadcast, replay_json_file, broadcast_downloader)
 
 				if (len(replay_saved) == 1):
 					log("[I] Finished downloading replay {:s} of {:s}.".format(str(current), str(len(broadcasts))), "GREEN")
@@ -340,11 +320,6 @@ def download_replays(broadcasts):
 					    os.remove(os.path.join(output_dir,'folder.lock'))
 					except OSError:
 					    pass
-					if settings.ftp_enabled:
-						try:
-							upload_ftp_files(replay_files)
-						except Exception as e:
-							log("[E] Could not upload replay files to FTP server: {:s}".format(str(e)), "RED")
 
 					if (current != len(broadcasts)):
 						seperator("GREEN")
@@ -451,37 +426,4 @@ def get_live_comments(instagram_api, broadcast, comments_json_file, broadcast_do
 			return False
 	except KeyboardInterrupt as e:
 		log("[W] Downloading livestream comments has been aborted.", "YELLOW")
-		return False
-
-
-def upload_ftp_files(files):
-	try:
-		ftp = ftplib.FTP(settings.ftp_host, settings.ftp_username, settings.ftp_password)
-		ftp.cwd(settings.ftp_save_path)
-
-		stream_type = "replay" if "_replay.mp4" in files[0] else "livestream"
-
-		for file in files:
-			try:
-				filename = file.split('/').pop() or file.split('\\').pop()
-				log("", "GREEN")
-				if filename.endswith("mp4"):
-					log("[I] Uploading video file to FTP server...".format(filename), "GREEN")
-				if filename.endswith("log"):
-					log("[I] Uploading comments logfile to FTP server...".format(filename), "GREEN")
-				if filename.endswith("json"):
-					log("[I] Uploading comments JSON file to FTP server...".format(filename), "GREEN")
-				filesize = os.path.getsize(file)
-				file_read = open(file, 'rb')
-				with tqdm(leave = False, ncols=70, miniters = 1, total = filesize, bar_format=">{bar}< - {percentage:3.0f}%") as tqdm_instance:
-					ftp.storbinary('STOR ' + filename, file_read, 2048, callback = lambda sent: tqdm_instance.update(len(sent)))
-				file_read.close()
-				log("[I] Successfully uploaded file to FTP server.", "GREEN")
-			except Exception as e:
-				log("[E] Could not upload file '{:s}' to FTP server: {:s}".format(filename, str(e)), "RED")
-		ftp.quit()
-		ftp = None
-	except Exception as e:
-		log("[E] Could not upload {:s} files to FTP server: {:s}".format(stream_type, str(e)), "RED")
-	except KeyboardInterrupt as e:
-		log("[W] Uploading {:s} files to FTP server has been aborted.".format(stream_type), "YELLOW")
+		return False

+ 2 - 19
pyinstalive/initialize.py

@@ -127,23 +127,6 @@ def check_config_validity(config):
 			has_thrown_errors = True
 
 
-		try:
-			if config.get('ftp', 'ftp_enabled').title() == "True":
-				settings.ftp_host = config.get('ftp', 'ftp_host')
-				settings.ftp_save_path = config.get('ftp', 'ftp_save_path')
-				settings.ftp_username = config.get('ftp', 'ftp_username')
-				settings.ftp_password = config.get('ftp', 'ftp_password')
-
-				if len(settings.ftp_host) > 0 and len(settings.ftp_save_path) > 0 and len(settings.ftp_username) > 0 and len(settings.ftp_password) > 0:
-					settings.ftp_enabled = True
-				else:
-					log("[W] Missing settings detected for the FTP settings, FTP will be ignored.", "YELLOW")
-					has_thrown_errors = True
-		except:
-			log("[W] Missing or invalid settings detected for the FTP settings, FTP will be ignored.", "YELLOW")
-			has_thrown_errors = True
-
-
 		if has_thrown_errors:
 			seperator("GREEN")
 
@@ -231,7 +214,7 @@ def new_config():
 		else:
 			try:
 				log("[W] Could not find configuration file, creating a default one...", "YELLOW")
-				config_template = "[pyinstalive]\nusername = johndoe\npassword = grapefruits\nsave_path = " + os.getcwd() + "\nshow_cookie_expiry = true\nclear_temp_files = false\nsave_replays = true\nrun_at_start = \nrun_at_finish = \nsave_comments = false\n\n[ftp]\nftp_enabled = false\nftp_host = \nftp_save_path = \nftp_username = \nftp_password = \n"
+				config_template = "[pyinstalive]\nusername = johndoe\npassword = grapefruits\nsave_path = " + os.getcwd() + "\nshow_cookie_expiry = true\nclear_temp_files = false\nsave_replays = true\nrun_at_start = \nrun_at_finish = \nsave_comments = false\n"
 				config_file = open("pyinstalive.ini", "w")
 				config_file.write(config_template)
 				config_file.close()
@@ -363,7 +346,7 @@ def run():
 		try:
 			config.read('pyinstalive.ini')
 		except Exception:
-			log("[E] Could not read configuration file. Try passing the required arguments manually.", "RED")
+			log("[E] Could not read configuration file.", "RED")
 			seperator("GREEN")
 	else:
 		new_config()

+ 1 - 6
pyinstalive/settings.py

@@ -11,9 +11,4 @@ class settings:
 	save_replays = "true"
 	run_at_start = "None"
 	run_at_finish = "None"
-	save_comments = "true"
-	ftp_host = "ftp.cluster020.hosting.ovh.net"
-	ftp_save_path = "/"
-	ftp_username = "milliemelp"
-	ftp_password = "xXkzcdV9SMZU"
-	ftp_enabled = False
+	save_comments = "true"