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
__version__ = "1.5.12"
__version__ = "1.5.13"

View File

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

View File

@ -3,6 +3,7 @@ from pathlib import Path
from os import makedirs, listdir
from deemix import __version__ as deemixVersion
from deemix.api.deezer import TrackFormats
from deemix.utils import checkFolder
import logging
import datetime
import platform
@ -142,10 +143,11 @@ class Settings:
with open(self.configFolder / 'config.json', 'r') as configFile:
self.settings = json.load(configFile)
self.settingsCheck()
# 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
@ -173,6 +175,9 @@ class Settings:
def saveSettings(self, newSettings=None, dz=None):
if newSettings:
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
with open(self.configFolder / 'config.json', 'w') as configFile:
json.dump(self.settings, configFile, indent=2)
@ -189,7 +194,8 @@ class Settings:
self.settings['tags'][set] = DEFAULT_SETTINGS['tags'][set]
changes += 1
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
for template in ['tracknameTemplate', 'albumTracknameTemplate', 'playlistTracknameTemplate', 'playlistNameTemplate', 'artistNameTemplate', 'albumNameTemplate', 'playlistFilenameTemplate', 'coverImageTemplate', 'artistImageTemplate', 'paddingSize']:
if self.settings[template] == "":

View File

@ -1,6 +1,7 @@
import re
import string
from deemix.api.deezer import TrackFormats
import os
def generateReplayGainString(trackGain):
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():
del arr[iRest]
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(
name="deemix",
version="1.5.12",
version="1.5.13",
description="A barebone deezer downloader library",
long_description=README,
long_description_content_type="text/markdown",