-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathserver.html
251 lines (245 loc) · 18.2 KB
/
server.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>PyRadio Remote Control Server</title>
<style>
body {padding: 2em;}
@media screen and (max-width: 770px) {
body {padding: 10px;}
}
body {max-width: 750px; margin: auto;}
h2 {margin-top: 2.5em; border-bottom:1px solid SaddleBrown; color: SaddleBrown;}
h3 {margin-top: 2em; color: SaddleBrown; text-decoration: underline SaddleBrown}
h4 {margin: 2em 0 1em 0; color: SaddleBrown; font-size: 1em;}
h4:before {content: "# "; font-weight: bold; vertical-align: middle;}
h5 {margin: 2em 0 1em 0; color: SaddleBrown; font-size: 1em;;}
h5:before {content: "## "; font-weight: bold; vertical-align: middle;}
p, table, ol, ul {margin-left: .8em;}
STRONG {color: SaddleBrown;}
dl {margin: 2em;}
dd {margin: 1em;}
dt {font-weight: bold;}
TABLE {border: 1px solid SaddleBrown; border-collapse: collapse; margin-left: auto; margin-right: auto; border-radius: 5px; -moz-border-radius: 5px; border-collapse:separate; box-shadow: 5px 5px 15px #888888;}
TH {text-align: left; vertical-align: top; padding: 5px;color: SaddleBrown;border: 1px solid SaddleBrown; background-color: SaddleBrown; color: white;}
TD {text-align: left; vertical-align: top; padding: 5px 10px;border: 1px solid SaddleBrown;}
pre { background-color: rgba(245, 245, 245, 1); color: #474747; padding: 1.5em; border: 1px solid #C7C7C7; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; overflow: auto; box-shadow: 5px 5px 15px #C7C7C7;}
.task-list {list-style-type: none; padding: 0; margin: 0 0 0 1em ;}
img{display: block; margin-left: auto; margin-right: auto; max-width: 750px; width: 100%; background:transparent; padding:3px; border:1px solid #999999; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; box-shadow:5px 5px 15px #888888;}
.indented {text-indent: -1.5em; padding-left: 1.5em; margin-left: 1em;}
a{ color: SaddleBrown;}
a:visited{color: SaddleBrown;}
</style>
</head>
<body>
<header id="title-block-header">
</header>
<h1 style="color: SaddleBrown" id="pyradio-remote-control-server">PyRadio Remote Control Server</h1>
<h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
<!-- vim-markdown-toc Marked -->
<ul>
<li><a href="#remote-control-server">Remote Control Server</a>
<ul>
<li><a href="#using-the-web-server">Using the Web Server</a>
<ul>
<li><a href="#web-interface-buttons">Web Interface buttons</a></li>
<li><a href="#navigating-through-radiobrowser-results">Navigating through RadioBrowser results</a></li>
</ul></li>
<li><a href="#using-the-text-server">Using the Text Server</a></li>
<li><a href="#server-lock-file">Server lock file</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#text-vs.-web-commands">Text vs. Web commands</a></li>
</ul></li>
</ul>
<!-- vim-markdown-toc -->
<p class="indented">[ <a href="index.html#remote-control-server">Return to main doc</a> ]</p>
<h2 id="remote-control-server">Remote Control Server <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
<p><strong>PyRadio</strong> can be controlled remotely using normal http requests either form the command line (with <em>curl</em> for example) or from a browser.</p>
<p>For this purpose, a simple web server has been integrated in <strong>PyRadio</strong>; this server can be started</p>
<ul>
<li>automatically<br />
Setting the <strong>Remote Control Server</strong> options ins the config file, especially setting the <strong>Auto-start Server</strong> to <strong>True</strong>, or</li>
<li>by pressing “<strong>\s</strong>” at the main window, selecting the desired options and pressing “<strong>s</strong>”.</li>
</ul>
<p>The options one can set are:</p>
<ol type="1">
<li><p><strong>Server IP</strong><br />
This can either be <strong>localhost</strong> (the server will be accessible from the current system only) or <strong>LAN</strong> (the server will be accessible from any PC on the local network).<br />
<br />
If the machine has more that one interface (network card), the actual IPs will be available for selection as well.</p></li>
<li><p><strong>Server Port</strong><br />
This is the port the server is listening to. Any free port number between 1025 and 65535 can be set here (default value is 9998).</p></li>
<li><p><strong>Auto-start Server</strong><br />
This option is available in the config only. If set to True, the server will be automatically started when <strong>PyRadio</strong> starts.</p></li>
</ol>
<p>After the server is up, pressing “<strong>\s</strong>” will display the following window:</p>
<p><a href="https://members.hellug.gr/sng/pyradio/server-on.jpg" target="_blank"><img style="width: 350px" src="https://members.hellug.gr/sng/pyradio/server-on.jpg" alt="PyRadio" /></a></p>
<p>This window will display both the server’s <strong>Text</strong> and <strong>Web</strong> address.</p>
<h3 id="using-the-web-server">Using the Web Server</h3>
<p>So, inserting the <strong>Web</strong> address displayed in the previous window in a web browser will result to the output shown at the left of following image, (which is actually a screenshot of my mobile phone).</p>
<p><a href="https://members.hellug.gr/sng/pyradio/phone.jpg" target="_blank"><img style="width: 550px" src="https://members.hellug.gr/sng/pyradio/phone.jpg" alt="PyRadio" /></a></p>
<p>The idea is that while <strong>PyRadio</strong> is running on the PC, people relaxing on the sofa, chilling with friends, listening to music from their favorite radio station, being able to increase / decrease the volume, change stations, etc. using their phones.</p>
<p>The available commands are “encoded” in the buttons shown on the screen; the right part of the image shows the output of the “<strong>Stations List</strong>” button. To start a station, I would just click (well, tap) on its name, and viola!</p>
<p>The <strong>Web</strong> interface will also show the song’s title, if available, or the name of the station that’s playing, if it’s not. In order to achieve this functionality, <em>JavaScript</em> is heavily used, so one should keep that in mind (in case <em>JavaScript</em> has been disabled in the browser, for example).</p>
<h4 id="web-interface-buttons">Web Interface buttons</h4>
<p>The buttons shown in the web interface are:</p>
<ul>
<li><p><strong>Local Playlist</strong><br />
This button will permit the user to toggle between opening a local playlist (default state) and a <strong>RadioBrowser</strong> “playlist”, actually a search result set of players.</p></li>
<li><p><strong>Play Next</strong> and <strong>Play Previous</strong><br />
The buttons title says it all…<br />
Subsequent clicks on a button will only be accepted after the player has “settled”, i.e. either started playing or failed to connect to the station.</p></li>
<li><p><strong>Play Hist. Next</strong> and <strong>Play Hist. Previous</strong><br />
Same as above, but stations will come from the “<strong>station history</strong>” instead of the current playlist.</p></li>
<li><p><strong>Toggle Playback</strong><br />
Nothing more to say here; start/stop the player.</p></li>
<li><p><strong>Volume Up</strong> and <strong>Volume Down</strong>, <strong>Save Volume</strong>, <strong>Mute Player</strong><br />
These are the volume adjustment, saving and muting the player functions.</p></li>
<li><p><strong>Recording</strong><br />
Toggle recording button.<br />
Its caption indicates whether recording is enabled or disabled.<br />
Its background color indicates whether a file is currently being recorded (a station is being recorded), in which case the button’s background color is green. If the color is red, no file is being recorded.</p></li>
<li><p><strong>Show Stations</strong><br />
Clicking this buttons will present the list of stations in the current playlist (or search result). Clicking on a station name will start its playback.</p></li>
<li><p><strong>Show Groups</strong><br />
This will display, and permit the selection of the groups defined within a playlist. When a group name is selected, the list of players will be opened and scrolled to the beginning of the group.</p></li>
<li><p><strong>Show Playlists</strong><br />
This will show a list of the playlists already composed by the user. Clicking on a playlist’s name will open the playlist; the stations will be available through the <strong>Show Stations</strong>.<br />
<br />
When <strong>RadioBrowser</strong> is active, the button’s label will change to <strong>Show Searches</strong>. When clicked, the list of existing search items will be presented to the user; clicking on an item will preform the search and results can be displayed by clicking on the <strong>Show Stations</strong> button.<br />
<br />
No new items can be inserted using the web interface.</p></li>
<li><p><strong>Enable Title Log</strong><br />
This will enable or disable the titles logging function.</p></li>
<li><p><strong>Like Title</strong><br />
This will “like” the current (song).</p></li>
<li><p><strong>System Info</strong><br />
This will display useful info about <strong>PyRadio</strong>.</p></li>
</ul>
<h4 id="navigating-through-radiobrowser-results">Navigating through RadioBrowser results</h4>
<p>All <strong>PyRadio</strong> queries to <strong>RadioBrowser</strong> will use a return limit parameter (default is 200 stations).</p>
<p>This means that the user is presented at most the first 200 stations (or whatever limit value he has set), but the actual result set may comprise hundreds of stations.</p>
<p><strong>PyRadio</strong> will permit the user to navigate through them by displaying the “<em>navigation buttons</em>” when the stations’ list is requested, provided that there is a possibility for a subsequent page exist - <strong>PyRadio</strong> has no way of knowing that beforehand.</p>
<p>An example can be seen in the following image.</p>
<p><a href="https://members.hellug.gr/sng/pyradio/radiobrowser-pages.jpg" target="_blank"><img src="https://members.hellug.gr/sng/pyradio/radiobrowser-pages.jpg" alt="PyRadio" /></a></p>
<p>In this example, the user has already displayed the fourth “<strong>page</strong>” of results; the buttons displayed are:</p>
<ul>
<li><p><strong>First Page</strong><br />
Display the first page of results.<br />
This button is displayed only when the third (and consequent) page is displayed.</p></li>
<li><p><strong>Previous Page</strong><br />
Display the previous page of results.<br />
This button is displayed only when the second (and consequent) page is displayed.</p></li>
<li><p><strong>Next Page</strong><br />
Display the next page of results.<br />
This button is visible only if the number of results in the current page is equal to the limit value set for the query. This way the user knows he has displayed the last page of results.<br />
<br />
Chances are the last page of results contain “<em>limit</em>” stations; in this case, clicking the button will produce no change (the existing page will be redisplayed). This is an indication that the last page of results has been reached.</p></li>
</ul>
<h3 id="using-the-text-server">Using the Text Server</h3>
<p>Why having the <strong>Text</strong> interface as well, one might ask…</p>
<p>Well, first of all it’s lighter, then one can use it to locally control <strong>PyRadio</strong> from a script and provide a way to adjust the volume for example, using some assigned shortcut key combination.</p>
<p>Inserting the <strong>Text</strong> address on a terminal using <em>curl</em> or <em>wget</em> or any similar software:</p>
<pre>$ curl http://192.168.122.4:9998</pre>
<p>or</p>
<pre>$ wget http://192.168.122.4:9998 -q -O -</pre>
<p>would result to displaying the list of available commands:</p>
<pre>PyRadio Remote Service
Global Commands
Long Short Description
---------------------------------------------------------------------------
/info /i display PyRadio info
/volume /v show volume (text only)
/set_volume/x /sv/x set volume to x% (text only)
/volumeup /vu increase volume
/volumedown /vd decrease volume
/volumesave /vs save volume
/mute /m toggle mute
/log /g toggle stations logging
/like /l tag (like) station
/title get title (HTML format)
Restricted Commands (Main mode only)
---------------------------------------------------------------------------
/toggle /t toggle playback
/playlists /pl get playlists list
/playlists/x /pl/x get stations list from playlist id x
(x comes from command /pl)
/playlists/x,y /pl/x,y play station id y from playlist id x
/stations /st get stations list from current playlist
/stations/x /st/x play station id x from current playlist
/next /n play next station
/previous /p play previous station
/histnext /hn play next station from history
/histprev /hp play previous station from history
/rec_status /srec get recording status
/toggle_rec /trec toggle recording
/open_rb /orb open RadioBrowser
/close_rb /crb close RadioBrowser
/list_rb /lrb list RadioBrowser search items
/search_rb/[x] /srb/[x] execute RadioBrowser search item x
(x comes from /lrb - execute default
search item if not specified)
/rb_page /grb get RadioBrowser searh results page number
/rb_first_page /frb load RadioBrowser first results page
/rb_next_page /nrb load RadioBrowser next results page
/rb_previous_page /prb load RadioBrowser previous results page</pre>
<p>The “<strong>Restricted Commands</strong>” will not work in <strong>Playlist mode</strong>; the “<strong>Global Commands</strong>” will work everywhere.</p>
<h3 id="server-lock-file">Server lock file</h3>
<p>When the server is up and running, a “server lock file” will be created; the file is named <strong>~/.config/pyradio/data/server.txt</strong> and contains the IP address and port the server is listening to; this is especially useful for user scripts that want to get hold of this information.</p>
<h3 id="examples">Examples</h3>
<p>The following commands will increase / decrease the volume and mute the player:</p>
<pre>$ curl http://192.168.122.4:9998/vu
$ wget http://192.168.122.4:9998/vd -q -O -
$ wget http://192.168.122.4:9998/m -q -O -</pre>
<p>The following command will display the contents of the loaded playlist:</p>
<pre>$ curl http://192.168.122.4:9998/st</pre>
<p>The stations will be numbered, like so:</p>
<pre>Stations List for Playlist: "stations"
1. Alternative (BAGeL Radio - SomaFM)
2. Alternative (The Alternative Project)
...
17. Jazz (Sonic Universe - SomaFM)
+ 18. Lounge (Illinois Street Lounge - SomaFM)
19. Pop (PopTron! - SomaFM)
20. Pop/Rock/Urban (Frequence 3 - Paris)
...
> 34. Echoes of Bluemars - Cryosleep
34. Echoes of Bluemars - Voices from Within
First column
[> ]: Selected, [+ ]: Playing, [+>]: Both</pre>
<p>so that in order to start playing station No 20, for example, one would just use the command:</p>
<pre>$ curl http://192.168.122.4:9998/st/20</pre>
<p>The following command will get the current song title:</p>
<pre>$ curl http://192.168.122.4:9998/title
retry: 150
event: /html/title
data: <b>Patti Page - Jingle bells</b>
</pre>
<p>The <strong>data</strong> field will contain the HTML format of the title, which is easy to parse in a script.</p>
<p>If the player is idle, the output will be</p>
<pre>$ curl http://192.168.122.192.168.122.4tle
retry: 150
event: /html/title
data: <b>Player is stopped!</b></pre>
<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>
<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>
<pre>$ curl http://192.168.122.4:9998/i
PyRadio 0.9.2.20
Player: mpv
Service: RadioBrowser (Netherlands)
Search: Name: christmas, Order: votes, Reverse: true
Status: In playback
Station (id=5): "Classical Christmas FM"
Title: Patti Page - Jingle bells
Selection (id=5): "Classical Christmas FM"</pre>
<h3 id="text-vs.-web-commands">Text vs. Web commands</h3>
<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>
<p>But things are actually more complex that that.</p>
<p>For example, when the <em>/st</em> command is issued, the server will return the list of stations as text and keep listening for connections. In this case, one requests has been made to the server and one response has been returned.</p>
<p>Now, if the <em>/html/st</em> command was issued, the server will return the same list, but formatted as html, so that a browser can correctly display it.</p>
<p>This output would pretty much be unusable to a user issuing the “<strong>html</strong>” command on a terminal.</p>
<p>Furthermore, using it from a browser, clicking or tapping the corresponding button, will lead to a number of requests from the browser to the server (requesting the mute status, the player’s status, the song’s title, etc.).</p>
</body>
</html>