80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
import string
|
|
from deezer import TrackFormats
|
|
import os
|
|
|
|
def generateReplayGainString(trackGain):
|
|
return "{0:.2f} dB".format((float(trackGain) + 18.4) * -1)
|
|
|
|
def getBitrateNumberFromText(txt):
|
|
txt = str(txt).lower()
|
|
if txt in ['flac', 'lossless', '9']:
|
|
return TrackFormats.FLAC
|
|
elif txt in ['mp3', '320', '3']:
|
|
return TrackFormats.MP3_320
|
|
elif txt in ['128', '1']:
|
|
return TrackFormats.MP3_128
|
|
elif txt in ['360', '360_hq', '15']:
|
|
return TrackFormats.MP4_RA3
|
|
elif txt in ['360_mq', '14']:
|
|
return TrackFormats.MP4_RA2
|
|
elif txt in ['360_lq', '13']:
|
|
return TrackFormats.MP4_RA1
|
|
else:
|
|
return None
|
|
|
|
def changeCase(str, type):
|
|
if type == "lower":
|
|
return str.lower()
|
|
elif type == "upper":
|
|
return str.upper()
|
|
elif type == "start":
|
|
return string.capwords(str)
|
|
elif type == "sentence":
|
|
return str.capitalize()
|
|
else:
|
|
return str
|
|
|
|
def removeFeatures(title):
|
|
clean = title
|
|
if "(feat." in clean.lower():
|
|
pos = clean.lower().find("(feat.")
|
|
tempTrack = clean[:pos]
|
|
if ")" in clean:
|
|
tempTrack += clean[clean.find(")", pos + 1) + 1:]
|
|
clean = tempTrack.strip()
|
|
clean = ' '.join(clean.split())
|
|
return clean
|
|
|
|
def andCommaConcat(lst):
|
|
tot = len(lst)
|
|
result = ""
|
|
for i, art in enumerate(lst):
|
|
result += art
|
|
if tot != i + 1:
|
|
if tot - 1 == i + 1:
|
|
result += " & "
|
|
else:
|
|
result += ", "
|
|
return result
|
|
|
|
def uniqueArray(arr):
|
|
for iPrinc, namePrinc in enumerate(arr):
|
|
for iRest, nRest in enumerate(arr):
|
|
if iPrinc!=iRest and namePrinc.lower() in nRest.lower():
|
|
del arr[iRest]
|
|
return arr
|
|
|
|
def removeDuplicateArtists(artist, artists):
|
|
artists = uniqueArray(artists)
|
|
for role in artist.keys():
|
|
artist[role] = uniqueArray(artist[role])
|
|
return (artist, artists)
|
|
|
|
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)
|