Moved utils.misc in utils
This commit is contained in:
parent
e020592d18
commit
3b2a5ac3bb
|
@ -14,7 +14,7 @@ from tempfile import gettempdir
|
||||||
|
|
||||||
from deemix.app.queueitem import QISingle, QICollection
|
from deemix.app.queueitem import QISingle, QICollection
|
||||||
from deemix.app.track import Track
|
from deemix.app.track import Track
|
||||||
from deemix.utils.misc import changeCase
|
from deemix.utils import changeCase
|
||||||
from deemix.utils.pathtemplates import generateFilename, generateFilepath, settingsRegexAlbum, settingsRegexArtist, settingsRegexPlaylistFile
|
from deemix.utils.pathtemplates import generateFilename, generateFilepath, settingsRegexAlbum, settingsRegexArtist, settingsRegexPlaylistFile
|
||||||
from deemix.api.deezer import USER_AGENT_HEADER
|
from deemix.api.deezer import USER_AGENT_HEADER
|
||||||
from deemix.utils.taggers import tagID3, tagFLAC
|
from deemix.utils.taggers import tagID3, tagFLAC
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from deemix.app.downloadjob import DownloadJob
|
from deemix.app.downloadjob import DownloadJob
|
||||||
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
|
from deemix.utils import getIDFromLink, getTypeFromLink, getBitrateInt
|
||||||
from deemix.api.deezer import APIError
|
from deemix.api.deezer import APIError
|
||||||
from spotipy.exceptions import SpotifyException
|
from spotipy.exceptions import SpotifyException
|
||||||
from deemix.app.queueitem import QueueItem, QISingle, QICollection, QIConvertable
|
from deemix.app.queueitem import QueueItem, QISingle, QICollection, QIConvertable
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from deemix.api.deezer import APIError
|
from deemix.api.deezer import APIError
|
||||||
from deemix.utils.misc import removeFeatures, andCommaConcat, uniqueArray
|
from deemix.utils import removeFeatures, andCommaConcat, uniqueArray
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger('deemix')
|
logger = logging.getLogger('deemix')
|
||||||
|
|
|
@ -1,2 +1,118 @@
|
||||||
#!/usr/bin/env python3
|
import re
|
||||||
# Empty File
|
import string
|
||||||
|
|
||||||
|
def getBitrateInt(txt):
|
||||||
|
txt = str(txt).lower()
|
||||||
|
if txt in ['flac', 'lossless', '9']:
|
||||||
|
return 9
|
||||||
|
elif txt in ['mp3', '320', '3']:
|
||||||
|
return 3
|
||||||
|
elif txt in ['128', '1']:
|
||||||
|
return 1
|
||||||
|
elif txt in ['360', '360_hq', '15']:
|
||||||
|
return 15
|
||||||
|
elif txt in ['360_mq', '14']:
|
||||||
|
return 14
|
||||||
|
elif txt in ['360_lq', '13']:
|
||||||
|
return 13
|
||||||
|
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()
|
||||||
|
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 getIDFromLink(link, type):
|
||||||
|
if '?' in link:
|
||||||
|
link = link[:link.find('?')]
|
||||||
|
if link.endswith("/"):
|
||||||
|
link = link[:-1]
|
||||||
|
|
||||||
|
if link.startswith("http") and 'open.spotify.com/' in link:
|
||||||
|
if type == "spotifyplaylist":
|
||||||
|
return link[link.find("/playlist/") + 10:]
|
||||||
|
if type == "spotifytrack":
|
||||||
|
return link[link.find("/track/") + 7:]
|
||||||
|
if type == "spotifyalbum":
|
||||||
|
return link[link.find("/album/") + 7:]
|
||||||
|
elif link.startswith("spotify:"):
|
||||||
|
if type == "spotifyplaylist":
|
||||||
|
return link[link.find("playlist:") + 9:]
|
||||||
|
if type == "spotifytrack":
|
||||||
|
return link[link.find("track:") + 6:]
|
||||||
|
if type == "spotifyalbum":
|
||||||
|
return link[link.find("album:") + 6:]
|
||||||
|
elif type == "artisttop":
|
||||||
|
return re.search(r"\/artist\/(\d+)\/top_track", link)[1]
|
||||||
|
elif type == "artistdiscography":
|
||||||
|
return re.search(r"\/artist\/(\d+)\/discography", link)[1]
|
||||||
|
else:
|
||||||
|
return link[link.rfind("/") + 1:]
|
||||||
|
|
||||||
|
|
||||||
|
def getTypeFromLink(link):
|
||||||
|
type = ''
|
||||||
|
if 'spotify' in link:
|
||||||
|
type = 'spotify'
|
||||||
|
if 'playlist' in link:
|
||||||
|
type += 'playlist'
|
||||||
|
elif 'track' in link:
|
||||||
|
type += 'track'
|
||||||
|
elif 'album' in link:
|
||||||
|
type += 'album'
|
||||||
|
elif 'deezer' in link:
|
||||||
|
if '/track' in link:
|
||||||
|
type = 'track'
|
||||||
|
elif '/playlist' in link:
|
||||||
|
type = 'playlist'
|
||||||
|
elif '/album' in link:
|
||||||
|
type = 'album'
|
||||||
|
elif re.search("\/artist\/(\d+)\/top_track", link):
|
||||||
|
type = 'artisttop'
|
||||||
|
elif re.search("\/artist\/(\d+)\/discography", link):
|
||||||
|
type = 'artistdiscography'
|
||||||
|
elif '/artist' in link:
|
||||||
|
type = 'artist'
|
||||||
|
return type
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -1,120 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
import re
|
|
||||||
import string
|
|
||||||
|
|
||||||
|
|
||||||
def getBitrateInt(txt):
|
|
||||||
txt = str(txt).lower()
|
|
||||||
if txt in ['flac', 'lossless', '9']:
|
|
||||||
return 9
|
|
||||||
elif txt in ['mp3', '320', '3']:
|
|
||||||
return 3
|
|
||||||
elif txt in ['128', '1']:
|
|
||||||
return 1
|
|
||||||
elif txt in ['360', '360_hq', '15']:
|
|
||||||
return 15
|
|
||||||
elif txt in ['360_mq', '14']:
|
|
||||||
return 14
|
|
||||||
elif txt in ['360_lq', '13']:
|
|
||||||
return 13
|
|
||||||
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()
|
|
||||||
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 getIDFromLink(link, type):
|
|
||||||
if '?' in link:
|
|
||||||
link = link[:link.find('?')]
|
|
||||||
if link.endswith("/"):
|
|
||||||
link = link[:-1]
|
|
||||||
|
|
||||||
if link.startswith("http") and 'open.spotify.com/' in link:
|
|
||||||
if type == "spotifyplaylist":
|
|
||||||
return link[link.find("/playlist/") + 10:]
|
|
||||||
if type == "spotifytrack":
|
|
||||||
return link[link.find("/track/") + 7:]
|
|
||||||
if type == "spotifyalbum":
|
|
||||||
return link[link.find("/album/") + 7:]
|
|
||||||
elif link.startswith("spotify:"):
|
|
||||||
if type == "spotifyplaylist":
|
|
||||||
return link[link.find("playlist:") + 9:]
|
|
||||||
if type == "spotifytrack":
|
|
||||||
return link[link.find("track:") + 6:]
|
|
||||||
if type == "spotifyalbum":
|
|
||||||
return link[link.find("album:") + 6:]
|
|
||||||
elif type == "artisttop":
|
|
||||||
return re.search(r"\/artist\/(\d+)\/top_track", link)[1]
|
|
||||||
elif type == "artistdiscography":
|
|
||||||
return re.search(r"\/artist\/(\d+)\/discography", link)[1]
|
|
||||||
else:
|
|
||||||
return link[link.rfind("/") + 1:]
|
|
||||||
|
|
||||||
|
|
||||||
def getTypeFromLink(link):
|
|
||||||
type = ''
|
|
||||||
if 'spotify' in link:
|
|
||||||
type = 'spotify'
|
|
||||||
if 'playlist' in link:
|
|
||||||
type += 'playlist'
|
|
||||||
elif 'track' in link:
|
|
||||||
type += 'track'
|
|
||||||
elif 'album' in link:
|
|
||||||
type += 'album'
|
|
||||||
elif 'deezer' in link:
|
|
||||||
if '/track' in link:
|
|
||||||
type = 'track'
|
|
||||||
elif '/playlist' in link:
|
|
||||||
type = 'playlist'
|
|
||||||
elif '/album' in link:
|
|
||||||
type = 'album'
|
|
||||||
elif re.search("\/artist\/(\d+)\/top_track", link):
|
|
||||||
type = 'artisttop'
|
|
||||||
elif re.search("\/artist\/(\d+)\/discography", link):
|
|
||||||
type = 'artistdiscography'
|
|
||||||
elif '/artist' in link:
|
|
||||||
type = 'artist'
|
|
||||||
return type
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
Loading…
Reference in New Issue