Fixed encoding issues

This commit is contained in:
RemixDev 2021-12-21 12:40:35 +01:00
parent 133314f481
commit 13efa2bc90
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
6 changed files with 24 additions and 23 deletions

1
.gitignore vendored
View File

@ -35,3 +35,4 @@ build
*egg-info
updatePyPi.sh
deezer
.cache

View File

@ -44,11 +44,11 @@ def download(url, bitrate, portable, path):
return arl
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()
if not dz.login_via_arl(arl): 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)
plugins = {}
@ -101,7 +101,7 @@ def download(url, bitrate, portable, path):
isfile = False
if isfile:
filename = url[0]
with open(filename) as f:
with open(filename, encoding="utf-8") as f:
url = f.readlines()
downloadLinks(url, bitrate)

View File

@ -376,8 +376,8 @@ class Downloader:
# Save lyrics in lrc file
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]:
with open(filepath / f"{filename}.lrc", 'wb') as f:
f.write(track.lyrics.sync.encode('utf-8'))
with open(filepath / f"{filename}.lrc", 'w', encoding="utf-8") as f:
f.write(track.lyrics.sync)
# Check for overwrite settings
trackAlreadyDownloaded = writepath.is_file()
@ -531,12 +531,12 @@ class Downloader:
# Create searched logfile
if self.settings['logSearched'] and 'searched' in track:
filename = f"{track.data.artist} - {track.data.title}"
with open(self.downloadObject.extrasPath / 'searched.txt', 'wb+') as f:
searchedFile = f.read().decode('utf-8')
with open(self.downloadObject.extrasPath / 'searched.txt', 'w+', encoding="utf-8") as f:
searchedFile = f.read()
if not filename in searchedFile:
if searchedFile != "": searchedFile += "\r\n"
searchedFile += filename + "\r\n"
f.write(searchedFile.encode('utf-8'))
f.write(searchedFile)
# Execute command after download
if self.settings['executeCommand'] != "":
@ -575,13 +575,13 @@ class Downloader:
# Create errors logfile
if self.settings['logErrors'] and errors != "":
with open(self.downloadObject.extrasPath / 'errors.txt', 'wb') as f:
f.write(errors.encode('utf-8'))
with open(self.downloadObject.extrasPath / 'errors.txt', 'w', encoding="utf-8") as f:
f.write(errors)
# Create searched logfile
if self.settings['logSearched'] and searched != "":
with open(self.downloadObject.extrasPath / 'searched.txt', 'wb') as f:
f.write(searched.encode('utf-8'))
with open(self.downloadObject.extrasPath / 'searched.txt', 'w', encoding="utf-8") as f:
f.write(searched)
# Save Playlist Artwork
if self.settings['saveArtwork'] and self.playlistCoverName and not self.settings['tags']['savePlaylistAsCompilation']:
@ -591,9 +591,9 @@ class Downloader:
# Create M3U8 File
if self.settings['createM3U8File']:
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:
f.write((line + "\n").encode('utf-8'))
f.write(line + "\n")
# Execute command after download
if self.settings['executeCommand'] != "":

View File

@ -306,14 +306,14 @@ class Spotify(Plugin):
def loadSettings(self):
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)
with open(self.configFolder / 'settings.json', 'r') as settingsFile:
with open(self.configFolder / 'settings.json', 'r', encoding="utf-8") as settingsFile:
try:
settings = json.load(settingsFile)
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)
settings = deepcopy({**self.credentials, **self.settings})
except Exception:
@ -325,7 +325,7 @@ class Spotify(Plugin):
def saveSettings(self, newSettings=None):
if newSettings: self.setSettings(newSettings)
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)
def getSettings(self):
@ -340,14 +340,14 @@ class Spotify(Plugin):
def loadCache(self):
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)
else:
cache = {'tracks': {}, 'albums': {}}
return cache
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)
def checkCredentials(self):

View File

@ -105,7 +105,7 @@ def save(settings, configFolder=None):
configFolder = Path(configFolder or localpaths.getConfigFolder())
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)
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
# Read config file
with open(configFolder / 'config.json', 'r') as configFile:
with open(configFolder / 'config.json', 'r', encoding="utf-8") as configFile:
try:
settings = json.load(configFile)
except json.decoder.JSONDecodeError:

View File

@ -44,7 +44,7 @@ def getMusicFolder():
musicdata = Path(os.getenv("XDG_MUSIC_DIR"))
musicdata = checkPath(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()
musicdata_search = re.search(r"XDG_MUSIC_DIR=\"(.*)\"", userDirs)
if musicdata_search: