Ejemplo n.º 1
0
def do_search(out=None, edit_mode=False):
    """ Search for song, display results.
    out can be "m3u" or "null", defaults to human-readable
    """

    duration = 0
    start_t = time()

    fields = list(valid_tags)
    fields.remove('filename')
    fields = tuple(fields)

    if callable(out):
        song_output = out
    elif out == 'm3u':
        print "#EXTM3U"
        def song_output(song):
            print u"#EXTINF:%d,%s - %s\n%s"%(song.length, song.artist, song.title, song.filename)
    elif out == 'null':
        def song_output(song): pass
    else:
        def song_output(song):
            txt = '%s :\n%s [%s, score: %s, tags: %s]'%(song.filename,
                    '%s - %s - %s'%(song.artist, song.album, song.title),
                    duration_tidy(song.length), song.score, song.tags,
                    )
            print txt.decode('utf8').encode('utf8')

    pat = string2python(' '.join(zshell.args))
    if edit_mode:
        search_fn = zshell.songs.u_search
    else:
        search_fn = zshell.songs.search

    num = 0
    for num, res in enumerate(search_fn(None, pat)):
        song_output(res)
        duration += res.length

    sys.stderr.write("# %d results in %s for a total of %s!\n"%(
            num,
            duration_tidy(time()-start_t),
            duration_tidy(duration)
            ))
Ejemplo n.º 2
0
                DEBUG()

        else: # XXX: move that to a dedicated command ? (ex: .../db/q?pattern=... looks nice)
            # or use "index" ... (sounds good too !)
            format = af['fmt'].value or 'html'
            if format == 'm3u':
                web.header('Content-Type', 'audio/x-mpegurl')
            elif format == 'html':
                web.header('Content-Type', 'text/html; charset=utf-8')

            pattern = af['pattern'].value

            if pattern is None:
                res = xrange(0)
            else:
                pat = string2python(pattern)
                web.debug('PAT %r'%pat)
                urlencode = web.http.urlencode
                ci = compact_int

                res = ([hd+'/db/get/%s?id=%s'%('song.'+ r.filename.rsplit('.', 1)[-1].lower(), ci(int(r.__id__))), r]
                        for r in zshell.songs.search(list(WEB_FIELDS+['filename']), pat)
                        )
            t_sel = time()

            if format == 'm3u':
                yield unicode(render.m3u(web.http.url, res))
            elif format == 'zip':
                web.header('Content-Type', 'application/zip')
                import tempfile
                tmp_file = tempfile.NamedTemporaryFile()