diff options
author | Mike Crute <mcrute@gmail.com> | 2015-07-03 22:13:39 -0700 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2015-07-04 14:01:06 -0700 |
commit | 65a04d81ff762526480b35bfeb705206efa8cbdf (patch) | |
tree | 0f6b8f62007edaacd773e98235b7258317ad4b9a /pydora | |
parent | ab4f1e2d769fae61834f62a9f12dd97bf826049b (diff) | |
download | pydora-65a04d81ff762526480b35bfeb705206efa8cbdf.tar.bz2 pydora-65a04d81ff762526480b35bfeb705206efa8cbdf.tar.xz pydora-65a04d81ff762526480b35bfeb705206efa8cbdf.zip |
Support fallback to Pianobar config
Diffstat (limited to 'pydora')
-rwxr-xr-x | pydora/player.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/pydora/player.py b/pydora/player.py index 05862a0..3ec3293 100755 --- a/pydora/player.py +++ b/pydora/player.py | |||
@@ -10,6 +10,7 @@ from __future__ import print_function | |||
10 | 10 | ||
11 | import os | 11 | import os |
12 | import sys | 12 | import sys |
13 | from pandora import APIClient, clientbuilder | ||
13 | 14 | ||
14 | from .mpg123 import Player | 15 | from .mpg123 import Player |
15 | from .utils import Colors, Screen | 16 | from .utils import Colors, Screen |
@@ -34,22 +35,20 @@ class PlayerApp(object): | |||
34 | self.client = None | 35 | self.client = None |
35 | self.player = Player(self, sys.stdin) | 36 | self.player = Player(self, sys.stdin) |
36 | 37 | ||
37 | @property | 38 | def get_client(self): |
38 | def config_path(self): | 39 | cfg_file = os.environ.get("PYDORA_CFG", "") |
39 | """Find the config file | 40 | builder = clientbuilder.PydoraConfigFileBuilder(cfg_file) |
41 | if builder.file_exists: | ||
42 | return builder.build() | ||
40 | 43 | ||
41 | Config file exists in either ~/.pydora.cfg or is pointed to by an | 44 | builder = clientbuilder.PianobarConfigFileBuilder() |
42 | environment variable PYDORA_CFG. | 45 | if builder.file_exists: |
43 | """ | 46 | return builder.build() |
44 | path = os.path.expanduser( | ||
45 | os.environ.get('PYDORA_CFG', '~/.pydora.cfg')) | ||
46 | 47 | ||
47 | if not os.path.exists(path): | 48 | if not self.client: |
48 | Screen.print_error('No settings at {!r}'.format(path)) | 49 | Screen.print_error("No valid config found") |
49 | sys.exit(1) | 50 | sys.exit(1) |
50 | 51 | ||
51 | return path | ||
52 | |||
53 | def station_selection_menu(self): | 52 | def station_selection_menu(self): |
54 | """Format a station menu and make the user select a station | 53 | """Format a station menu and make the user select a station |
55 | """ | 54 | """ |
@@ -126,7 +125,7 @@ class PlayerApp(object): | |||
126 | Screen.set_echo(True) | 125 | Screen.set_echo(True) |
127 | 126 | ||
128 | def run(self): | 127 | def run(self): |
129 | self.client = APIClient.from_config_file(self.config_path) | 128 | self.client = self.get_client() |
130 | self.stations = self.client.get_station_list() | 129 | self.stations = self.client.get_station_list() |
131 | 130 | ||
132 | while True: | 131 | while True: |