2
2
3
3
from pathlib import Path
4
4
from typing import Dict , List
5
+ import platform
5
6
6
7
from spotdl .providers import (
7
8
metadata_provider ,
@@ -58,6 +59,16 @@ def from_spotify_url(
58
59
song_name , [artist ["name" ] for artist in raw_track_meta ["artists" ]]
59
60
)
60
61
62
+ # Ensure file name doesnt contain forbidden characters
63
+ filesystem_display_name = display_name # Create copy of display_name for filesystem use
64
+ if platform .system () == 'Windows' :
65
+ for forbidden_letter in ['<' , '>' , ':' , '"' , '/' , '\\ ' , '|' , '?' , '*' ]:
66
+ converted_file_name = converted_file_name .replace (forbidden_letter , '' )
67
+ filesystem_display_name = filesystem_display_name .replace (forbidden_letter , '' )
68
+ else : # Linux or MacOS
69
+ converted_file_name = converted_file_name .replace ('/' , '' )
70
+ filesystem_display_name = filesystem_display_name .replace ('/' , '' )
71
+
61
72
# If song name is too long use only first artist
62
73
if len (converted_file_name ) > 250 :
63
74
converted_file_name = SongObject .create_file_name (
@@ -67,7 +78,7 @@ def from_spotify_url(
67
78
converted_file_path = Path ("." , f"{ converted_file_name } .{ output_format } " )
68
79
69
80
# Alternate file path.
70
- alternate_file_path = Path ("." , f"{ display_name } .{ output_format } " )
81
+ alternate_file_path = Path ("." , f"{ filesystem_display_name } .{ output_format } " )
71
82
72
83
# if a song is already downloaded skip it
73
84
if converted_file_path .is_file () or alternate_file_path .is_file ():
0 commit comments