Skip to content

Commit

Permalink
- version 0.9.3.8
Browse files Browse the repository at this point in the history
- pressing "*" will add the selected station to favorites
- updating docs
  • Loading branch information
s-n-g committed Jun 4, 2024
1 parent a10cf5f commit 334b084
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 36 deletions.
9 changes: 9 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2024-06-04 s-n-g
* version 0.9.3.8
* pressing "*" will add the selected station to favorites
* adding the possibility to declare a "Referer URL" for a station
* pyradio-client: /title will actually report the song title
* pyradio-client: beautifying output
* removing more python 2 code
* updating docs

2024-05-24 s-n-g
* version 0.9.3.7
* introducing the pyradio-client program
Expand Down
32 changes: 23 additions & 9 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ <h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><
</ul></li>
<li><a href="#displaying-station-info">Displaying Station Info</a></li>
<li><a href="#copying-and-pasting---registers">Copying and pasting - Registers</a></li>
<li><a href="#favorites-playlist">Favorites playlist</a></li>
<li><a href="#pyradio-themes">PyRadio Themes</a></li>
<li><a href="#recording-stations">Recording stations</a></li>
<li><a href="#mouse-support">Mouse support</a></li>
Expand Down Expand Up @@ -214,6 +215,15 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
<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>
<pre style="height: 200px;">

2024-06-04 s-n-g
* version 0.9.3.8
* pressing "*" will add the selected station to favorites
* adding the possibility to declare a "Referer URL" for a station
* pyradio-client: /title will actually report the song title
* pyradio-client: beautifying output
* removing more python 2 code
* updating docs

2024-05-24 s-n-g
* version 0.9.3.7
* introducing the pyradio-client program
Expand Down Expand Up @@ -1303,14 +1313,13 @@ <h2 id="installation">Installation <span style="padding-left: 10px;"><sup style=
<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>
<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>
<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>
<pre>Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-u PLAYER]
[-l] [-lt] [-sd] [-od] [-pc] [-d] [-ul] [-us] [-U] [-R] [-V]
[-ls] [-s PLAYLIST] [-tlp] [-t THEME] [--show-themes]
[--no-themes] [--write-theme IN_THEME OUT_THEME,]
[--terminal TERMINAL] [--terminal-param TERMINAL_PARAM] [-oc]
[-sc] [-cc] [-gc] [-r] [-or] [-lr] [-mkv MKV_FILE]
[-scv PNG_FILE] [-srt] [-ach] [--headless IP_AND_PORT]
[--address] [-fd]
<pre>Usage: pyradio [-h] [-c CONFIG_DIR] [-p [STATION_NUMBER]] [-u PLAYER] [-l]
[-lt] [-sd] [-od] [-pc] [-d] [-ul] [-us] [-U] [-R] [-V] [-ls]
[-s PLAYLIST] [-tlp] [-t THEME] [--show-themes] [--no-themes]
[--write-theme IN_THEME OUT_THEME,] [--terminal TERMINAL]
[--terminal-param TERMINAL_PARAM] [-oc] [-sc] [-cc] [-gc] [-r]
[-or] [-lr] [-mkv MKV_FILE] [-scv PNG_FILE] [-srt] [-ach]
[--headless IP_AND_PORT] [--address] [-fd]

Curses based Internet Radio Player

Expand Down Expand Up @@ -1436,6 +1445,7 @@ <h2 id="controls">Controls <span style="padding-left: 10px;"><sup style="font-si
-/+ or ,/. Change volume [Valid] [Valid]
m Mute / unmute player [Valid] [Valid]
v Save volume (not applicable for vlc) [Valid] [Valid]
* Add station to favorites - -
o s R Open / Save / Reload playlist - -
a A Add / append a new station - -
e Edit current station - -
Expand Down Expand Up @@ -1770,7 +1780,7 @@ <h3 id="changing-player-mid-session">Changing player mid-session</h3>
<h3 id="specifying-a-stations-referer-url">Specifying a station’s Referer URL</h3>
<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>
<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>
<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>
<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>
<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>
<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>
<p>In our example above, the file will have to be named:</p>
Expand Down Expand Up @@ -1974,6 +1984,10 @@ <h2 id="copying-and-pasting---registers">Copying and pasting - Registers <span s
<li><p><strong>\p</strong>” while editing a playlist or register. This would open the “<em>Paste selection</em>” window.</p></li>
<li><p><strong>\p</strong>” in the “<em>Playlist Selection</em> or the”<em>Registers</em>” window.</p></li>
</ul>
<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>
<p>Pressing “*” (asterisk) in <strong>Main Mode</strong> will add the selected station to the <strong>favorites</strong> playlist.</p>
<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>
<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>
<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>
<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>
<p>To set a theme you just press “<strong>t</strong>” and</p>
Expand Down
27 changes: 18 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ To ensure the correct operation, please take these actions:
* [How it works](#how-it-works)
* [Displaying Station Info](#displaying-station-info)
* [Copying and pasting - Registers](#copying-and-pasting---registers)
* [Favorites playlist](#favorites-playlist)
* [PyRadio Themes](#pyradio-themes)
* [Recording stations](#recording-stations)
* [Mouse support](#mouse-support)
Expand Down Expand Up @@ -164,14 +165,13 @@ In any other case, and since **PyRadio** is currently not available via pip, you
## Command line options

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

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

**PyRadio** now does support the declaration of a **Referer URL** for individual stations; it does it in an "anorthodox" way, but it is possible.
**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.

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.

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

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

## Favorites playlist

Pressing "*" (asterisk) in **Main Mode** will add the selected station to the **favorites** playlist.

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.

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.

## PyRadio Themes

**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.
Expand Down
2 changes: 1 addition & 1 deletion docs/pyradio-client.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH pyradio-client 1 "May 2024" pyradio
.TH pyradio-client 1 "June 2024" pyradio

.SH Name
.PP
Expand Down
15 changes: 10 additions & 5 deletions docs/pyradio.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.\" Copyright (C) 2018-2024 Spiros Georgaras <sng@hellug.gr>
.\" This manual is freely distributable under the terms of the GPL.
.\"
.TH pyradio 1 "May 2024" pyradio
.TH pyradio 1 "June 2024" pyradio

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





.SH Specifying a station's Referer URL

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).

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

\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.
\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.

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.

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

.RE

.SH Favorites playlist

Pressing "\fI*\fR" in \fBMain Mode\fR will add the selected station to the \fBfavorites\fR playlist.

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.

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.

.SH Pyradio Themes
.PP

Expand Down
2 changes: 1 addition & 1 deletion docs/pyradio_rb.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" Copyright (C) 2018-2024 Spiros Georgaras <sng@hellug.gr>
.\" This manual is freely distributable under the terms of the GPL.
.\"
.TH pyradio_rb 1 "April 2024" pyradio
.TH pyradio_rb 1 "June 2024" pyradio

.SH Name
.PP
Expand Down
2 changes: 1 addition & 1 deletion docs/pyradio_rec.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH pyradio_rec 1 "May 2024" pyradio
.TH pyradio_rec 1 "June 2024" pyradio

.SH Name
.PP
Expand Down
2 changes: 1 addition & 1 deletion docs/pyradio_server.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" Copyright (C) 2018-2024 Spiros Georgaras <sng@hellug.gr>
.\" This manual is freely distributable under the terms of the GPL.
.\"
.TH pyradio_server 1 "May 2024" pyradio
.TH pyradio_server 1 "June 2024" pyradio

.SH Name
.PP
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyradio"
version = "0.9.3.7"
version = "0.9.3.8"
authors = [
{ name="Ben Dowling", email="ben.m.dowling@gmail.com" },
{ name="Spiros Georgaras", email="sng@hellug.gr" },
Expand Down
2 changes: 1 addition & 1 deletion pyradio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
" pyradio -- Console radio player. "

version_info = (0, 9, 3, 7)
version_info = (0, 9, 3, 8)

# Set it to True if new stations have been
# added to the package's stations.csv
Expand Down
92 changes: 92 additions & 0 deletions pyradio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class PyRadioStations(object):

renamed_stations = []

favorites = None

def __init__(self, stationFile='', user_config_dir=None):
if platform.startswith('win'):
self._open_string_id = 1
Expand All @@ -180,6 +182,7 @@ def __init__(self, stationFile='', user_config_dir=None):
self.player_params_file = path.join(self.data_dir, 'player-params.json')
self.schedule_file = path.join(self.data_dir, 'schedule.json')
self.themes_dir = path.join(self.stations_dir, 'themes')
self.favorites_path = path.join(self.stations_dir, 'favorites.csv')
try:
makedirs(self.themes_dir, exist_ok = True)
except:
Expand Down Expand Up @@ -207,6 +210,11 @@ def __init__(self, stationFile='', user_config_dir=None):
new_rb_config = path.join(self.stations_dir, 'radio-browser.conf')
rename(rb_config, new_rb_config)

def add_to_favorites(self, an_item):
if self.favorites is None:
self.favorites = FavoritesManager(self.favorites_path)
return self.favorites.add(an_item)

def _move_to_data(self):
if not path.exists(self.data_dir):
makedirs(self.data_dir)
Expand Down Expand Up @@ -4020,3 +4028,87 @@ def _read_theme_sh(self, theme_name):
return lines


class FavoritesManager:
def __init__(self, a_file):
self.file_path = a_file

def add(self, an_item):
''' Returns:
-2 : Error saving file
-1 : Invalid item
0 : Item added
1 : Item already in favorites
'''
items = self._read_csv()
url = an_item[1]
updated = False
write_it = True

for i, item in enumerate(an_item):
if item is None:
if i in range(0, 2):
return -1, '___Station is invalid!___'
an_item[i] = ''
if an_item[0] == '' or \
an_item[1] == '':
return -1, '___Station is invalid!___'
if isinstance(an_item[-1], dict):
an_item[-1] = an_item[-1]['image']
msg = None
for i, item in enumerate(items):
if item[1] == url:
if item == an_item:
return 1, '___Already in favorites!___'
if item[0] != an_item[0] or \
item[2] != an_item[2] or \
item[3] != an_item[3]:
items[i] = an_item
msg = '___Station updated!___'
updated = True
break
if not updated:
items.append(an_item)
updated = True
if updated:
ret = self._write_csv(items)
return ret[0], msg if msg else ret
return 1, '___Already in favorites!___'

# def remove(self, an_item):
# items = self._read_csv()
# name = an_item[0]
# url = an_item[1]
# new_items = [item for item in items if item[0] != name and item[1] != url]

# if len(new_items) != len(items):
# self._write_csv(new_items)

def _read_csv(self):
items = []
if path.exists(self.file_path):
try:
with open(self.file_path, mode='r', newline='') as file:
reader = csv.reader(file)
for row in reader:
if not row[0].startswith('#'):
while len(row) < 4:
row.append('')
name, url, enc, icon = [s.strip() for s in row]
items.append([name, url, enc, icon])
except:
return []
return items

def _write_csv(self, items):
''' Returns:
-2 : Error saving file
0 : Item added
'''
try:
with open(self.file_path, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerows(items)
except:
return -2, '___Error writing favorites!___'
return 0, '___Added to favorites!___'

2 changes: 1 addition & 1 deletion pyradio/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
''' This is PyRadio version this
install.py was released for
'''
PyRadioInstallPyReleaseVersion = '0.9.3.7'
PyRadioInstallPyReleaseVersion = '0.9.3.8'

import locale
locale.setlocale(locale.LC_ALL, "")
Expand Down
1 change: 1 addition & 0 deletions pyradio/messages_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def set_text(self, parent, *args):
i |*| Display station |i|nfo (when playing).
r |*| Select and play a random station.
Space|, |Left|, |h |*| Stop / start playing selected station.
* |*| Add station to favorites.
Esc|, |q |*| Quit.
!Volume management
Expand Down
Loading

0 comments on commit 334b084

Please sign in to comment.