예제 #1
0
파일: nicefm.py 프로젝트: npcardoso/nicefm
def mpd_find(mpd, items, query_type, duplicates):
    ret = []

    if query_type == "albums":
        field = "album"
    elif query_type == "songs":
        field = "title"
    else:
        raise Exception("Invalid query type.")

    count, func = duplicates

    if func == "random":
        def func(x):
            random.shuffle(x)
            return x
    elif func == "first":
        func = lambda(x): x
    elif func == "last":
        def func(x):
            x.reverse()
            return x
    else:
        raise Exception("Invalid duplicate resolution method (%s)." % func)

    for t in items:
        search = mpd._execute('search',['artist', t['artist'], field, t['title']])
        if count:
            search = func(search)[0:count]
        ret = ret + [i['file'] for i in search]
    return ret
예제 #2
0
파일: nicefm.py 프로젝트: npcardoso/nicefm
def mpd_add_tracks(mpd, playlist, tracks):
    mpd._execute('playlistclear', [playlist])
    for t in tracks:
        mpd._execute('playlistadd', [playlist, t])