mirror of
				https://github.com/KevinMidboe/spotify-downloader.git
				synced 2025-10-29 18:00:15 +00:00 
			
		
		
		
	Add a config option to preserve spaces in file names (#201)
* Add a config option to preserve spaces in file names * Typo * Fix replacing in path
This commit is contained in:
		
				
					committed by
					
						
						Ritiek Malhotra
					
				
			
			
				
	
			
			
			
						parent
						
							e283231f8e
						
					
				
				
					commit
					1fe94c9896
				
			
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							@@ -129,6 +129,8 @@ optional arguments:
 | 
				
			|||||||
  -d, --dry-run         Show only track title and YouTube URL (default: False)
 | 
					  -d, --dry-run         Show only track title and YouTube URL (default: False)
 | 
				
			||||||
  -mo, --music-videos-only
 | 
					  -mo, --music-videos-only
 | 
				
			||||||
                        Search only for music on Youtube (default: False)
 | 
					                        Search only for music on Youtube (default: False)
 | 
				
			||||||
 | 
					  -ps, --preserve-spaces
 | 
				
			||||||
 | 
					                        Preserve spaces on file names (default: False)
 | 
				
			||||||
  -ll {INFO,WARNING,ERROR,DEBUG}, --log-level {INFO,WARNING,ERROR,DEBUG}
 | 
					  -ll {INFO,WARNING,ERROR,DEBUG}, --log-level {INFO,WARNING,ERROR,DEBUG}
 | 
				
			||||||
                        set log verbosity (default: INFO)
 | 
					                        set log verbosity (default: INFO)
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
@@ -244,18 +246,6 @@ If you don't want to download all the songs to the `Music/` folder relative to t
 | 
				
			|||||||
E.g. `$ python3 spotdl.py -s "adele hello" -f "/home/user/Music/"`.
 | 
					E.g. `$ python3 spotdl.py -s "adele hello" -f "/home/user/Music/"`.
 | 
				
			||||||
This works with both relative and absolute paths.
 | 
					This works with both relative and absolute paths.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Preserve Spaces in File Names
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Beside some other characters, spaces will be replaced by underscores.
 | 
					 | 
				
			||||||
There's no option to change this behavior in spotify-downloader itself,
 | 
					 | 
				
			||||||
but on Unix-based operating systems you can issue the following bash
 | 
					 | 
				
			||||||
command after downloading is done:
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
$ find . -type f -name "*.mp3" -exec bash -c 'mv "$0" "${0//_/ }"' {} \;
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Just make sure your working directory is the one you have the music files in.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Config File
 | 
					## Config File
 | 
				
			||||||
 | 
					
 | 
				
			||||||
At first run, this tool will generate a `config.yml` in root directory
 | 
					At first run, this tool will generate a `config.yml` in root directory
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ default_conf = { 'spotify-downloader':
 | 
				
			|||||||
                   'download-only-metadata' : False,
 | 
					                   'download-only-metadata' : False,
 | 
				
			||||||
                   'dry-run'                : False,
 | 
					                   'dry-run'                : False,
 | 
				
			||||||
                   'music-videos-only'      : False,
 | 
					                   'music-videos-only'      : False,
 | 
				
			||||||
 | 
					                   'preserve-spaces'        : False,
 | 
				
			||||||
                   'log-level'              : 'INFO' }
 | 
					                   'log-level'              : 'INFO' }
 | 
				
			||||||
               }
 | 
					               }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -107,6 +108,10 @@ def get_arguments(to_group=True, raw_args=None):
 | 
				
			|||||||
        '-mo', '--music-videos-only', default=config['music-videos-only'],
 | 
					        '-mo', '--music-videos-only', default=config['music-videos-only'],
 | 
				
			||||||
        help='Search only for music on Youtube',
 | 
					        help='Search only for music on Youtube',
 | 
				
			||||||
        action='store_true')
 | 
					        action='store_true')
 | 
				
			||||||
 | 
					    parser.add_argument(
 | 
				
			||||||
 | 
					        '-ps', '--preserve-spaces', default=config['preserve-spaces'],
 | 
				
			||||||
 | 
					        help='Preserve spaces on file names',
 | 
				
			||||||
 | 
					        action='store_true')
 | 
				
			||||||
    parser.add_argument(
 | 
					    parser.add_argument(
 | 
				
			||||||
        '-ll', '--log-level', default=config['log-level'],
 | 
					        '-ll', '--log-level', default=config['log-level'],
 | 
				
			||||||
        choices=_LOG_LEVELS_STR,
 | 
					        choices=_LOG_LEVELS_STR,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -186,6 +186,10 @@ def grab_single(raw_song, number=None):
 | 
				
			|||||||
            if not const.args.no_metadata and meta_tags is not None:
 | 
					            if not const.args.no_metadata and meta_tags is not None:
 | 
				
			||||||
                metadata.embed(os.path.join(const.args.folder, output_song), meta_tags)
 | 
					                metadata.embed(os.path.join(const.args.folder, output_song), meta_tags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if const.args.preserve_spaces and "_" in output_song:
 | 
				
			||||||
 | 
					                song_path = os.path.join(const.args.folder, output_song.replace('_', ' '))
 | 
				
			||||||
 | 
					                os.rename(os.path.join(const.args.folder, output_song), song_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            log.error('No audio streams available')
 | 
					            log.error('No audio streams available')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user