Przeglądaj źródła

Add config option to use user-defined ffmpeg path

Cammy 6 lat temu
rodzic
commit
d222726096
6 zmienionych plików z 33 dodań i 3 usunięć
  1. 2 0
      .gitignore
  2. 4 0
      MOREHELP.md
  3. 1 0
      README.md
  4. 4 2
      pyinstalive/downloader.py
  5. 21 1
      pyinstalive/initialize.py
  6. 1 0
      pyinstalive/settings.py

+ 2 - 0
.gitignore

@@ -51,3 +51,5 @@ pyinstalive_win\.py
 
 
 win_building/
+
+*.exe

+ 4 - 0
MOREHELP.md

@@ -29,6 +29,7 @@
 username = johndoe
 password = grapefruits
 save_path = 
+ffmpeg_path = 
 show_cookie_expiry = true
 clear_temp_files = false
 save_lives = true
@@ -45,6 +46,9 @@ log_to_file = false
 
 ```save_path```  **—**  Path to the folder where downloaded Instagram livestreams and replays will be saved. PyInstaLive must have permission to write files to this folder. If left empty, PyInstaLive will attempt to fall back to the folder where it's being run from.
 
+```ffmpeg_path```  **—**  User-defined path to the FFmpeg binary. If left empty, PyInstaLive will fall back to the system's environment variable.
+
+
 ```show_cookie_expiry```  **—**  When set to True, PyInstaLive will show when the current cookie used to login will expire.
 
 ```clear_temp_files```  **—**  When set to True, PyInstaLive will delete all temporary files that were downloaded as well as the folders which contained these files. Replay folders created by PyInstaLive will not be deleted because they are used to determine if a replay has already been downloaded.

+ 1 - 0
README.md

@@ -92,6 +92,7 @@ Here is an example of a valid configuration file:
 username = johndoe
 password = grapefruits
 save_path = 
+ffmpeg_path = 
 show_cookie_expiry = true
 clear_temp_files = false
 save_lives = true

+ 4 - 2
pyinstalive/downloader.py

@@ -164,7 +164,8 @@ def download_livestream(broadcast):
 			duplicate_etag_retry=30,
 			callback_check=print_status,
 			mpd_download_timeout=3,
-			download_timeout=3)
+			download_timeout=3,
+			ffmpeg_binary=settings.ffmpeg_path)
 	except Exception as e:
 		log_error('Could not start downloading livestream: {:s}'.format(str(e)))
 		log_seperator()
@@ -476,7 +477,8 @@ def download_replays(broadcasts):
 				broadcast_downloader = replay.Downloader(
 					mpd=broadcast.get('dash_manifest'),
 					output_dir=output_dir,
-					user_agent=instagram_api.user_agent)
+					user_agent=instagram_api.user_agent,
+					ffmpeg_binary=settings.ffmpeg_path)
 				open(os.path.join(output_dir, 'folder.lock'), 'a').close()
 				replay_mp4_file = '{}{}_{}_{}_{}_replay.mp4'.format(settings.save_path, settings.current_date, user_to_download, broadcast.get('id'), settings.current_time)
 				replay_json_file = os.path.join(output_dir, '{}_{}_{}_{}_replay_comments.json'.format(settings.current_date, user_to_download, broadcast.get('id'), settings.current_time))

+ 21 - 1
pyinstalive/initialize.py

@@ -20,7 +20,10 @@ bool_values = {'True', 'False'}
 def check_ffmpeg():
 	try:
 		FNULL = open(os.devnull, 'w')
-		subprocess.call(["ffmpeg"], stdout=FNULL, stderr=subprocess.STDOUT)
+		if settings.ffmpeg_path == None:
+			subprocess.call(["ffmpeg"], stdout=FNULL, stderr=subprocess.STDOUT)
+		else:
+			subprocess.call([settings.ffmpeg_path], stdout=FNULL, stderr=subprocess.STDOUT)
 		return True
 	except OSError as e:
 		return False
@@ -159,6 +162,22 @@ def check_config_validity(config):
 			has_thrown_errors = True
 
 
+		try:
+			settings.ffmpeg_path = config.get('pyinstalive', 'ffmpeg_path')
+
+			if (os.path.exists(settings.ffmpeg_path)):
+				log_info_blue("Overriding FFmpeg path: {:s}".format(settings.ffmpeg_path))
+				log_seperator()
+			else:
+				log_warn("Invalid or missing setting detected for 'ffmpeg_path', falling back to environment variable.")
+				settings.ffmpeg_path = None
+				has_thrown_errors = True
+		except:
+			log_warn("Invalid or missing setting detected for 'ffmpeg_path', falling back to environment variable.")
+			settings.ffmpeg_path = None
+			has_thrown_errors = True
+
+
 		if has_thrown_errors:
 			log_seperator()
 
@@ -256,6 +275,7 @@ def new_config():
 username = johndoe
 password = grapefruits
 save_path = {:s}
+ffmpeg_path = 
 show_cookie_expiry = true
 clear_temp_files = false
 save_lives = true

+ 1 - 0
pyinstalive/settings.py

@@ -5,6 +5,7 @@ class settings:
 	username = ""
 	password = ""
 	save_path = "/"
+	ffmpeg_path = None
 	show_cookie_expiry = "true"
 	clear_temp_files = "false"
 	current_time = str(int(time.time()))