コード例 #1
0
ファイル: httpdb.py プロジェクト: fdev31/zicbee
    def REQ_rate(self, song, rating):
        """ Rate a song
        rate/<song id>/<rating>

        Args:
            - song (int): song
            - rating (int): the rate you want to give to that song
        Returns:
            None
        """
        web.debug('rate: song=%s rating=%s'%(song,rating))
        try:
            with self._db_lock:
                song_id = uncompact_int(song)
                zshell.songs[song_id].update(score=int(rating))
        finally:
            refresh_db()
コード例 #2
0
ファイル: httpdb.py プロジェクト: fdev31/zicbee
    def REQ_multirate(self, ratings_list):
        """ Rate a list of songs
        multirate/[song id=rating]<,song id2=rating2><,song id3=rating3>...

        Args:
            - ratings_list: a list of tuples of the form::
                song=rating,song2=rating2,...
        Returns:
            None
        """
        web.debug('rate: ratings_list=%s'%ratings_list)
        try:
            ratings = [rating.split('=') for rating in ratings_list.split(',')]
            with self._db_lock:
                for song, rating in ratings:
                        song_id = uncompact_int(song)
                        zshell.songs[song_id].update(score=int(rating))
        finally:
            refresh_db()
コード例 #3
0
ファイル: httpdb.py プロジェクト: fdev31/zicbee
    def REQ_get(self, *args):
        af = DbSimpleSearchForm()
        if af.validates():
            af.fill()
            song_id = uncompact_int(af['id'].value)
        filename = zshell.songs[song_id].filename
        web.header('Content-Type', 'application/x-audio')
        web.header('Content-Disposition',
                'attachment; filename:%s'%filename.rsplit('/', 1)[-1], unique=True)

        CHUNK=1024
        in_fd = file(filename)
        web.header('Content-Length', str( os.fstat(in_fd.fileno()).st_size ) )
        yield ''

        while True:
            data = in_fd.read(CHUNK)
            if not data: break
            y = (yield data)
        in_fd.close()
        return
コード例 #4
0
ファイル: httpdb.py プロジェクト: fdev31/zicbee
    def REQ_infos(self, song_id):
        """ Show infos about a song
        Either positional parameter or ``id`` keyword has to be given

        Keywords:
            fmt (str): output format
            id (str): id of the song
        Args:
            song_id (int): index of the song
        Returns:
            all the metadatas in desired format
        """


        af = DbSimpleSearchForm()
        if af.validates():
            af.fill()
            song_id = uncompact_int(af['id'].value)
            fmt = af['fmt'].value

        song = zshell.songs[song_id]
        d = dict( (f, getattr(song, f)) for f in song.fields ) if song else {}
        return dump_data_as_text(d, fmt)
コード例 #5
0
ファイル: httpdb.py プロジェクト: fdev31/zicbee
    def REQ_tag(self, song, tag):
        """ Tags a song
        tag/<song id>/<tag>

        Args:
            - song (int): song
            - tag (str): the tag you want to add to that song
        Returns:
            None
        """

        song_id = uncompact_int(song)
        try:
            tag = unicode(tag)
            with self._db_lock:
                SEP=u','
                _t = zshell.songs[song_id].tags
                tag_set = set( _t.strip(SEP).split(SEP) ) if _t else set()
                for single_tag in tag.split(','):
                    tag_set.add(single_tag.strip())
                new_tag = ''.join((SEP,SEP.join(tag_set),SEP))
                zshell.songs[song_id].update(tags=new_tag)
        except Exception, e:
            web.debug('E!%s'%e)