summaryrefslogtreecommitdiffstats
path: root/feeding_example.py
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2010-08-23 22:45:10 +0200
committerLaurent Bachelier <laurent@bachelier.name>2010-08-23 22:48:04 +0200
commit415630d657067695d460b19eba1509bdd3bf610a (patch)
tree04e1ee4eba99368a3c5e4dd5430bb254e0e449c4 /feeding_example.py
parentSome method documentation (diff)
downloadmpdat-415630d657067695d460b19eba1509bdd3bf610a.tar.xz
Cache and autoupdate final dirs
When and only when the MPD database is updated, the final dirs are computed again, on demand. The client code has been enhanced and simplified. It's not perfect yet (it reads the file each time the function is called, we could have an in-memory cache too).
Diffstat (limited to 'feeding_example.py')
-rwxr-xr-xfeeding_example.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/feeding_example.py b/feeding_example.py
index 404af27..d9bde2b 100755
--- a/feeding_example.py
+++ b/feeding_example.py
@@ -12,10 +12,14 @@ m.connect_from_env(mpd_host, mpd_port)
m.wait_for_update()
# get all "final" directories
-m.update_final_dirs("")
+nb_dirs = len(m.get_final_dirs())
+print "We have found %s albums." % nb_dirs
# if the playlist is empty, add one random album
-if m.is_playlist_hungry(1):
- m.add(m.get_random_dir())
+while m.is_playlist_hungry(100) and nb_dirs:
+ rdir = m.get_random_dir()
+ m.add(rdir)
+ print "Added %s" % rdir
print m.status()
+print m.stats()