Esempio n. 1
0
def get_last_search(output):
    uris = memory.get('last_search')
    if not uris:
        print "No previous search, use shell to re-use previous result!"
        return

    to_download = []
    all_filenames = set()
    dst_prefix = config.download_dir
    for infos in unroll(iter_webget(u) for u in memory['last_search']):
        if infos[-1] == '|':
            infos += ' '
        try:
            uri, artist, album, title = infos.split(' | ', 3)
        except ValueError:
            print repr(infos)
            import pdb; pdb.set_trace()
            raise
        ext = uri.rsplit('.', 1)[1].rsplit('?', 1)[0].strip()
        if len(ext) < 2:
            print "WARNING: Ext=%s for %s\n"%(ext, uri)
            ext = 'mp3'
        title = title.replace(os.path.sep, '-').split('\n', 1)[0]
        album = album.replace(os.path.sep, '-').split('\n', 1)[0]
        artist = artist.replace(os.path.sep, '-').split('\n', 1)[0]

        out_dir = os.path.join(dst_prefix.strip(), artist.strip(), album.strip())
        fname = os.path.join(out_dir, title.strip() or 'unknown') + "."
        if fname+ext in all_filenames:
            count = 1
            while True:
                new_name = "%s-%d%s"%(fname, count, ext)
                if new_name not in all_filenames:
                    fname = new_name
                    break
                count += 1
        else:
            fname += ext

        out_dir = os.path.dirname(fname)

        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        to_download.append((uri, fname))
        all_filenames.add(fname)
    del all_filenames
    Downloader().run(to_download)
    output((e[1] for e in to_download))
Esempio n. 2
0
def show_random_result(it):
    uri = modify_show(None)
    return ('-'.join(r.split('|')[1:4]) for r in iter_webget(uri))
Esempio n. 3
0
def random_command(output, what='artist'):
    dbh = config.db_host[0]
    arg = iter_webget('http://%s/db/random?what=%s'%(dbh, what)).next()
    return '/search?%s&host=%s'%(arg, dbh)
Esempio n. 4
0
                                print "Wrong number of arguments"
                                return
            else:
                try:
                    uris = [pattern%expansion]
                except TypeError:
                    print "Wrong number of arguments"
                    return

        except Exception, e:
            print "Invalid arguments: %s"%e

    if extras.get('uri_hook'):
        extras['uri_hook'](uris)

    r = unroll(iter_webget(uri) for uri in uris)

    if r:
        def _finish(r, out=None):
            if extras.get('display_modifier'):
                r = extras['display_modifier'](r)
            if out:
                out(r)
            else:
                if debug_enabled:
                    for l in r:
                        out(r)
                else:
                    for l in r:
                        pass