mirror of
				https://github.com/KevinMidboe/spotify-downloader.git
				synced 2025-10-29 18:00:15 +00:00 
			
		
		
		
	Add the --trim-silence parameter
This commit is contained in:
		| @@ -15,11 +15,11 @@ https://trac.ffmpeg.org/wiki/Encode/AAC | |||||||
| """ | """ | ||||||
|  |  | ||||||
|  |  | ||||||
| def song(input_song, output_song, folder, avconv=False): | def song(input_song, output_song, folder, avconv=False, trim_silence=True): | ||||||
|     """ Do the audio format conversion. """ |     """ Do the audio format conversion. """ | ||||||
|     if input_song == output_song: |     if input_song == output_song: | ||||||
|         return 0 |         return 0 | ||||||
|     convert = Converter(input_song, output_song, folder) |     convert = Converter(input_song, output_song, folder, trim_silence) | ||||||
|     log.info('Converting {0} to {1}'.format( |     log.info('Converting {0} to {1}'.format( | ||||||
|         input_song, output_song.split('.')[-1])) |         input_song, output_song.split('.')[-1])) | ||||||
|     if avconv: |     if avconv: | ||||||
| @@ -30,9 +30,10 @@ def song(input_song, output_song, folder, avconv=False): | |||||||
|  |  | ||||||
|  |  | ||||||
| class Converter: | class Converter: | ||||||
|     def __init__(self, input_song, output_song, folder): |     def __init__(self, input_song, output_song, folder, trim_silence): | ||||||
|         self.input_file = os.path.join(folder, input_song) |         self.input_file = os.path.join(folder, input_song) | ||||||
|         self.output_file = os.path.join(folder, output_song) |         self.output_file = os.path.join(folder, output_song) | ||||||
|  |         self.trim_silence = trim_silence | ||||||
|  |  | ||||||
|     def with_avconv(self): |     def with_avconv(self): | ||||||
|         if log.level == 10: |         if log.level == 10: | ||||||
| @@ -44,6 +45,9 @@ class Converter: | |||||||
|                    self.input_file, '-ab', '192k', |                    self.input_file, '-ab', '192k', | ||||||
|                    self.output_file, '-y'] |                    self.output_file, '-y'] | ||||||
|          |          | ||||||
|  |         if self.trim_silence: | ||||||
|  |             log.warning('--trim-silence not supported with avconv') | ||||||
|  |          | ||||||
|         log.debug(command) |         log.debug(command) | ||||||
|         return subprocess.call(command) |         return subprocess.call(command) | ||||||
|  |  | ||||||
| @@ -75,8 +79,11 @@ class Converter: | |||||||
|  |  | ||||||
|         # add common params for any of the above combination |         # add common params for any of the above combination | ||||||
|         ffmpeg_params += '-b:a 192k -vn ' |         ffmpeg_params += '-b:a 192k -vn ' | ||||||
|         ffmpeg_params += '-af silenceremove=start_periods=1 ' |  | ||||||
|         ffmpeg_pre += ' -i' |         ffmpeg_pre += ' -i' | ||||||
|  |          | ||||||
|  |         if self.trim_silence: | ||||||
|  |             ffmpeg_params += '-af silenceremove=start_periods=1 ' | ||||||
|  |          | ||||||
|         command = ffmpeg_pre.split() + [self.input_file] + ffmpeg_params.split() + [self.output_file] |         command = ffmpeg_pre.split() + [self.input_file] + ffmpeg_params.split() + [self.output_file] | ||||||
|  |  | ||||||
|         log.debug(command) |         log.debug(command) | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ default_conf = { 'spotify-downloader': | |||||||
|                    'overwrite'              : 'prompt', |                    'overwrite'              : 'prompt', | ||||||
|                    'input-ext'              : '.m4a', |                    'input-ext'              : '.m4a', | ||||||
|                    'output-ext'             : '.mp3', |                    'output-ext'             : '.mp3', | ||||||
|  |                    'trim-silence'           : False, | ||||||
|                    'download-only-metadata' : False, |                    'download-only-metadata' : False, | ||||||
|                    'dry-run'                : False, |                    'dry-run'                : False, | ||||||
|                    'music-videos-only'      : False, |                    'music-videos-only'      : False, | ||||||
| @@ -153,6 +154,10 @@ def get_arguments(raw_args=None, to_group=True, to_merge=True): | |||||||
|         help='file format to save the downloaded track with, each tag ' |         help='file format to save the downloaded track with, each tag ' | ||||||
|              'is surrounded by curly braces. Possible formats: ' |              'is surrounded by curly braces. Possible formats: ' | ||||||
|              '{}'.format([internals.formats[x] for x in internals.formats])) |              '{}'.format([internals.formats[x] for x in internals.formats])) | ||||||
|  |     parser.add_argument( | ||||||
|  |         '--trim-silence', default=config['trim-silence'], | ||||||
|  |         help='remove silence from the start of the audio', | ||||||
|  |         action='store_true') | ||||||
|     parser.add_argument( |     parser.add_argument( | ||||||
|         '-sf', '--search-format', default=config['search-format'], |         '-sf', '--search-format', default=config['search-format'], | ||||||
|         help='search format to search for on YouTube, each tag ' |         help='search format to search for on YouTube, each tag ' | ||||||
|   | |||||||
| @@ -159,7 +159,7 @@ def download_single(raw_song, number=None): | |||||||
|             print('') |             print('') | ||||||
|             try: |             try: | ||||||
|                 convert.song(input_song, output_song, const.args.folder, |                 convert.song(input_song, output_song, const.args.folder, | ||||||
|                              avconv=const.args.avconv) |                              avconv=const.args.avconv, trim_silence=const.args.trim_silence) | ||||||
|             except FileNotFoundError: |             except FileNotFoundError: | ||||||
|                 encoder = 'avconv' if const.args.avconv else 'ffmpeg' |                 encoder = 'avconv' if const.args.avconv else 'ffmpeg' | ||||||
|                 log.warning('Could not find {0}, skipping conversion'.format(encoder)) |                 log.warning('Could not find {0}, skipping conversion'.format(encoder)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user