diff options
Diffstat (limited to 'pydora/audio_backend.py')
-rw-r--r-- | pydora/audio_backend.py | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/pydora/audio_backend.py b/pydora/audio_backend.py index aecd87e..1186d93 100644 --- a/pydora/audio_backend.py +++ b/pydora/audio_backend.py | |||
@@ -13,22 +13,19 @@ log = logging.getLogger("pydora.audio_backend") | |||
13 | 13 | ||
14 | 14 | ||
15 | class PlayerException(Exception): | 15 | class PlayerException(Exception): |
16 | """Base class for all player exceptions | 16 | """Base class for all player exceptions""" |
17 | """ | ||
18 | 17 | ||
19 | pass | 18 | pass |
20 | 19 | ||
21 | 20 | ||
22 | class UnsupportedEncoding(PlayerException): | 21 | class UnsupportedEncoding(PlayerException): |
23 | """Song encoding is not supported by player backend | 22 | """Song encoding is not supported by player backend""" |
24 | """ | ||
25 | 23 | ||
26 | pass | 24 | pass |
27 | 25 | ||
28 | 26 | ||
29 | class PlayerUnusable(PlayerException): | 27 | class PlayerUnusable(PlayerException): |
30 | """Player can not be used on this system | 28 | """Player can not be used on this system""" |
31 | """ | ||
32 | 29 | ||
33 | pass | 30 | pass |
34 | 31 | ||
@@ -67,13 +64,11 @@ class BasePlayer: | |||
67 | raise NotImplementedError | 64 | raise NotImplementedError |
68 | 65 | ||
69 | def _load_track(self, song): | 66 | def _load_track(self, song): |
70 | """Load a track into the audio backend by song model | 67 | """Load a track into the audio backend by song model""" |
71 | """ | ||
72 | raise NotImplementedError | 68 | raise NotImplementedError |
73 | 69 | ||
74 | def _player_stopped(self, value): | 70 | def _player_stopped(self, value): |
75 | """Determine if player has stopped | 71 | """Determine if player has stopped""" |
76 | """ | ||
77 | raise NotImplementedError | 72 | raise NotImplementedError |
78 | 73 | ||
79 | def raise_volume(self): | 74 | def raise_volume(self): |
@@ -93,13 +88,11 @@ class BasePlayer: | |||
93 | raise NotImplementedError | 88 | raise NotImplementedError |
94 | 89 | ||
95 | def _post_start(self): | 90 | def _post_start(self): |
96 | """Optionally, do something after the audio backend is started | 91 | """Optionally, do something after the audio backend is started""" |
97 | """ | ||
98 | return | 92 | return |
99 | 93 | ||
100 | def _loop_hook(self): | 94 | def _loop_hook(self): |
101 | """Optionally, do something each main loop iteration | 95 | """Optionally, do something each main loop iteration""" |
102 | """ | ||
103 | return | 96 | return |
104 | 97 | ||
105 | def _read_from_process(self, handle): | 98 | def _read_from_process(self, handle): |
@@ -111,19 +104,16 @@ class BasePlayer: | |||
111 | return handle.readline().strip() | 104 | return handle.readline().strip() |
112 | 105 | ||
113 | def _send_cmd(self, cmd): | 106 | def _send_cmd(self, cmd): |
114 | """Write command to remote process | 107 | """Write command to remote process""" |
115 | """ | ||
116 | self._process.stdin.write("{}\n".format(cmd).encode("utf-8")) | 108 | self._process.stdin.write("{}\n".format(cmd).encode("utf-8")) |
117 | self._process.stdin.flush() | 109 | self._process.stdin.flush() |
118 | 110 | ||
119 | def stop(self): | 111 | def stop(self): |
120 | """Stop the currently playing song | 112 | """Stop the currently playing song""" |
121 | """ | ||
122 | self._send_cmd("stop") | 113 | self._send_cmd("stop") |
123 | 114 | ||
124 | def pause(self): | 115 | def pause(self): |
125 | """Pause the player | 116 | """Pause the player""" |
126 | """ | ||
127 | self._send_cmd("pause") | 117 | self._send_cmd("pause") |
128 | 118 | ||
129 | def __del__(self): | 119 | def __del__(self): |
@@ -138,8 +128,7 @@ class BasePlayer: | |||
138 | self._ensure_started() | 128 | self._ensure_started() |
139 | 129 | ||
140 | def _ensure_started(self): | 130 | def _ensure_started(self): |
141 | """Ensure player backing process is started | 131 | """Ensure player backing process is started""" |
142 | """ | ||
143 | if self._process and self._process.poll() is None: | 132 | if self._process and self._process.poll() is None: |
144 | return | 133 | return |
145 | 134 | ||
@@ -189,8 +178,7 @@ class BasePlayer: | |||
189 | self._callbacks.post_poll() | 178 | self._callbacks.post_poll() |
190 | 179 | ||
191 | def end_station(self): | 180 | def end_station(self): |
192 | """Stop playing the station | 181 | """Stop playing the station""" |
193 | """ | ||
194 | raise StopIteration | 182 | raise StopIteration |
195 | 183 | ||
196 | def play_station(self, station): | 184 | def play_station(self, station): |
@@ -208,8 +196,7 @@ class BasePlayer: | |||
208 | 196 | ||
209 | 197 | ||
210 | class MPG123Player(BasePlayer): | 198 | class MPG123Player(BasePlayer): |
211 | """Player Backend Using mpg123 | 199 | """Player Backend Using mpg123""" |
212 | """ | ||
213 | 200 | ||
214 | def __init__(self, callbacks, control_channel): | 201 | def __init__(self, callbacks, control_channel): |
215 | super().__init__(callbacks, control_channel) | 202 | super().__init__(callbacks, control_channel) |