diff options
Diffstat (limited to 'pydora/player.py')
-rw-r--r-- | pydora/player.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/pydora/player.py b/pydora/player.py index 991468a..128674b 100644 --- a/pydora/player.py +++ b/pydora/player.py | |||
@@ -10,9 +10,11 @@ from __future__ import print_function | |||
10 | 10 | ||
11 | import os | 11 | import os |
12 | import sys | 12 | import sys |
13 | import argparse | ||
13 | from pandora import clientbuilder | 14 | from pandora import clientbuilder |
14 | 15 | ||
15 | from .utils import Colors, Screen | 16 | from .utils import Colors, Screen |
17 | from .audio_backend import RemoteVLC | ||
16 | from .audio_backend import MPG123Player, VLCPlayer | 18 | from .audio_backend import MPG123Player, VLCPlayer |
17 | from .audio_backend import UnsupportedEncoding, PlayerUnusable | 19 | from .audio_backend import UnsupportedEncoding, PlayerUnusable |
18 | 20 | ||
@@ -66,7 +68,20 @@ class PlayerApp(object): | |||
66 | self.client = None | 68 | self.client = None |
67 | self.screen = Screen() | 69 | self.screen = Screen() |
68 | 70 | ||
69 | def get_player(self): | 71 | def get_player(self, vlc_net=None): |
72 | # The user must explicitly request network VLC so we should always | ||
73 | # honor that request, to this end we try network first and fail hard | ||
74 | # if that isn't available. | ||
75 | if vlc_net: | ||
76 | try: | ||
77 | host, port = vlc_net.split(":") | ||
78 | player = RemoteVLC(host, port, self, sys.stdin) | ||
79 | Screen.print_success("Using Remote VLC") | ||
80 | return player | ||
81 | except PlayerUnusable: | ||
82 | Screen.print_error("Unable to connect to vlc") | ||
83 | raise | ||
84 | |||
70 | try: | 85 | try: |
71 | player = VLCPlayer(self, sys.stdin) | 86 | player = VLCPlayer(self, sys.stdin) |
72 | self.screen.print_success("Using VLC") | 87 | self.screen.print_success("Using VLC") |
@@ -232,8 +247,16 @@ class PlayerApp(object): | |||
232 | "your config file before continuing.")) | 247 | "your config file before continuing.")) |
233 | sys.exit(1) | 248 | sys.exit(1) |
234 | 249 | ||
250 | def _parse_args(self): | ||
251 | parser = argparse.ArgumentParser( | ||
252 | description="command line Pandora player") | ||
253 | parser.add_argument( | ||
254 | "--vlc-net", dest="vlc_net", | ||
255 | help="connect to VLC over the network (host:port)") | ||
256 | return parser.parse_args() | ||
257 | |||
235 | def run(self): | 258 | def run(self): |
236 | self.player = self.get_player() | 259 | self.player = self.get_player(self._parse_args().vlc_net) |
237 | self.player.start() | 260 | self.player.start() |
238 | 261 | ||
239 | self.client = self.get_client() | 262 | self.client = self.get_client() |
@@ -258,6 +281,7 @@ class PlayerApp(object): | |||
258 | except UnsupportedEncoding as ex: | 281 | except UnsupportedEncoding as ex: |
259 | error = str(ex) | 282 | error = str(ex) |
260 | except KeyboardInterrupt: | 283 | except KeyboardInterrupt: |
284 | self.player.stop() | ||
261 | sys.exit(0) | 285 | sys.exit(0) |
262 | 286 | ||
263 | 287 | ||