Skip to content

Commit 334b084

Browse files
committed
- version 0.9.3.8
- pressing "*" will add the selected station to favorites - updating docs
1 parent a10cf5f commit 334b084

15 files changed

+180
-36
lines changed

Changelog

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2024-06-04 s-n-g
2+
* version 0.9.3.8
3+
* pressing "*" will add the selected station to favorites
4+
* adding the possibility to declare a "Referer URL" for a station
5+
* pyradio-client: /title will actually report the song title
6+
* pyradio-client: beautifying output
7+
* removing more python 2 code
8+
* updating docs
9+
110
2024-05-24 s-n-g
211
* version 0.9.3.7
312
* introducing the pyradio-client program

docs/index.html

+23-9
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ <h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><
147147
</ul></li>
148148
<li><a href="#displaying-station-info">Displaying Station Info</a></li>
149149
<li><a href="#copying-and-pasting---registers">Copying and pasting - Registers</a></li>
150+
<li><a href="#favorites-playlist">Favorites playlist</a></li>
150151
<li><a href="#pyradio-themes">PyRadio Themes</a></li>
151152
<li><a href="#recording-stations">Recording stations</a></li>
152153
<li><a href="#mouse-support">Mouse support</a></li>
@@ -214,6 +215,15 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
214215
<h2 id="changelog">Changelog <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
215216
<pre style="height: 200px;">
216217

218+
2024-06-04 s-n-g
219+
* version 0.9.3.8
220+
* pressing "*" will add the selected station to favorites
221+
* adding the possibility to declare a "Referer URL" for a station
222+
* pyradio-client: /title will actually report the song title
223+
* pyradio-client: beautifying output
224+
* removing more python 2 code
225+
* updating docs
226+
217227
2024-05-24 s-n-g
218228
* version 0.9.3.7
219229
* introducing the pyradio-client program
@@ -1303,14 +1313,13 @@ <h2 id="installation">Installation <span style="padding-left: 10px;"><sup style=
13031313
<p>The best way to install <strong>PyRadio</strong> is via a distribution package, if one exists (<em>Arch Linux</em> and derivatives can install <a target="_blank" href="https://aur.archlinux.org/packages/?K=pyradio">any of these packages</a> from the AUR, <em>FreeBSD</em> users will find it in the <a target="_blank" href="https://www.freshports.org/audio/py-pyradio/">ports</a>, etc.).</p>
13041314
<p>In any other case, and since <strong>PyRadio</strong> is currently not available via pip, you will have to <a href="build.html">build it from source</a>.</p>
13051315
<h2 id="command-line-options">Command line options <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
1306-
<pre>Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-u PLAYER]
1307-
[-l] [-lt] [-sd] [-od] [-pc] [-d] [-ul] [-us] [-U] [-R] [-V]
1308-
[-ls] [-s PLAYLIST] [-tlp] [-t THEME] [--show-themes]
1309-
[--no-themes] [--write-theme IN_THEME OUT_THEME,]
1310-
[--terminal TERMINAL] [--terminal-param TERMINAL_PARAM] [-oc]
1311-
[-sc] [-cc] [-gc] [-r] [-or] [-lr] [-mkv MKV_FILE]
1312-
[-scv PNG_FILE] [-srt] [-ach] [--headless IP_AND_PORT]
1313-
[--address] [-fd]
1316+
<pre>Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-u PLAYER] [-l]
1317+
[-lt] [-sd] [-od] [-pc] [-d] [-ul] [-us] [-U] [-R] [-V] [-ls]
1318+
[-s PLAYLIST] [-tlp] [-t THEME] [--show-themes] [--no-themes]
1319+
[--write-theme IN_THEME OUT_THEME,] [--terminal TERMINAL]
1320+
[--terminal-param TERMINAL_PARAM] [-oc] [-sc] [-cc] [-gc] [-r]
1321+
[-or] [-lr] [-mkv MKV_FILE] [-scv PNG_FILE] [-srt] [-ach]
1322+
[--headless IP_AND_PORT] [--address] [-fd]
13141323

13151324
Curses based Internet Radio Player
13161325

@@ -1436,6 +1445,7 @@ <h2 id="controls">Controls <span style="padding-left: 10px;"><sup style="font-si
14361445
-/+ or ,/. Change volume [Valid] [Valid]
14371446
m Mute / unmute player [Valid] [Valid]
14381447
v Save volume (not applicable for vlc) [Valid] [Valid]
1448+
* Add station to favorites - -
14391449
o s R Open / Save / Reload playlist - -
14401450
a A Add / append a new station - -
14411451
e Edit current station - -
@@ -1770,7 +1780,7 @@ <h3 id="changing-player-mid-session">Changing player mid-session</h3>
17701780
<h3 id="specifying-a-stations-referer-url">Specifying a station’s Referer URL</h3>
17711781
<p>Although <strong>PyRadio</strong> is meant to be a radio station player, it can also be used to listen to video stations transmitting m3u8 playlists (HTTP Live Streaming or HLS).</p>
17721782
<p>The thing with these transmissions is that usually a <strong>Referer URL</strong> has to be provided so that the connection does not fail.</p>
1773-
<p><strong>PyRadio</strong> now does support the declaration of a <strong>Referer URL</strong> for individual stations; it does it in an “anorthodox” way, but it is possible.</p>
1783+
<p><strong>PyRadio</strong> now does support the declaration of a <strong>Referer URL</strong> for individual stations; it does it in an “anorthodox” way, but it is available and it works.</p>
17741784
<p>So, let us imagine that a station called “<em>My video station</em>” has been added to a playlist. The user tries to play it but it fails; the referer URL is missing.</p>
17751785
<p>To rectify the situation, a file containing the referer URL would have to be saved in the config directory: its name must be the name of the station as it is in the playlist, followed by the “<strong>.referer.txt</strong>” extension.</p>
17761786
<p>In our example above, the file will have to be named:</p>
@@ -1974,6 +1984,10 @@ <h2 id="copying-and-pasting---registers">Copying and pasting - Registers <span s
19741984
<li><p><strong>\p</strong>” while editing a playlist or register. This would open the “<em>Paste selection</em>” window.</p></li>
19751985
<li><p><strong>\p</strong>” in the “<em>Playlist Selection</em> or the”<em>Registers</em>” window.</p></li>
19761986
</ul>
1987+
<h2 id="favorites-playlist">Favorites playlist <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
1988+
<p>Pressing “*” (asterisk) in <strong>Main Mode</strong> will add the selected station to the <strong>favorites</strong> playlist.</p>
1989+
<p>If the station is already there, it will either be updated if its name has been changed, for example, or will be ignored, to avoid creating duplicate entries.</p>
1990+
<p>The <strong>favorites</strong> playlist, residing in the configuration folder, is a normal playlist in any other respect, which can be subsequently opened, edited, deleted even, as any other playlist.</p>
19771991
<h2 id="pyradio-themes">PyRadio Themes <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
19781992
<p><strong>PyRadio</strong> supports <strong>CSS themes</strong>; it comes with a number of predefined ones and can use external programs that can provide automatically created and updated themes.</p>
19791993
<p>To set a theme you just press “<strong>t</strong>” and</p>

docs/index.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ To ensure the correct operation, please take these actions:
9999
* [How it works](#how-it-works)
100100
* [Displaying Station Info](#displaying-station-info)
101101
* [Copying and pasting - Registers](#copying-and-pasting---registers)
102+
* [Favorites playlist](#favorites-playlist)
102103
* [PyRadio Themes](#pyradio-themes)
103104
* [Recording stations](#recording-stations)
104105
* [Mouse support](#mouse-support)
@@ -164,14 +165,13 @@ In any other case, and since **PyRadio** is currently not available via pip, you
164165
## Command line options
165166

166167
```
167-
Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-u PLAYER]
168-
[-l] [-lt] [-sd] [-od] [-pc] [-d] [-ul] [-us] [-U] [-R] [-V]
169-
[-ls] [-s PLAYLIST] [-tlp] [-t THEME] [--show-themes]
170-
[--no-themes] [--write-theme IN_THEME OUT_THEME,]
171-
[--terminal TERMINAL] [--terminal-param TERMINAL_PARAM] [-oc]
172-
[-sc] [-cc] [-gc] [-r] [-or] [-lr] [-mkv MKV_FILE]
173-
[-scv PNG_FILE] [-srt] [-ach] [--headless IP_AND_PORT]
174-
[--address] [-fd]
168+
Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-u PLAYER] [-l]
169+
[-lt] [-sd] [-od] [-pc] [-d] [-ul] [-us] [-U] [-R] [-V] [-ls]
170+
[-s PLAYLIST] [-tlp] [-t THEME] [--show-themes] [--no-themes]
171+
[--write-theme IN_THEME OUT_THEME,] [--terminal TERMINAL]
172+
[--terminal-param TERMINAL_PARAM] [-oc] [-sc] [-cc] [-gc] [-r]
173+
[-or] [-lr] [-mkv MKV_FILE] [-scv PNG_FILE] [-srt] [-ach]
174+
[--headless IP_AND_PORT] [--address] [-fd]
175175
176176
Curses based Internet Radio Player
177177
@@ -300,6 +300,7 @@ Headless operation:
300300
-/+ or ,/. Change volume [Valid] [Valid]
301301
m Mute / unmute player [Valid] [Valid]
302302
v Save volume (not applicable for vlc) [Valid] [Valid]
303+
* Add station to favorites - -
303304
o s R Open / Save / Reload playlist - -
304305
a A Add / append a new station - -
305306
e Edit current station - -
@@ -756,7 +757,7 @@ Although **PyRadio** is meant to be a radio station player, it can also be used
756757

757758
The thing with these transmissions is that usually a **Referer URL** has to be provided so that the connection does not fail.
758759

759-
**PyRadio** now does support the declaration of a **Referer URL** for individual stations; it does it in an "anorthodox" way, but it is possible.
760+
**PyRadio** now does support the declaration of a **Referer URL** for individual stations; it does it in an "anorthodox" way, but it is available and it works.
760761

761762
So, let us imagine that a station called "*My video station*" has been added to a playlist. The user tries to play it but it fails; the referer URL is missing.
762763

@@ -1003,6 +1004,14 @@ To **paste** the *unnamed* register to a playlist or register, one would press:
10031004

10041005
* "**\\p**" in the "*Playlist Selection* or the "*Registers*" window.
10051006

1007+
## Favorites playlist
1008+
1009+
Pressing "*" (asterisk) in **Main Mode** will add the selected station to the **favorites** playlist.
1010+
1011+
If the station is already there, it will either be updated if its name has been changed, for example, or will be ignored, to avoid creating duplicate entries.
1012+
1013+
The **favorites** playlist, residing in the configuration folder, is a normal playlist in any other respect, which can be subsequently opened, edited, deleted even, as any other playlist.
1014+
10061015
## PyRadio Themes
10071016

10081017
**PyRadio** supports **CSS themes**; it comes with a number of predefined ones and can use external programs that can provide automatically created and updated themes.

docs/pyradio-client.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH pyradio-client 1 "May 2024" pyradio
1+
.TH pyradio-client 1 "June 2024" pyradio
22

33
.SH Name
44
.PP

docs/pyradio.1

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.\" Copyright (C) 2018-2024 Spiros Georgaras <[email protected]>
33
.\" This manual is freely distributable under the terms of the GPL.
44
.\"
5-
.TH pyradio 1 "May 2024" pyradio
5+
.TH pyradio 1 "June 2024" pyradio
66

77
.SH Name
88
.PP
@@ -838,16 +838,13 @@ Pressing "\fI\\m\fR" will bring up the "\fBSwitch Media Player\fR" window, where
838838
The activated player will not be saved; **PyRadio** will still use the player defined at its config next time it is executed.
839839

840840

841-
842-
843-
844841
.SH Specifying a station's Referer URL
845842

846843
Although \fBpyradio\fR is meant to be a radio station player, it can also be used to listen to video stations transmitting m3u8 playlists (HTTP Live Streaming or HLS).
847844

848845
The thing with these transmissions is that usually a \fBReferer URL\fR has to be provided so that the connection does not fail.
849846

850-
\fBpyradio\fR now does support the declaration of a \fBReferer URL\fR for individual stations; it does it in an "anorthodox" way, but it is possible.
847+
\fBpyradio\fR now does support the declaration of a \fBReferer URL\fR for individual stations; it does it in an "anorthodox" way, but it is available and it works.
851848

852849
So, let us imagine that a station called "\fIMy video station\fR" has been added to a playlist. The user tries to play it but it fails; the referer URL is missing.
853850

@@ -1172,6 +1169,14 @@ To \fBpaste\fR the \fIunnamed\fR register to a playlist or register, one would p
11721169

11731170
.RE
11741171

1172+
.SH Favorites playlist
1173+
1174+
Pressing "\fI*\fR" in \fBMain Mode\fR will add the selected station to the \fBfavorites\fR playlist.
1175+
1176+
If the station is already there, it will either be updated if its name has been changed, for example, or will be ignored, to avoid creating duplicate entries.
1177+
1178+
The \fBfavorites\fR playlist, residing in the configuration folder, is a normal playlist in any other respect, which can be subsequently opened, edited, deleted even, as any other playlist.
1179+
11751180
.SH Pyradio Themes
11761181
.PP
11771182

docs/pyradio_rb.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Copyright (C) 2018-2024 Spiros Georgaras <[email protected]>
22
.\" This manual is freely distributable under the terms of the GPL.
33
.\"
4-
.TH pyradio_rb 1 "April 2024" pyradio
4+
.TH pyradio_rb 1 "June 2024" pyradio
55

66
.SH Name
77
.PP

docs/pyradio_rec.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH pyradio_rec 1 "May 2024" pyradio
1+
.TH pyradio_rec 1 "June 2024" pyradio
22

33
.SH Name
44
.PP

docs/pyradio_server.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Copyright (C) 2018-2024 Spiros Georgaras <[email protected]>
22
.\" This manual is freely distributable under the terms of the GPL.
33
.\"
4-
.TH pyradio_server 1 "May 2024" pyradio
4+
.TH pyradio_server 1 "June 2024" pyradio
55

66
.SH Name
77
.PP

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyradio"
3-
version = "0.9.3.7"
3+
version = "0.9.3.8"
44
authors = [
55
{ name="Ben Dowling", email="[email protected]" },
66
{ name="Spiros Georgaras", email="[email protected]" },

pyradio/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
" pyradio -- Console radio player. "
33

4-
version_info = (0, 9, 3, 7)
4+
version_info = (0, 9, 3, 8)
55

66
# Set it to True if new stations have been
77
# added to the package's stations.csv

pyradio/config.py

+92
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ class PyRadioStations(object):
168168

169169
renamed_stations = []
170170

171+
favorites = None
172+
171173
def __init__(self, stationFile='', user_config_dir=None):
172174
if platform.startswith('win'):
173175
self._open_string_id = 1
@@ -180,6 +182,7 @@ def __init__(self, stationFile='', user_config_dir=None):
180182
self.player_params_file = path.join(self.data_dir, 'player-params.json')
181183
self.schedule_file = path.join(self.data_dir, 'schedule.json')
182184
self.themes_dir = path.join(self.stations_dir, 'themes')
185+
self.favorites_path = path.join(self.stations_dir, 'favorites.csv')
183186
try:
184187
makedirs(self.themes_dir, exist_ok = True)
185188
except:
@@ -207,6 +210,11 @@ def __init__(self, stationFile='', user_config_dir=None):
207210
new_rb_config = path.join(self.stations_dir, 'radio-browser.conf')
208211
rename(rb_config, new_rb_config)
209212

213+
def add_to_favorites(self, an_item):
214+
if self.favorites is None:
215+
self.favorites = FavoritesManager(self.favorites_path)
216+
return self.favorites.add(an_item)
217+
210218
def _move_to_data(self):
211219
if not path.exists(self.data_dir):
212220
makedirs(self.data_dir)
@@ -4020,3 +4028,87 @@ def _read_theme_sh(self, theme_name):
40204028
return lines
40214029

40224030

4031+
class FavoritesManager:
4032+
def __init__(self, a_file):
4033+
self.file_path = a_file
4034+
4035+
def add(self, an_item):
4036+
''' Returns:
4037+
-2 : Error saving file
4038+
-1 : Invalid item
4039+
0 : Item added
4040+
1 : Item already in favorites
4041+
'''
4042+
items = self._read_csv()
4043+
url = an_item[1]
4044+
updated = False
4045+
write_it = True
4046+
4047+
for i, item in enumerate(an_item):
4048+
if item is None:
4049+
if i in range(0, 2):
4050+
return -1, '___Station is invalid!___'
4051+
an_item[i] = ''
4052+
if an_item[0] == '' or \
4053+
an_item[1] == '':
4054+
return -1, '___Station is invalid!___'
4055+
if isinstance(an_item[-1], dict):
4056+
an_item[-1] = an_item[-1]['image']
4057+
msg = None
4058+
for i, item in enumerate(items):
4059+
if item[1] == url:
4060+
if item == an_item:
4061+
return 1, '___Already in favorites!___'
4062+
if item[0] != an_item[0] or \
4063+
item[2] != an_item[2] or \
4064+
item[3] != an_item[3]:
4065+
items[i] = an_item
4066+
msg = '___Station updated!___'
4067+
updated = True
4068+
break
4069+
if not updated:
4070+
items.append(an_item)
4071+
updated = True
4072+
if updated:
4073+
ret = self._write_csv(items)
4074+
return ret[0], msg if msg else ret
4075+
return 1, '___Already in favorites!___'
4076+
4077+
# def remove(self, an_item):
4078+
# items = self._read_csv()
4079+
# name = an_item[0]
4080+
# url = an_item[1]
4081+
# new_items = [item for item in items if item[0] != name and item[1] != url]
4082+
4083+
# if len(new_items) != len(items):
4084+
# self._write_csv(new_items)
4085+
4086+
def _read_csv(self):
4087+
items = []
4088+
if path.exists(self.file_path):
4089+
try:
4090+
with open(self.file_path, mode='r', newline='') as file:
4091+
reader = csv.reader(file)
4092+
for row in reader:
4093+
if not row[0].startswith('#'):
4094+
while len(row) < 4:
4095+
row.append('')
4096+
name, url, enc, icon = [s.strip() for s in row]
4097+
items.append([name, url, enc, icon])
4098+
except:
4099+
return []
4100+
return items
4101+
4102+
def _write_csv(self, items):
4103+
''' Returns:
4104+
-2 : Error saving file
4105+
0 : Item added
4106+
'''
4107+
try:
4108+
with open(self.file_path, mode='w', newline='') as file:
4109+
writer = csv.writer(file)
4110+
writer.writerows(items)
4111+
except:
4112+
return -2, '___Error writing favorites!___'
4113+
return 0, '___Added to favorites!___'
4114+

pyradio/install.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
''' This is PyRadio version this
1717
install.py was released for
1818
'''
19-
PyRadioInstallPyReleaseVersion = '0.9.3.7'
19+
PyRadioInstallPyReleaseVersion = '0.9.3.8'
2020

2121
import locale
2222
locale.setlocale(locale.LC_ALL, "")

pyradio/messages_system.py

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def set_text(self, parent, *args):
118118
i |*| Display station |i|nfo (when playing).
119119
r |*| Select and play a random station.
120120
Space|, |Left|, |h |*| Stop / start playing selected station.
121+
* |*| Add station to favorites.
121122
Esc|, |q |*| Quit.
122123
123124
!Volume management

0 commit comments

Comments
 (0)