summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2010-07-26 22:05:44 +0200
committerLaurent Bachelier <laurent@bachelier.name>2010-07-26 22:06:18 +0200
commit76d7172413f141354a8b03da7f80e4e89c68c006 (patch)
treefb9f1212b938ab4ee1df695a4534ca9f08db6b9b
parentBetter imports (diff)
downloadmpdat-76d7172413f141354a8b03da7f80e4e89c68c006.tar.xz
Do not overload connect()
-rwxr-xr-xfeeding_example.py2
-rwxr-xr-xmpdrast/client.py10
-rw-r--r--mpdrast/process.py1
-rwxr-xr-xpruning_example.py2
4 files changed, 11 insertions, 4 deletions
diff --git a/feeding_example.py b/feeding_example.py
index 9cde3ac..404af27 100755
--- a/feeding_example.py
+++ b/feeding_example.py
@@ -6,7 +6,7 @@ mpd_host = environ.get("MPD_HOST", "localhost")
mpd_port = environ.get("MPD_PORT", 6600)
m = MPDrastClient()
-m.connect(mpd_host, mpd_port)
+m.connect_from_env(mpd_host, mpd_port)
# the user can run mpc update before; wait for completion
m.wait_for_update()
diff --git a/mpdrast/client.py b/mpdrast/client.py
index 26d6410..307200d 100755
--- a/mpdrast/client.py
+++ b/mpdrast/client.py
@@ -10,14 +10,15 @@ class MPDrastClient(mpd.MPDClient):
mpd.MPDClient.__init__(self)
self.final_dirs = []
- def connect(self, host, port):
+
+ def connect_from_env(self, host, port):
password = None
infos = host.split('@')
if len(infos) == 2:
password = infos[0]
host = infos[1]
- mpd.MPDClient.connect(self, host, port)
+ self.connect(host, port)
if password:
self.password(password)
@@ -42,15 +43,19 @@ class MPDrastClient(mpd.MPDClient):
while self.status().has_key("updating_db"):
time.sleep(1)
+
def get_random_dir(self):
return random.choice(self.final_dirs)
+
def is_playlist_hungry(self, hungriness=100):
return int(self.status()["playlistlength"]) < hungriness
+
def is_playlist_empty(self):
return int(self.status()["playlistlength"]) == 0
+
def _find_changing_pos(self, number, type):
pl = (process.process_song(item) for item in self.playlistinfo())
value = None
@@ -62,6 +67,7 @@ class MPDrastClient(mpd.MPDClient):
if count == number:
return song["pos"]
+
def clean_but(self, number=1, type="album"):
pos = self._find_changing_pos(number, type)
diff --git a/mpdrast/process.py b/mpdrast/process.py
index a7c7c3f..efe240d 100644
--- a/mpdrast/process.py
+++ b/mpdrast/process.py
@@ -18,6 +18,7 @@ def get_files_and_dirs_from_db(items):
return (files, dirs)
+
def process_song(item):
"""
Adds a "dir" attribute to songs, change "pos" to int
diff --git a/pruning_example.py b/pruning_example.py
index 1ced4d5..93ca7e0 100755
--- a/pruning_example.py
+++ b/pruning_example.py
@@ -7,7 +7,7 @@ mpd_host = environ.get("MPD_HOST", "localhost")
mpd_port = environ.get("MPD_PORT", 6600)
m = MPDrastClient()
-m.connect(mpd_host, mpd_port)
+m.connect_from_env(mpd_host, mpd_port)
# Keep only one album in the playlist
m.clean_but(1, "album")