diff --git a/.gitignore b/.gitignore index 6f9d14b..b8f4931 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ build *egg-info updatePyPi.sh deezer +.cache diff --git a/deemix/__main__.py b/deemix/__main__.py index 9e64c6d..39a878a 100644 --- a/deemix/__main__.py +++ b/deemix/__main__.py @@ -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) diff --git a/deemix/downloader.py b/deemix/downloader.py index c79708f..4f5ac74 100644 --- a/deemix/downloader.py +++ b/deemix/downloader.py @@ -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'] != "": diff --git a/deemix/plugins/spotify.py b/deemix/plugins/spotify.py index ec104b9..a9b72e4 100644 --- a/deemix/plugins/spotify.py +++ b/deemix/plugins/spotify.py @@ -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): diff --git a/deemix/settings.py b/deemix/settings.py index b196101..1f0656c 100644 --- a/deemix/settings.py +++ b/deemix/settings.py @@ -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: diff --git a/deemix/utils/localpaths.py b/deemix/utils/localpaths.py index 2b2d797..b8ac8d5 100644 --- a/deemix/utils/localpaths.py +++ b/deemix/utils/localpaths.py @@ -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: