Ejemplo n.º 1
0
 def new_playlist(self, name):
     data = self.ne.new_playlist(self.uid, name)
     if not self.is_response_avaible(data):
         return None
     playlist = data['playlist']
     playlist['uid'] = playlist['userId']
     playlist['tracks'] = []
     playlist['type'] = playlist['adType']
     playlist_model = PlaylistModel(playlist)
     return playlist_model
Ejemplo n.º 2
0
    def get_playlist_detail(self, pid, cache=True):
        """貌似这个请求会比较慢

        :param pid:
        :return:
        """
        # LOG.info(time.ctime())
        data = self.ne.playlist_detail(pid)  # 当列表内容多的时候,耗时久
        # LOG.info(time.ctime())

        data['uid'] = data['userId']
        data['type'] = data['specialType']

        for i, track in enumerate(data['tracks']):
            data['tracks'][i] = access_music(track)
        model = PlaylistModel(data).get_model()
        LOG.info('Update playlist cache finish: ' + model['name'])
        return model
Ejemplo n.º 3
0
    def get_playlist_detail(self, pid, cache=True):
        """貌似这个请求会比较慢

        :param pid:
        :return:
        """
        data = self.ne.playlist_detail(pid)  # 当列表内容多的时候,耗时久
        if not self.is_data_avaible(data):
            return data

        data = data['result']

        data['uid'] = data['userId']
        data['type'] = data['specialType']

        for i, track in enumerate(data['tracks']):
            data['tracks'][i] = access_music(track)
        model = PlaylistModel(data).get_dict()
        LOG.debug('Update playlist cache finish: ' + model['name'])
        return model
Ejemplo n.º 4
0
    def get_playlist_detail(self, pid, cache=True):
        if (cache is True) and PlaylistDb.exists(pid):
            LOG.info("Read playlist %d info from sqlite" % (pid))
            return PlaylistDb.get_data(pid)

        data = self.ne.playlist_detail(pid)  # 当列表内容多的时候,耗时久
        if not self.is_response_avaible(data):
            return data

        data = data['result']
        data['uid'] = data['userId']
        data['type'] = data['specialType']
        for i, track in enumerate(data['tracks']):
            data['tracks'][i] = self.access_music(track)
        model = PlaylistModel(data).get_dict()

        if PlaylistDb.exists(pid):
            PlaylistDb.update_data(pid, model)
        else:
            playlist = PlaylistDb(pid=pid, _data=pickle.dumps(model))
            playlist.save()

        LOG.info('Save playlist %d info to sqlite' % pid)
        return model