Fixed encoding issues
This commit is contained in:
parent
133314f481
commit
13efa2bc90
|
@ -35,3 +35,4 @@ build
|
||||||
*egg-info
|
*egg-info
|
||||||
updatePyPi.sh
|
updatePyPi.sh
|
||||||
deezer
|
deezer
|
||||||
|
.cache
|
||||||
|
|
|
@ -44,11 +44,11 @@ def download(url, bitrate, portable, path):
|
||||||
return arl
|
return arl
|
||||||
|
|
||||||
if (configFolder / '.arl').is_file():
|
if (configFolder / '.arl').is_file():
|
||||||
with open(configFolder / '.arl', 'r') as f:
|
with open(configFolder / '.arl', 'r', encoding="utf-8") as f:
|
||||||
arl = f.readline().rstrip("\n").strip()
|
arl = f.readline().rstrip("\n").strip()
|
||||||
if not dz.login_via_arl(arl): arl = requestValidArl()
|
if not dz.login_via_arl(arl): arl = requestValidArl()
|
||||||
else: arl = requestValidArl()
|
else: arl = requestValidArl()
|
||||||
with open(configFolder / '.arl', 'w') as f:
|
with open(configFolder / '.arl', 'w', encoding="utf-8") as f:
|
||||||
f.write(arl)
|
f.write(arl)
|
||||||
|
|
||||||
plugins = {}
|
plugins = {}
|
||||||
|
@ -101,7 +101,7 @@ def download(url, bitrate, portable, path):
|
||||||
isfile = False
|
isfile = False
|
||||||
if isfile:
|
if isfile:
|
||||||
filename = url[0]
|
filename = url[0]
|
||||||
with open(filename) as f:
|
with open(filename, encoding="utf-8") as f:
|
||||||
url = f.readlines()
|
url = f.readlines()
|
||||||
|
|
||||||
downloadLinks(url, bitrate)
|
downloadLinks(url, bitrate)
|
||||||
|
|
|
@ -376,8 +376,8 @@ class Downloader:
|
||||||
# Save lyrics in lrc file
|
# Save lyrics in lrc file
|
||||||
if self.settings['syncedLyrics'] and track.lyrics.sync:
|
if self.settings['syncedLyrics'] and track.lyrics.sync:
|
||||||
if not (filepath / f"{filename}.lrc").is_file() or self.settings['overwriteFile'] in [OverwriteOption.OVERWRITE, OverwriteOption.ONLY_TAGS]:
|
if not (filepath / f"{filename}.lrc").is_file() or self.settings['overwriteFile'] in [OverwriteOption.OVERWRITE, OverwriteOption.ONLY_TAGS]:
|
||||||
with open(filepath / f"{filename}.lrc", 'wb') as f:
|
with open(filepath / f"{filename}.lrc", 'w', encoding="utf-8") as f:
|
||||||
f.write(track.lyrics.sync.encode('utf-8'))
|
f.write(track.lyrics.sync)
|
||||||
|
|
||||||
# Check for overwrite settings
|
# Check for overwrite settings
|
||||||
trackAlreadyDownloaded = writepath.is_file()
|
trackAlreadyDownloaded = writepath.is_file()
|
||||||
|
@ -531,12 +531,12 @@ class Downloader:
|
||||||
# Create searched logfile
|
# Create searched logfile
|
||||||
if self.settings['logSearched'] and 'searched' in track:
|
if self.settings['logSearched'] and 'searched' in track:
|
||||||
filename = f"{track.data.artist} - {track.data.title}"
|
filename = f"{track.data.artist} - {track.data.title}"
|
||||||
with open(self.downloadObject.extrasPath / 'searched.txt', 'wb+') as f:
|
with open(self.downloadObject.extrasPath / 'searched.txt', 'w+', encoding="utf-8") as f:
|
||||||
searchedFile = f.read().decode('utf-8')
|
searchedFile = f.read()
|
||||||
if not filename in searchedFile:
|
if not filename in searchedFile:
|
||||||
if searchedFile != "": searchedFile += "\r\n"
|
if searchedFile != "": searchedFile += "\r\n"
|
||||||
searchedFile += filename + "\r\n"
|
searchedFile += filename + "\r\n"
|
||||||
f.write(searchedFile.encode('utf-8'))
|
f.write(searchedFile)
|
||||||
|
|
||||||
# Execute command after download
|
# Execute command after download
|
||||||
if self.settings['executeCommand'] != "":
|
if self.settings['executeCommand'] != "":
|
||||||
|
@ -575,13 +575,13 @@ class Downloader:
|
||||||
|
|
||||||
# Create errors logfile
|
# Create errors logfile
|
||||||
if self.settings['logErrors'] and errors != "":
|
if self.settings['logErrors'] and errors != "":
|
||||||
with open(self.downloadObject.extrasPath / 'errors.txt', 'wb') as f:
|
with open(self.downloadObject.extrasPath / 'errors.txt', 'w', encoding="utf-8") as f:
|
||||||
f.write(errors.encode('utf-8'))
|
f.write(errors)
|
||||||
|
|
||||||
# Create searched logfile
|
# Create searched logfile
|
||||||
if self.settings['logSearched'] and searched != "":
|
if self.settings['logSearched'] and searched != "":
|
||||||
with open(self.downloadObject.extrasPath / 'searched.txt', 'wb') as f:
|
with open(self.downloadObject.extrasPath / 'searched.txt', 'w', encoding="utf-8") as f:
|
||||||
f.write(searched.encode('utf-8'))
|
f.write(searched)
|
||||||
|
|
||||||
# Save Playlist Artwork
|
# Save Playlist Artwork
|
||||||
if self.settings['saveArtwork'] and self.playlistCoverName and not self.settings['tags']['savePlaylistAsCompilation']:
|
if self.settings['saveArtwork'] and self.playlistCoverName and not self.settings['tags']['savePlaylistAsCompilation']:
|
||||||
|
@ -591,9 +591,9 @@ class Downloader:
|
||||||
# Create M3U8 File
|
# Create M3U8 File
|
||||||
if self.settings['createM3U8File']:
|
if self.settings['createM3U8File']:
|
||||||
filename = generateDownloadObjectName(self.settings['playlistFilenameTemplate'], self.downloadObject, self.settings) or "playlist"
|
filename = generateDownloadObjectName(self.settings['playlistFilenameTemplate'], self.downloadObject, self.settings) or "playlist"
|
||||||
with open(self.downloadObject.extrasPath / f'{filename}.m3u8', 'wb') as f:
|
with open(self.downloadObject.extrasPath / f'{filename}.m3u8', 'w', encoding="utf-8") as f:
|
||||||
for line in playlist:
|
for line in playlist:
|
||||||
f.write((line + "\n").encode('utf-8'))
|
f.write(line + "\n")
|
||||||
|
|
||||||
# Execute command after download
|
# Execute command after download
|
||||||
if self.settings['executeCommand'] != "":
|
if self.settings['executeCommand'] != "":
|
||||||
|
|
|
@ -306,14 +306,14 @@ class Spotify(Plugin):
|
||||||
|
|
||||||
def loadSettings(self):
|
def loadSettings(self):
|
||||||
if not (self.configFolder / 'settings.json').is_file():
|
if not (self.configFolder / 'settings.json').is_file():
|
||||||
with open(self.configFolder / 'settings.json', 'w') as f:
|
with open(self.configFolder / 'settings.json', 'w', encoding="utf-8") as f:
|
||||||
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
||||||
|
|
||||||
with open(self.configFolder / 'settings.json', 'r') as settingsFile:
|
with open(self.configFolder / 'settings.json', 'r', encoding="utf-8") as settingsFile:
|
||||||
try:
|
try:
|
||||||
settings = json.load(settingsFile)
|
settings = json.load(settingsFile)
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
with open(self.configFolder / 'settings.json', 'w') as f:
|
with open(self.configFolder / 'settings.json', 'w', encoding="utf-8") as f:
|
||||||
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
||||||
settings = deepcopy({**self.credentials, **self.settings})
|
settings = deepcopy({**self.credentials, **self.settings})
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -325,7 +325,7 @@ class Spotify(Plugin):
|
||||||
def saveSettings(self, newSettings=None):
|
def saveSettings(self, newSettings=None):
|
||||||
if newSettings: self.setSettings(newSettings)
|
if newSettings: self.setSettings(newSettings)
|
||||||
self.checkCredentials()
|
self.checkCredentials()
|
||||||
with open(self.configFolder / 'settings.json', 'w') as f:
|
with open(self.configFolder / 'settings.json', 'w', encoding="utf-8") as f:
|
||||||
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
||||||
|
|
||||||
def getSettings(self):
|
def getSettings(self):
|
||||||
|
@ -340,14 +340,14 @@ class Spotify(Plugin):
|
||||||
|
|
||||||
def loadCache(self):
|
def loadCache(self):
|
||||||
if (self.configFolder / 'cache.json').is_file():
|
if (self.configFolder / 'cache.json').is_file():
|
||||||
with open(self.configFolder / 'cache.json', 'r') as f:
|
with open(self.configFolder / 'cache.json', 'r', encoding="utf-8") as f:
|
||||||
cache = json.load(f)
|
cache = json.load(f)
|
||||||
else:
|
else:
|
||||||
cache = {'tracks': {}, 'albums': {}}
|
cache = {'tracks': {}, 'albums': {}}
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
def saveCache(self, newCache):
|
def saveCache(self, newCache):
|
||||||
with open(self.configFolder / 'cache.json', 'w') as spotifyCache:
|
with open(self.configFolder / 'cache.json', 'w', encoding="utf-8") as spotifyCache:
|
||||||
json.dump(newCache, spotifyCache)
|
json.dump(newCache, spotifyCache)
|
||||||
|
|
||||||
def checkCredentials(self):
|
def checkCredentials(self):
|
||||||
|
|
|
@ -105,7 +105,7 @@ def save(settings, configFolder=None):
|
||||||
configFolder = Path(configFolder or localpaths.getConfigFolder())
|
configFolder = Path(configFolder or localpaths.getConfigFolder())
|
||||||
makedirs(configFolder, exist_ok=True) # Create config folder if it doesn't exsist
|
makedirs(configFolder, exist_ok=True) # Create config folder if it doesn't exsist
|
||||||
|
|
||||||
with open(configFolder / 'config.json', 'w') as configFile:
|
with open(configFolder / 'config.json', 'w', encoding="utf-8") as configFile:
|
||||||
json.dump(settings, configFile, indent=2)
|
json.dump(settings, configFile, indent=2)
|
||||||
|
|
||||||
def load(configFolder=None):
|
def load(configFolder=None):
|
||||||
|
@ -114,7 +114,7 @@ def load(configFolder=None):
|
||||||
if not (configFolder / 'config.json').is_file(): save(DEFAULTS, configFolder) # Create config file if it doesn't exsist
|
if not (configFolder / 'config.json').is_file(): save(DEFAULTS, configFolder) # Create config file if it doesn't exsist
|
||||||
|
|
||||||
# Read config file
|
# Read config file
|
||||||
with open(configFolder / 'config.json', 'r') as configFile:
|
with open(configFolder / 'config.json', 'r', encoding="utf-8") as configFile:
|
||||||
try:
|
try:
|
||||||
settings = json.load(configFile)
|
settings = json.load(configFile)
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
|
|
|
@ -44,7 +44,7 @@ def getMusicFolder():
|
||||||
musicdata = Path(os.getenv("XDG_MUSIC_DIR"))
|
musicdata = Path(os.getenv("XDG_MUSIC_DIR"))
|
||||||
musicdata = checkPath(musicdata)
|
musicdata = checkPath(musicdata)
|
||||||
if (homedata / '.config' / 'user-dirs.dirs').is_file() and musicdata == "":
|
if (homedata / '.config' / 'user-dirs.dirs').is_file() and musicdata == "":
|
||||||
with open(homedata / '.config' / 'user-dirs.dirs', 'r') as f:
|
with open(homedata / '.config' / 'user-dirs.dirs', 'r', encoding="utf-8") as f:
|
||||||
userDirs = f.read()
|
userDirs = f.read()
|
||||||
musicdata_search = re.search(r"XDG_MUSIC_DIR=\"(.*)\"", userDirs)
|
musicdata_search = re.search(r"XDG_MUSIC_DIR=\"(.*)\"", userDirs)
|
||||||
if musicdata_search:
|
if musicdata_search:
|
||||||
|
|
Loading…
Reference in New Issue