Skip to content

Commit 6d1ac55

Browse files
committed
Remote control server info will display the current search item string
if RadioBrowser is active
1 parent 53d397d commit 6d1ac55

File tree

4 files changed

+46
-42
lines changed

4 files changed

+46
-42
lines changed

docs/server.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ <h3 id="examples">Examples</h3>
193193

194194
retry: 150
195195
event: /html/title
196-
data: &lt;b&gt;The Carpenters - No Place Like Home For The Holidays&lt;/b&gt;
196+
data: &lt;b&gt;Patti Page - Jingle bells&lt;/b&gt;
197197
</pre>
198198
<p>The <strong>data</strong> field will contain the HTML format of the title, which is easy to parse in a script.</p>
199199
<p>If the player is idle, the output will be</p>
@@ -204,13 +204,13 @@ <h3 id="examples">Examples</h3>
204204
<p>Several commands (such as <strong>/v</strong>, <strong>/vu</strong>, <strong>/vd</strong>, etc.) will return this info; this is a side effect of the way the server works, but provides useful info for the script issuing the command.</p>
205205
<p>One thing that should be made clear is that getting the above info does not mean that the command has succeeded; for example issuing the <strong>/orc</strong> (<strong>/open-radio-browser</strong>) command, will return the above info, but to make sure about the state of <strong>PyRadio</strong>, one should issue the <strong>/i</strong> (<strong>/info</strong>) command:</p>
206206
<pre>$ curl http://127.0.0.1:9998/i
207-
208207
PyRadio 0.9.2.20
209-
Player: mpv
210-
Service: RadioBrowser (Austria)
211-
Status: In playback
212-
Station (id=5): &quot;Classical Christmas FM&quot;
213-
Selection (id=5): &quot;Classical Christmas FM&quot;</pre>
208+
Player: mpv
209+
Service: RadioBrowser (Netherlands)
210+
Search: Name: christmas, Order: votes, Reverse: true
211+
Status: In playback
212+
Station (id=5): &quot;Classical Christmas FM&quot;
213+
Selection (id=5): &quot;Classical Christmas FM&quot;</pre>
214214
<h3 id="text-vs.-web-commands">Text vs. Web commands</h3>
215215
<p>On first glance, the difference between a <strong>Text</strong> and a <strong>Web</strong> command is the <em>/html</em> part that exists in the later.</p>
216216
<p>But things are actually more complex that that.</p>

docs/server.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ $ curl http://192.168.122.4:9998/title
209209
210210
retry: 150
211211
event: /html/title
212-
data: <b>The Carpenters - No Place Like Home For The Holidays</b>
212+
data: <b>Patti Page - Jingle bells</b>
213213
214214
```
215215

@@ -230,13 +230,13 @@ One thing that should be made clear is that getting the above info does not mean
230230

231231
```
232232
$ curl http://127.0.0.1:9998/i
233-
234233
PyRadio 0.9.2.20
235-
Player: mpv
236-
Service: RadioBrowser (Austria)
237-
Status: In playback
238-
Station (id=5): "Classical Christmas FM"
239-
Selection (id=5): "Classical Christmas FM"
234+
Player: mpv
235+
Service: RadioBrowser (Netherlands)
236+
Search: Name: christmas, Order: votes, Reverse: true
237+
Status: In playback
238+
Station (id=5): "Classical Christmas FM"
239+
Selection (id=5): "Classical Christmas FM"
240240
```
241241

242242
### Text vs. Web commands

pyradio/browser.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,29 +1234,31 @@ def _format_term_for_get_strings(self, aterm):
12341234
return a_string + (' (exact)' if aterm.endswith('exact') else '')
12351235

12361236
def get_strings(self):
1237-
strings = []
1238-
for i, n in enumerate(self._search_history):
1239-
if i > 0:
1240-
out = []
1241-
if 'type' in n:
1242-
if n['type'] and 'term' in n:
1243-
if n['type'] != 'search':
1244-
out.append('{0}: {1}'.format(
1245-
self._format_term_for_get_strings(n['type']),
1246-
n['term']
1247-
)
1248-
)
1249-
if 'post_data' in n:
1250-
for k in n['post_data']:
1251-
out.append('{0}: {1}'.format(
1252-
k.title().replace('exact', ' (exact)'),
1253-
n['post_data'][k]
1254-
)
1237+
return [self.get_a_search_string(n) for i, n in enumerate(self._search_history) if i > 0]
1238+
1239+
def get_a_search_string(self, a_search_item):
1240+
out = []
1241+
if 'type' in a_search_item:
1242+
if a_search_item['type'] and 'term' in a_search_item:
1243+
if a_search_item['type'] != 'search':
1244+
out.append('{0}: {1}'.format(
1245+
self._format_term_for_get_strings(a_search_item['type']),
1246+
a_search_item['term']
12551247
)
1248+
)
1249+
if 'post_data' in a_search_item:
1250+
for k in a_search_item['post_data']:
1251+
out.append('{0}: {1}'.format(
1252+
k.title().replace('exact', ' (exact)'),
1253+
a_search_item['post_data'][k]
1254+
)
1255+
)
1256+
if out:
1257+
return ', '.join(out)
1258+
return None
12561259

1257-
if out:
1258-
strings.append(', '.join(out))
1259-
return strings
1260+
def get_current_history_string(self):
1261+
return self.get_a_search_string(self._search_history[self._search_history_index])
12601262

12611263
def get_history_from_search(self):
12621264
if self._search_win:

pyradio/radio.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -807,17 +807,18 @@ def _save_colors(self):
807807
def _text_info(self):
808808
out = []
809809
out.append('PyRadio {}'.format(self._cnf.current_pyradio_version))
810-
out.append('Player: {}'.format(self.player.PLAYER_NAME))
810+
out.append(' Player: {}'.format(self.player.PLAYER_NAME))
811811
if self._cnf.browsing_station_service:
812-
out.append('Service: ' + self._cnf.online_browser.TITLE)
812+
out.append(' Service: ' + self._cnf.online_browser.TITLE)
813+
out.append(' Search: ' + self._cnf.online_browser.get_current_history_string())
813814
else:
814-
out.append('Playlist: "{}"'.format(basename(self._playlist_in_editor)[:-4]))
815+
out.append(' Playlist: "{}"'.format(basename(self._playlist_in_editor)[:-4]))
815816
if self.player.isPlaying():
816-
out.append('Status: In playback {}'.format('(muted)' if self.player.muted else ''))
817-
out.append(' Station (id={0}): "{1}"'.format(self.playing+1, self.stations[self.playing][0]))
817+
out.append(' Status: In playback {}'.format('(muted)' if self.player.muted else ''))
818+
out.append(' Station (id={0}): "{1}"'.format(self.playing+1, self.stations[self.playing][0]))
818819
else:
819-
out.append('Status: Idle')
820-
out.append('Selection (id={0}): "{1}"'.format(self.selection+1, self.stations[self.selection][0]))
820+
out.append(' Status: Idle')
821+
out.append(' Selection (id={0}): "{1}"'.format(self.selection+1, self.stations[self.selection][0]))
821822
return '\n'.join(out)
822823

823824
def _html_info(self):
@@ -827,6 +828,7 @@ def _html_info(self):
827828
out.append('<span style="padding-left: 1em;">Player: <b>{}</b></span><br>'.format(self.player.PLAYER_NAME))
828829
if self._cnf.browsing_station_service:
829830
out.append('<span style="padding-left: 1em;">Service: <b>{}</b></span><br>'.format(self._cnf.online_browser.TITLE))
831+
out.append('<span style="padding-left: 2em;">Search: <b>{}</b></span><br>'.format(self._cnf.online_browser.get_current_history_string()))
830832
else:
831833
out.append('<span style="padding-left: 1em;">Playlist: <b>{}</b></span><br>'.format(basename(self._playlist_in_editor)[:-4]))
832834
if self.player.isPlaying():

0 commit comments

Comments
 (0)