Пример #1
0
    def REQ_infos(self):
        format = web.input().get('fmt', 'txt')

        _d = self.player.selected or dict()
        # add player infos
        _d['song_position'] = self.player.position
        _d['paused'] = self.player._paused

        if format.startswith('htm'):
            web.header('Content-Type', 'text/html; charset=utf-8')
        return dump_data_as_text(_d, format)
Пример #2
0
    def REQ_genres(self):
        """ List all the genres

        Keywords:
            fmt (str, optional): output format

        Returns:
            A list of genres in desired format
        """
        inp = web.input()
        for d in dump_data_as_text(zshell.songs.genres, inp.get('fmt', 'txt')):
            yield d
Пример #3
0
    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)
Пример #4
0
    def REQ_playlist(self):
        i = web.input()
        pls = self.player.playlist

        start = int(i.get('start', 0))

        format = i.get('fmt', 'txt')
        if start < 0:
            start = len(pls) + start

        if i.get('res'):
            r = int(i.res)
            if r > 0:
                end = start + r
            else:
                # compute from end
                end = len(pls) + r
        else:
            end = len(pls)

        window_iterator = (pls[i] + [i] for i in xrange(start, min(len(pls), end)))

        return dump_data_as_text(window_iterator, format)
Пример #5
0
                some_db = zshell.songs.databases.itervalues().next()['handle']
                # try to pre-compute useful things
                field_decoder = zip( WEB_FIELDS,
                        (some_db.f_decode[some_db.fields[fname]] for fname in WEB_FIELDS)
                        )
                yield ''

                infos_iterator = ( [r[0]] + [d(r[1][r[1].fields.index(f)]) for f, d in field_decoder]
                        for r in res )
                if format == 'json':
                    d = jdump
                else:
                    def d(line):
                        return ' | '.join(line[:4])

                try:
                    # TODO: optimise this (jdump by 100 size blocks)
                    for r in infos_iterator:
                        yield d(r)
                        yield '\n'
                    web.debug('handled in %.2fs (%.2f for select)'%(time() - t0, t_sel - t0))
                except Exception, e:
                    DEBUG()
                    web.debug("ERR: %s(%s)"% (type(e), e))
            else:
                # TODO: add support for zip output (returns a zip stream with all the songs)
                web.debug('unknown search mode')
                for r in res:
                    yield dump_data_as_text(r, format)