artist.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import demixed.utils
  2. from generic.object import Object
  3. import demixed.album
  4. instances = {}
  5. class DeezerArtist(Object):
  6. def set_raw_data(self, raw_data):
  7. artist_data = raw_data["DATA"]
  8. albums_data = raw_data["ALBUMS"]["data"]
  9. return self.set_values(
  10. artist_id = artist_data["ART_ID"],
  11. name = artist_data["ART_NAME"],
  12. picture_url = demixed.utils.ARTIST_PICTURES_URL % artist_data["ART_PICTURE"],
  13. albums = list(map(
  14. lambda a: demixed.album.DeezerAlbum.grab_or_create(
  15. a["ALB_ID"], raw_data = a
  16. ),
  17. albums_data
  18. )),
  19. is_full = True
  20. )
  21. def set_values(
  22. self,
  23. artist_id = None,
  24. name = None,
  25. picture_url = None,
  26. albums = None,
  27. is_full = False, # if the album is fully loaded
  28. raw_data = None
  29. ):
  30. if raw_data != None:
  31. self.set_raw_data(raw_data)
  32. return
  33. self.artist_id = artist_id
  34. self.name = name
  35. self.picture_url = picture_url
  36. self.albums = albums
  37. self.is_full = is_full
  38. def get_full_data(self, deezer_instance):
  39. if not self.is_full:
  40. raw_data = deezer_instance.get_artist_data(self.album_id)
  41. self.set_raw_data(raw_data)
  42. if self.albums != None:
  43. for album in self.albums:
  44. if not album.is_full:
  45. album.get_full_data(deezer_instance)