Пример #1
0
 def __init__(self, song: Song, tags: [Tag]=None, sources: [Source]=None):
     assert isinstance(song, Song)
     super(JamendoSongEntity, self).__init__(song)
     # The given tags plus the persisted tags of the song, if the song is already persisted.
     if tags is not None:
         self.tags = set(tags + (song.tags.all() if song.id is not None else []))
     else:
         self.tags = song.tags.all() if song.id is not None else []
     # The given sources plus the persisted sources of the song, if the song is already persisted.
     if sources is not None:
         self.sources = set(sources + (song.sources() if song.id is not None else []))
     else:
         self.sources = song.sources() if song.id is not None else []
Пример #2
0
 def __init__(self,
              song: Song,
              tags: [Tag] = None,
              sources: [Source] = None):
     assert isinstance(song, Song)
     super(JamendoSongEntity, self).__init__(song)
     # The given tags plus the persisted tags of the song, if the song is already persisted.
     if tags is not None:
         self.tags = set(tags +
                         (song.tags.all() if song.id is not None else []))
     else:
         self.tags = song.tags.all() if song.id is not None else []
     # The given sources plus the persisted sources of the song, if the song is already persisted.
     if sources is not None:
         self.sources = set(sources +
                            (song.sources() if song.id is not None else []))
     else:
         self.sources = song.sources() if song.id is not None else []
Пример #3
0
    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))
Пример #4
0
 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
Пример #5
0
    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))
Пример #6
0
 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