def new_by_json(cls, json: {str: str}): """ Create a new JamendoSongEntity from the song received from jamendo as json dictionary. :param json: the song received from jamendo as json dictionary. :return: the JamendoSongEntity of the given json dictionary. """ song = Song() song.name = json['name'] # Creates a jamendo profile for this song. song.jamendo_profile = JamendoSongProfile.objects.update_or_create(jamendo_id=json['id'], defaults={'name': json['name'], 'cover': json['image'], 'external_link': json['shareurl'], })[0] # Link to an album. try: song.album = JamendoAlbumEntity.get_or_create(name=json['album_name'], jamendo_id=json['album_id']) except ValueError as e: song.album = None logging.exception(e) # Link to an artist. try: song.artist = JamendoArtistEntity.get_or_create(name=json['artist_name'], jamendo_id=json['artist_id']) except ValueError as e: song.artist = None logging.exception(e) song.duration = int(json['duration']) song.release_date = json['releasedate'] song.cover = json['image'] song.license = cls.__get_or_create_license(json) return cls(song, tags=cls.__get_tags(json), sources=cls.__get_sources(json))
def new_by_json(cls, json: {str: str}): """ Create a new JamendoSongEntity from the song received from jamendo as json dictionary. :param json: the song received from jamendo as json dictionary. :return: the JamendoSongEntity of the given json dictionary. """ song = Song() song.name = json['name'] # Creates a jamendo profile for this song. song.jamendo_profile = JamendoSongProfile.objects.update_or_create( jamendo_id=json['id'], defaults={ 'name': json['name'], 'cover': json['image'], 'external_link': json['shareurl'], })[0] # Link to an album. try: song.album = JamendoAlbumEntity.get_or_create( name=json['album_name'], jamendo_id=json['album_id']) except ValueError as e: song.album = None logging.exception(e) # Link to an artist. try: song.artist = JamendoArtistEntity.get_or_create( name=json['artist_name'], jamendo_id=json['artist_id']) except ValueError as e: song.artist = None logging.exception(e) song.duration = int(json['duration']) song.release_date = json['releasedate'] song.cover = json['image'] song.license = cls.__get_or_create_license(json) return cls(song, tags=cls.__get_tags(json), sources=cls.__get_sources(json))
def _merge(cls, new: Song, old: Song) -> Song: if new.is_on_jamendo and not old.is_on_jamendo: old.jamendo_profile = new.jamendo_profile return old