summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Steinke <rasi@xssn.at>2015-02-15 23:09:40 +0100
committerRasmus Steinke <rasi@xssn.at>2015-02-15 23:09:40 +0100
commit00779a16ea6fb1892daba3a2bb9767232a1b7e94 (patch)
treecafa062f3e56a91d530b6e569a8ec5806678c780
parentf073b3145c994ba16aa888f1f662fc6392bd5b14 (diff)
downloadmppc-00779a16ea6fb1892daba3a2bb9767232a1b7e94.tar.gz
mppc-00779a16ea6fb1892daba3a2bb9767232a1b7e94.tar.bz2
common function for caches
-rwxr-xr-xmppc74
1 files changed, 26 insertions, 48 deletions
diff --git a/mppc b/mppc
index 04e4d7c..607bc37 100755
--- a/mppc
+++ b/mppc
@@ -153,72 +153,50 @@ def stopSong(args):
mpd_status = client.status()
statusMPD(args)
-def trackCache(args):
- artistlist=client.list('artist')
+def lookup(key, fields):
+ artistlist = client.list(key)
content = set()
- errors = set()
- errors2 = set()
- fields = ('artist', 'track', 'title', 'album')
- fh = open(os.getenv('HOME')+'/.config/clerk/tracks.cache', "w")
for artist in artistlist:
- for element in client.find('artist', artist):
- # die werte aller felder
+ for element in client.find(key, artist):
elementvalues = []
for field in fields:
- # der wert dieses einen feldes
- fieldvalue = element[field]
+ if field in element:
+ fieldvalue = element[field]
+ else:
+ fieldvalue = ''
if isinstance(fieldvalue, list):
elementvalues.append(fieldvalue[0])
else:
elementvalues.append(fieldvalue)
- # alle felder wurden abgegrast
- content.add(os.getenv('separator').join(elementvalues))
- for line in sorted(content, key=str.lower):
- fh.write(line+"\n")
- fh.close()
+ content.add(tuple(elementvalues))
+ return content
+def trackCache(args):
+ key = 'artist'
+ fields = ('artist', 'track', 'title', 'album')
+ content = lookup(key, fields)
+ fh = open(os.getenv('HOME')+'/.config/clerk/tracks.cache', "w")
+ entries = [os.getenv('separator').join(entry) for entry in content]
+ for entry in sorted(entries, key=lambda x:str.lower):
+ fh.write(entry+"\n")
+ fh.close()
def albumCache(args):
- artistlist=client.list('albumartist')
- content = set()
+ key = 'albumartist'
fields = ('albumartist', 'date', 'album')
+ content = lookup(key, fields)
fh = open(os.getenv('HOME')+'/.config/clerk/album.cache', "w")
- for artist in artistlist:
- for element in client.find('albumartist', artist):
- # die werte aller felder
- elementvalues = []
- for field in fields:
- # der wert dieses einen feldes
- fieldvalue = element[field]
- if isinstance(fieldvalue, list):
- elementvalues.append(fieldvalue[0])
- else:
- elementvalues.append(fieldvalue)
- # alle felder wurden abgegrast
- content.add(os.getenv('separator').join(elementvalues))
- for line in sorted(content, key=str.lower):
- fh.write(line+"\n")
+ entries = [os.getenv('separator').join(entry) for entry in content]
+ for entry in sorted(entries, key=lambda x:str.lower):
+ fh.write(entry+"\n")
fh.close()
def lastCache(args):
- artistlist=client.list('albumartist')
- content = set()
+ key = 'albumartist'
fields = ('last-modified', 'date', 'albumartist', 'album')
- fh = open(os.getenv('HOME')+'/.config/clerk/last.cache', "w")
+ content = lookup(key, fields)
seen = set()
- for artist in artistlist:
- for element in client.find('albumartist', artist):
- # die werte aller felder
- elementvalues = []
- for field in fields:
- # der wert dieses einen feldes
- fieldvalue = element[field]
- if isinstance(fieldvalue, list):
- elementvalues.append(fieldvalue[0])
- else:
- elementvalues.append(fieldvalue)
- # alle felder wurden abgegrast
- content.add(tuple(elementvalues))
+ fh = open(os.getenv('HOME')+'/.config/clerk/last.cache', "w")
for element in sorted(content, key=lambda elem: elem[0], reverse=True):
if element[1:] not in seen:
line = element[1:]