summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2010-02-07 14:58:58 +0100
committerLaurent Bachelier <laurent@bachelier.name>2010-02-07 14:58:58 +0100
commit4337f5d5034a2d31c49bb5d36580ccfdda74dcb5 (patch)
treea1572654a33002ac57243bbc58fb7166262b020d
parentRemove whitespace (diff)
downloadmpdat-4337f5d5034a2d31c49bb5d36580ccfdda74dcb5.tar.xz
Fixes indentation
Switched from 2 spaces to 4 spaces
-rwxr-xr-xfeeding_example.py2
-rwxr-xr-xmpdrast/client.py132
-rw-r--r--mpdrast/process.py50
3 files changed, 92 insertions, 92 deletions
diff --git a/feeding_example.py b/feeding_example.py
index 73aca49..1e5d6de 100755
--- a/feeding_example.py
+++ b/feeding_example.py
@@ -16,6 +16,6 @@ m.update_final_dirs("")
# if the playlist is empty, add one random album
if m.is_playlist_hungry(1):
- m.add(m.get_random_dir())
+ m.add(m.get_random_dir())
print m.status()
diff --git a/mpdrast/client.py b/mpdrast/client.py
index fb52068..e23a8e3 100755
--- a/mpdrast/client.py
+++ b/mpdrast/client.py
@@ -6,70 +6,70 @@ import random
from process import MPDrastProcess
class MPDrastClient(mpd.MPDClient):
- def __init__(self):
- mpd.MPDClient.__init__(self)
- self.final_dirs = []
-
- def connect(self, host, port):
- password = None
- infos = host.split('@')
- if len(infos) == 2:
- password = infos[0]
- host = infos[1]
-
- mpd.MPDClient.connect(self, host, port)
- if password:
- self.password(password)
-
-
- def update_final_dirs(self, path="", first=True):
- if first:
- self.final_dirs = []
-
- items = self.lsinfo(path)
- if first and not items:
- raise Exception("database is empty")
-
- files, dirs = MPDrastProcess.get_files_and_dirs_from_db(items)
- if len(files) and len(dirs) == 0:
- self.final_dirs.append(path)
- else:
- for dir in dirs:
- self.update_final_dirs(dir, False)
-
-
- def wait_for_update(self):
- while self.status().has_key("updating_db"):
- time.sleep(1)
-
- def get_random_dir(self):
- return random.choice(self.final_dirs)
-
- # Om Nom Nom Nom
- 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 = (MPDrastProcess.process_song(item) for item in self.playlistinfo())
- value = None
- count = -1
- for song in pl:
- if value != song[type]:
- count = count + 1
- value = song[type]
- if count == number:
- return song["pos"]
-
- def clean_but(self, number=1, type="album"):
- pos = self._find_changing_pos(number, type)
-
- if pos:
- try:
- while True:
- self.delete(pos)
- except mpd.CommandError:
- pass
+ def __init__(self):
+ mpd.MPDClient.__init__(self)
+ self.final_dirs = []
+
+ def connect(self, host, port):
+ password = None
+ infos = host.split('@')
+ if len(infos) == 2:
+ password = infos[0]
+ host = infos[1]
+
+ mpd.MPDClient.connect(self, host, port)
+ if password:
+ self.password(password)
+
+
+ def update_final_dirs(self, path="", first=True):
+ if first:
+ self.final_dirs = []
+
+ items = self.lsinfo(path)
+ if first and not items:
+ raise Exception("database is empty")
+
+ files, dirs = MPDrastProcess.get_files_and_dirs_from_db(items)
+ if len(files) and len(dirs) == 0:
+ self.final_dirs.append(path)
+ else:
+ for dir in dirs:
+ self.update_final_dirs(dir, False)
+
+
+ def wait_for_update(self):
+ while self.status().has_key("updating_db"):
+ time.sleep(1)
+
+ def get_random_dir(self):
+ return random.choice(self.final_dirs)
+
+ # Om Nom Nom Nom
+ 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 = (MPDrastProcess.process_song(item) for item in self.playlistinfo())
+ value = None
+ count = -1
+ for song in pl:
+ if value != song[type]:
+ count = count + 1
+ value = song[type]
+ if count == number:
+ return song["pos"]
+
+ def clean_but(self, number=1, type="album"):
+ pos = self._find_changing_pos(number, type)
+
+ if pos:
+ try:
+ while True:
+ self.delete(pos)
+ except mpd.CommandError:
+ pass
diff --git a/mpdrast/process.py b/mpdrast/process.py
index c749c30..fabcd58 100644
--- a/mpdrast/process.py
+++ b/mpdrast/process.py
@@ -1,34 +1,34 @@
import posixpath
class MPDrastProcess:
- """
- Process MPDrastClient responses
- """
-
- @staticmethod
- def get_files_and_dirs_from_db(items):
"""
- Returns (files, directories) from a source with files and directories mixed.
+ Process MPDrastClient responses
"""
- 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)
+ @staticmethod
+ 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"])
- @staticmethod
- def process_song(item):
- """
- Adds a "dir" attribute to songs, change "pos" to int
- """
- if item.has_key("file"):
- item["dir"] = posixpath.dirname(item["file"])
+ return (files, dirs)
+
+ @staticmethod
+ def process_song(item):
+ """
+ Adds a "dir" attribute to songs, change "pos" to int
+ """
+ if item.has_key("file"):
+ item["dir"] = posixpath.dirname(item["file"])
- if item.has_key("pos"):
- item["pos"] = int(item["pos"])
+ if item.has_key("pos"):
+ item["pos"] = int(item["pos"])
- return item
+ return item