mirror of
				https://github.com/KevinMidboe/spotify-downloader.git
				synced 2025-10-29 18:00:15 +00:00 
			
		
		
		
	Optional parameter to check if the encoder exists
If `must_exists` is `False` when intializing `EncoderFFmpeg()`, skip skip checking whether the FFmpeg binary exists. Fixes #722.
This commit is contained in:
		| @@ -37,12 +37,12 @@ class EncoderBase(ABC): | |||||||
|     """ |     """ | ||||||
|  |  | ||||||
|     @abstractmethod |     @abstractmethod | ||||||
|     def __init__(self, encoder_path, loglevel, additional_arguments=[]): |     def __init__(self, encoder_path, must_exist, loglevel, additional_arguments=[]): | ||||||
|         """ |         """ | ||||||
|         This method must make sure whether specified encoder |         This method must make sure whether specified encoder | ||||||
|         is available under PATH. |         is available under PATH. | ||||||
|         """ |         """ | ||||||
|         if shutil.which(encoder_path) is None: |         if must_exist and shutil.which(encoder_path) is None: | ||||||
|             raise EncoderNotFoundError( |             raise EncoderNotFoundError( | ||||||
|                 "{} executable does not exist or was not found in PATH.".format( |                 "{} executable does not exist or was not found in PATH.".format( | ||||||
|                     encoder_path |                     encoder_path | ||||||
|   | |||||||
| @@ -27,11 +27,11 @@ RULES = { | |||||||
|  |  | ||||||
|  |  | ||||||
| class EncoderFFmpeg(EncoderBase): | class EncoderFFmpeg(EncoderBase): | ||||||
|     def __init__(self, encoder_path="ffmpeg"): |     def __init__(self, encoder_path="ffmpeg", must_exist=True): | ||||||
|         _loglevel = "-hide_banner -nostats -v panic" |         _loglevel = "-hide_banner -nostats -v panic" | ||||||
|         _additional_arguments = ["-b:a", "192k", "-vn"] |         _additional_arguments = ["-b:a", "192k", "-vn"] | ||||||
|         try: |         try: | ||||||
|             super().__init__(encoder_path, _loglevel, _additional_arguments) |             super().__init__(encoder_path, must_exist, _loglevel, _additional_arguments) | ||||||
|         except EncoderNotFoundError as e: |         except EncoderNotFoundError as e: | ||||||
|             raise FFmpegNotFoundError(e.args[0]) |             raise FFmpegNotFoundError(e.args[0]) | ||||||
|         self._rules = RULES |         self._rules = RULES | ||||||
|   | |||||||
| @@ -44,9 +44,9 @@ class Track: | |||||||
|         return progress_bar |         return progress_bar | ||||||
|  |  | ||||||
|     def download_while_re_encoding(self, stream, target_path, target_encoding=None, |     def download_while_re_encoding(self, stream, target_path, target_encoding=None, | ||||||
|                                    encoder=EncoderFFmpeg, show_progress=True): |                                    encoder=EncoderFFmpeg(must_exist=False), show_progress=True): | ||||||
|         total_chunks = self.calculate_total_chunks(stream["filesize"]) |         total_chunks = self.calculate_total_chunks(stream["filesize"]) | ||||||
|         process = encoder().re_encode_from_stdin( |         process = encoder.re_encode_from_stdin( | ||||||
|             stream["encoding"], |             stream["encoding"], | ||||||
|             target_path, |             target_path, | ||||||
|             target_encoding=target_encoding |             target_encoding=target_encoding | ||||||
| @@ -80,10 +80,10 @@ class Track: | |||||||
|                 writer(response, progress_bar, file_io) |                 writer(response, progress_bar, file_io) | ||||||
|  |  | ||||||
|     def re_encode(self, input_path, target_path, target_encoding=None, |     def re_encode(self, input_path, target_path, target_encoding=None, | ||||||
|                   encoder=EncoderFFmpeg, show_progress=True): |                   encoder=EncoderFFmpeg(must_exist=False), show_progress=True): | ||||||
|         stream = self.metadata["streams"].getbest() |         stream = self.metadata["streams"].getbest() | ||||||
|         total_chunks = self.calculate_total_chunks(stream["filesize"]) |         total_chunks = self.calculate_total_chunks(stream["filesize"]) | ||||||
|         process = encoder().re_encode_from_stdin( |         process = encoder.re_encode_from_stdin( | ||||||
|             stream["encoding"], |             stream["encoding"], | ||||||
|             target_path, |             target_path, | ||||||
|             target_encoding=target_encoding |             target_encoding=target_encoding | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user