Added folderCheck for download folder

folderCheck checks if the folder exsists and it's writable
This commit is contained in:
RemixDev 2020-10-08 13:26:17 +02:00
parent 4d09925f64
commit a9a09c58e0
5 changed files with 24 additions and 8 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
__version__ = "1.5.12" __version__ = "1.5.13"

View File

@ -2,13 +2,14 @@ from pathlib import Path
from os import makedirs from os import makedirs
from deemix.app import deemix from deemix.app import deemix
from deemix.utils import checkFolder
class cli(deemix): class cli(deemix):
def __init__(self, downloadpath, configFolder=None): def __init__(self, downloadpath, configFolder=None):
super().__init__(configFolder) super().__init__(configFolder)
if downloadpath: if downloadpath:
if checkFolder(downloadpath):
self.set.settings['downloadLocation'] = str(downloadpath) self.set.settings['downloadLocation'] = str(downloadpath)
makedirs(downloadpath, exist_ok=True)
print("Using folder: "+self.set.settings['downloadLocation']) print("Using folder: "+self.set.settings['downloadLocation'])
def downloadLink(self, url, bitrate=None): def downloadLink(self, url, bitrate=None):

View File

@ -3,6 +3,7 @@ from pathlib import Path
from os import makedirs, listdir from os import makedirs, listdir
from deemix import __version__ as deemixVersion from deemix import __version__ as deemixVersion
from deemix.api.deezer import TrackFormats from deemix.api.deezer import TrackFormats
from deemix.utils import checkFolder
import logging import logging
import datetime import datetime
import platform import platform
@ -142,10 +143,11 @@ class Settings:
with open(self.configFolder / 'config.json', 'r') as configFile: with open(self.configFolder / 'config.json', 'r') as configFile:
self.settings = json.load(configFile) self.settings = json.load(configFile)
self.settingsCheck()
# Make sure the download path exsits # Make sure the download path exsits
makedirs(self.settings['downloadLocation'], exist_ok=True) if not checkFolder(self.settings['downloadLocation']) and self.settings['downloadLocation'] != "":
self.settings['downloadLocation'] = ""
self.settingsCheck()
# LOGFILES # LOGFILES
@ -173,6 +175,9 @@ class Settings:
def saveSettings(self, newSettings=None, dz=None): def saveSettings(self, newSettings=None, dz=None):
if newSettings: if newSettings:
if dz and newSettings.get('tagsLanguage') != self.settings.get('tagsLanguage'): dz.set_accept_language(newSettings.get('tagsLanguage')) if dz and newSettings.get('tagsLanguage') != self.settings.get('tagsLanguage'): dz.set_accept_language(newSettings.get('tagsLanguage'))
if newSettings.get('downloadLocation') != self.settings.get('downloadLocation') and not checkFolder(newSettings.get('downloadLocation')):
newSettings['downloadLocation'] = DEFAULT_SETTINGS['downloadLocation']
makedirs(newSettings['downloadLocation'], exist_ok=True)
self.settings = newSettings self.settings = newSettings
with open(self.configFolder / 'config.json', 'w') as configFile: with open(self.configFolder / 'config.json', 'w') as configFile:
json.dump(self.settings, configFile, indent=2) json.dump(self.settings, configFile, indent=2)
@ -189,7 +194,8 @@ class Settings:
self.settings['tags'][set] = DEFAULT_SETTINGS['tags'][set] self.settings['tags'][set] = DEFAULT_SETTINGS['tags'][set]
changes += 1 changes += 1
if self.settings['downloadLocation'] == "": if self.settings['downloadLocation'] == "":
self.settings['downloadLocation'] = str(localpaths.getHomeFolder() / 'deemix Music') self.settings['downloadLocation'] = DEFAULT_SETTINGS['downloadLocation']
makedirs(self.settings['downloadLocation'], exist_ok=True)
changes += 1 changes += 1
for template in ['tracknameTemplate', 'albumTracknameTemplate', 'playlistTracknameTemplate', 'playlistNameTemplate', 'artistNameTemplate', 'albumNameTemplate', 'playlistFilenameTemplate', 'coverImageTemplate', 'artistImageTemplate', 'paddingSize']: for template in ['tracknameTemplate', 'albumTracknameTemplate', 'playlistTracknameTemplate', 'playlistNameTemplate', 'artistNameTemplate', 'albumNameTemplate', 'playlistFilenameTemplate', 'coverImageTemplate', 'artistImageTemplate', 'paddingSize']:
if self.settings[template] == "": if self.settings[template] == "":

View File

@ -1,6 +1,7 @@
import re import re
import string import string
from deemix.api.deezer import TrackFormats from deemix.api.deezer import TrackFormats
import os
def generateReplayGainString(trackGain): def generateReplayGainString(trackGain):
return "{0:.2f} dB".format((float(trackGain) + 18.4) * -1) return "{0:.2f} dB".format((float(trackGain) + 18.4) * -1)
@ -120,3 +121,11 @@ def uniqueArray(arr):
if iPrinc!=iRest and namePrinc.lower() in nRest.lower(): if iPrinc!=iRest and namePrinc.lower() in nRest.lower():
del arr[iRest] del arr[iRest]
return arr return arr
def checkFolder(folder):
try:
os.makedirs(folder, exist_ok=True)
except Exception as e:
print(str(e))
return False
return os.access(folder, os.W_OK)

View File

@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
setup( setup(
name="deemix", name="deemix",
version="1.5.12", version="1.5.13",
description="A barebone deezer downloader library", description="A barebone deezer downloader library",
long_description=README, long_description=README,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",