33from youtube import Youtube
44from editor import TagEditor
55from lastfm import LastFM
6+ from deezer import Deezer
67import sys , getopt , shutil
78import os
89
@@ -22,6 +23,7 @@ def __init__(self):
2223 self .__spotify = Spotify ()
2324 self .__editor = TagEditor ()
2425 self .__last = LastFM ()
26+ self .__deezer = Deezer ()
2527
2628
2729 def __downloadMusicFromYoutube (self , name , uri , dur ):
@@ -59,6 +61,9 @@ def getData(self, uri):
5961 def getLastFMTags (self , name ):
6062 return self .__last .get (name )
6163
64+ def getDeezerTags (self , id ):
65+ return self .__deezer .getSongInfo (id )
66+
6267 def getYoutubeMusicInfo (self , url ):
6368 return self .__youtube .getNameFromYoutube (url )
6469
@@ -302,12 +307,70 @@ def downloadFromYoutubeMusic(self, url, info):
302307 else :
303308 return False , None
304309
310+ def downloadByDeezerID (self , uri ):
311+ #get info
312+ info = self .__deezer .getSongInfo (uri )
313+
314+ if info :
315+
316+ fixed_name = f'{ info ["artist" ][0 ]} - { info ["name" ]} '
317+ fixed_name = fixed_name .replace ('.' ,'' )
318+ fixed_name = fixed_name .replace (',' ,'' )
319+ fixed_name = fixed_name .replace ("'" ,'' )
320+ fixed_name = fixed_name .replace ("/" ,"" )
321+
322+ #finding and download from YouTube and tagging
323+ if self .__downloadMusicFromYoutube (fixed_name , info ['uri' ], info ['duration_ms' ]):
324+
325+ self .__editor .setTags (
326+ data = info
327+ )
328+
329+ cachepath = os .getcwd () + '/cache'
330+ fullpath = os .getcwd () + '/Downloads'
331+
332+ #logging
333+ logging .info (f'CACHEPATH { cachepath } ' )
334+ logging .info (f'FULLPATH { fullpath } ' )
335+
336+ if not os .path .exists (fullpath ):
337+ os .makedirs (fullpath )
338+
339+ os .rename (
340+ f"{ cachepath } /{ info ['uri' ]} /{ info ['uri' ]} .png" ,
341+ f"{ fullpath } /{ info ['uri' ]} .png"
342+ )
343+ #logging
344+ logging .info (f"MOVE TO Downloads/{ info ['uri' ]} .png" )
345+
346+ os .rename (
347+ f"{ cachepath } /{ info ['uri' ]} /{ info ['uri' ]} .mp3" ,
348+ f"{ fullpath } /{ info ['uri' ]} .mp3"
349+ )
350+ #logging
351+ logging .info (f"MOVE TO Downloads/{ info ['uri' ]} .mp3" )
352+
353+ #deleting cache
354+ try :
355+ shutil .rmtree (f"cache/{ info ['uri' ]} " )
356+ #logging
357+ logging .info (f"DELETED cache/{ info ['uri' ]} " )
358+ except :
359+ #logging
360+ logging .error (f"DELETING cache/{ info ['uri' ]} " )
361+
362+ return True
363+ return False
364+
305365 def search (self , query ):
306366 return self .__spotify .search (query = query )
307367
308368 def getAlbum (self , uri ):
309369 return self .__spotify .getAlbum (uri )
310370
371+ def getAlbumDeezer (self , id ):
372+ return self .__deezer .getAlbum (id )
373+
311374
312375
313376class CLI (object ):
0 commit comments