mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-08 20:39:08 +00:00
Windows - 'My Music' folder won't be assumed to be on C drive (#387)
* Windows - 'My Music' folder won't be assumed to be on C drive
Windows has a nice registry check to get the absolute path of the 'My Music' folder. This helps because some people change their location of their music folder.
* Updated according to suggestions
Let me know if there are anymore improvements 👍
* Fixups
This commit is contained in:
committed by
Ritiek Malhotra
parent
a565d449ea
commit
71ee6ad5e2
@@ -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\<user>\Music or /Users/<user>/Music
|
||||
|
||||
Reference in New Issue
Block a user