Skip to content

Commit 78ace51

Browse files
committed
pyradio-client:
will report server IP and PORT only at the response of the "i", "info" command, provided that "-s", "--server_and_port" has not been provided (IP and PORT auto-detected) the response of the "title" command will actually report the song title (or "player stopped")
1 parent 44568bb commit 78ace51

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

pyradio/client.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(
4545
self._last_reply = None
4646
self._timeout = timeout
4747
self._type = -1
48+
self._discovered = True
4849

4950
if host and port:
5051
self._host = host
@@ -54,6 +55,7 @@ def __init__(
5455
is_recording()
5556
are happy '''
5657
self._file = host
58+
self._discovered = False
5759
elif server_file:
5860
if path.exists(server_file):
5961
self._file = server_file
@@ -93,22 +95,20 @@ def last_command(self):
9395

9496
@property
9597
def last_reply(self):
96-
server_id = ''
97-
if self._type >= 0:
98-
if self._last_command:
99-
server_id = 'Server: [green]{}[/green]:[green]{}[/green] {}\n'.format(
100-
self._host, self._port,
101-
'([blue]headless[/blue])' if self._type == 0 else ''
102-
)
103-
else:
104-
server_id = 'Server: {}:{} {}\n'.format(
105-
self._host, self._port,
106-
'(headless)' if self._type == 0 else ''
107-
)
10898
if self._last_reply:
99+
if self._last_command == 'title':
100+
try:
101+
return self._last_reply.split('<b>')[1][:-6]
102+
except IndexError:
103+
return 'Error retrieving title!'
104+
elif self._last_command in ('i', 'info') and \
105+
self._discovered:
106+
out = self._last_reply.splitlines()
107+
out.insert(1, ' Server: ' + self._host + ':' + self._port)
108+
self._last_reply = '\n'.join(out)
109109
if 'retry: ' in self._last_reply:
110110
self._last_reply = 'Command executed\n'
111-
return server_id + self._last_reply if server_id else self._last_reply
111+
return self._last_reply
112112
# empty reply
113113
if self._type == -1:
114114
return 'Command executed\n'
@@ -196,8 +196,9 @@ def send_command(self, command):
196196
0 : all ok
197197
1 : error
198198
'''
199-
if command is None:
200-
command = ''
199+
self._last_command = command
200+
if self._last_command is None:
201+
self._last_command = ''
201202
try:
202203
response = requests.get(
203204
'http://' + self._host + ':' + self._port + '/' + command,

0 commit comments

Comments
 (0)