Пример #1
0
 def create_song_model(self, data):
     title_list = data.get('title_list', [])
     title = title_list[0] if title_list else 'Unknown'
     artist_name_list = data.get('artist_name_list', [])
     album_name_list = data.get('album_name_list', [])
     identifier = str(elfhash(base64.b64encode(bytes(data['url'],
                                                     'utf-8'))))
     song_data = {
         'source':
         SOURCE,
         'identifier':
         identifier,
         'title':
         title,
         'duration':
         data['duration'],
         'url':
         data['url'],
         'artists': [{
             'name': name,
             'identifier': name,
             'source': SOURCE
         } for name in artist_name_list]
     }
     if album_name_list:
         song_data['album'] = {
             'name': album_name_list[0],
             'identifier': album_name_list[0],
             'source': SOURCE
         }
     song, _ = SongSchema(strict=True).load(song_data)
     return song
Пример #2
0
def gen_id(s):
    return str(elfhash(base64.b64encode(bytes(s, 'utf-8'))))
Пример #3
0
 def get_coll_id(self, coll):
     # TODO: 目前还没想好 collection identifier 计算方法,故添加这个函数
     # 现在把 fpath 当作 identifier 使用,但对外透明
     return elfhash(base64.b64encode(bytes(coll.fpath, 'utf-8')))
Пример #4
0
 def __hash__(self):
     try:
         id_hash = int(self.identifier)
     except ValueError:
         id_hash = elfhash(self.identifier.encode())
     return id_hash * 1000 + id(type(self)) % 1000