diff --git a/spotdl/internals.py b/spotdl/internals.py index 76fc6d9..a36c7a2 100755 --- a/spotdl/internals.py +++ b/spotdl/internals.py @@ -4,6 +4,10 @@ from logzero import logger as log from spotdl import const +try: + import winreg +except ImportError: + pass try: from slugify import SLUG_OK, slugify @@ -174,8 +178,7 @@ def get_unique_tracks(text_file): return lines - -# a hacky way to user's localized music directory +# a hacky way to get user's localized music directory # (thanks @linusg, issue #203) def get_music_dir(): home = os.path.expanduser('~') @@ -191,6 +194,15 @@ def get_music_dir(): if line.startswith('XDG_MUSIC_DIR'): return os.path.expandvars(line.strip().split('=')[1].strip('"')) + # Windows / Cygwin + # Queries registry for 'My Music' folder path (as this can be changed) + if 'win' in sys.platform: + try: + key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", 0, winreg.KEY_ALL_ACCESS) + return winreg.QueryValueEx(key, "My Music")[0] + except (FileNotFoundError, NameError): + pass + # On both Windows and macOS, the localized folder names you see in # Explorer and Finder are actually in English on the file system. # So, defaulting to C:\Users\\Music or /Users//Music