summaryrefslogtreecommitdiffstats
path: root/mpdrast/process.py
blob: efe240d96cd19f823be21ec47cbb98c714432fd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from os.path import dirname

"""
Process MPDrastClient responses
"""

def get_files_and_dirs_from_db(items):
    """
    Returns (files, directories) from a source with files and directories mixed.
    """
    files = []
    dirs = []
    for item in items:
        if item.has_key("directory"):
            dirs.append(item["directory"])
        elif item.has_key("file"):
            files.append(item["file"])

    return (files, dirs)


def process_song(item):
    """
    Adds a "dir" attribute to songs, change "pos" to int
    """
    if item.has_key("file"):
        item["dir"] = dirname(item["file"])

    if item.has_key("pos"):
        item["pos"] = int(item["pos"])

    return item