Skip to content

Commit

Permalink
- version 0.8.9.27 (0.9-beta24)
Browse files Browse the repository at this point in the history
- implementing Stations History for RadioBrowser
- station encoding will be checked before used
- fixing station paste to playlist
- updating docs
  • Loading branch information
s-n-g committed Sep 18, 2022
1 parent 5995d7c commit e4b4d06
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 72 deletions.
10 changes: 10 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2022-09-18 s-n-g
* version 0.8.9.27 (0.9-beta24)
* Implementing Stations History as per #161
* Station encoding will be checked before used
* Fixing several crashes
* Fixing several Python 2 errors
* Fixing station paste to playlist
* Fixing RadioBrowser columns when CJK characters are
present, on Windows

2022-08-28 s-n-g
* version 0.8.9.26 (0.9-beta23)
* adding calculated messages windows color
Expand Down
17 changes: 17 additions & 0 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ <h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><
<li><a href="#managing-%22foreign%22-playlists">Managing “foreign” playlists</a></li>
<li><a href="#playlist-history">Playlist history</a></li>
</ul></li>
<li><a href="#stations-history">Stations history</a></li>
<li><a href="#search-function">Search function</a></li>
<li><a href="#line-editor">Line editor</a>
<ul>
Expand Down Expand Up @@ -179,6 +180,16 @@ <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;">

2022-09-18 s-n-g
* version 0.8.9.27 (0.9-beta24)
* Implementing Stations History as per #161
* Station encoding will be checked before used
* Fixing several crashes
* Fixing several Python 2 errors
* Fixing station paste to playlist
* Fixing RadioBrowser columns when CJK characters are
present, on Windows

2022-08-28 s-n-g
* version 0.8.9.26 (0.9-beta23)
* adding calculated messages windows color
Expand Down Expand Up @@ -892,6 +903,7 @@ <h2 id="controls">Controls <span style="padding-left: 10px;"><sup style="font-si
E Change station&#39;s encoding - -
DEL,x Delete selected station - -
O Open RadioBrowser - -
&lt; &gt; Browse the Stations history list - -
t T Load theme / Toggle transparency [Valid] [Valid]
c Open Configuration window. - -
/ n N Search, go to next / previous result [Valid] [Valid]
Expand Down Expand Up @@ -1053,6 +1065,11 @@ <h3 id="playlist-history">Playlist history</h3>
<p><strong>PyRadio</strong> will keep a history of all the playlists opened (within a given session), so that navigating between them is made easy.</p>
<p>In order to go back to the previous playlist, the user just has to press “<strong>\\</strong>” (double backslash). To get to the first playlist “<strong>\]</strong>” (backslash - closing square bracket) can be used.</p>
<p>Going forward in history is not supported.</p>
<h2 id="stations-history">Stations history <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>Playing several stations, sometimes among different playlists, and returning to them is sometimes a tedious operation.</p>
<p>This problem is addressed with the “<strong>Station history</strong>” functionality, which is actually a list of stations which have been played back.</p>
<p>The user can go back and forth in this list using the “<strong>&lt;</strong>” and “<strong>&gt;</strong>” keys.</p>
<p>The list is not saved between sessions (restarting the program will lead to an empty list). When an “<strong>online service</strong> is used (e.g. <strong>Radio Browser</strong>) the list is reseted with every search that is performed.</p>
<h2 id="search-function">Search function <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>On any window presenting a list of items (stations, playlists, themes) a <strong>search function</strong> is available by pressing “<strong>/</strong>”.</p>
<p>The <em>Search Window</em> supports normal and extend editing and in session history.</p>
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
* [Managing playlists (within PyRadio)](#managing-playlists-(within-pyradio))
* [Managing "foreign" playlists](#managing-"foreign"-playlists)
* [Playlist history](#playlist-history)
* [Stations history](#stations-history)
* [Search function](#search-function)
* [Line editor](#line-editor)
* [CJK characters support](#cjk-characters-support)
Expand Down Expand Up @@ -209,6 +210,7 @@ The following options can also be set in **PyRadio**'s [configuration file](#con
E Change station's encoding - -
DEL,x Delete selected station - -
O Open RadioBrowser - -
< > Browse the Stations history list - -
t T Load theme / Toggle transparency [Valid] [Valid]
c Open Configuration window. - -
/ n N Search, go to next / previous result [Valid] [Valid]
Expand Down Expand Up @@ -421,6 +423,16 @@ In order to go back to the previous playlist, the user just has to press "**\\\\

Going forward in history is not supported.

## Stations history

Playing several stations, sometimes among different playlists, and returning to them is sometimes a tedious operation.

This problem is addressed with the "**Station history**" functionality, which is actually a list of stations which have been played back.

The user can go back and forth in this list using the "**<**" and "**>**" keys.

The list is not saved between sessions (restarting the program will lead to an empty list). When an "**online service** is used (e.g. **Radio Browser**) the list is reseted with every search that is performed.

## Search function

On any window presenting a list of items (stations, playlists, themes) a **search function** is available by pressing "**/**".
Expand Down
16 changes: 15 additions & 1 deletion pyradio.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" Copyright (C) 2011 Ben Dowling <http://www.coderholic.com/pyradio>
.\" This manual is freely distributable under the terms of the GPL.
.\"
.TH pyradio 1 "August 2022" PyRadio
.TH pyradio 1 "September 2022" PyRadio

.SH Name
.PP
Expand Down Expand Up @@ -116,6 +116,10 @@ Edit current station
Change current station's encoding
.IP \fBDEL\fR,\fBx
Delete selected station
.IP \fBO\fR
Open \fIRadio Browser\fR
.IP \fB<\fR\ /\ \fB>\fR
Browse the \fIStations history\fR list
.IP \fBJ
Create a \fIJump tag
.IP \fI<n>\fB^U\fR,\fI<n>\fB^D
Expand Down Expand Up @@ -392,6 +396,16 @@ In order to go back to the previous playlist, the user just has to press "\fI\\\

Going forward in history is not supported.

.SH Stations history

Playing several stations, sometimes among different playlists, and returning to them is sometimes a tedious operation.

This problem is addressed with the \fBStation history\fR functionality, which is actually a list of stations which have been played back.

The user can go back and forth in this list using the "\fI<\fR" and "\fI>\fR" keys.

The list is not saved between sessions (restarting the program will lead to an empty list). When an \fBonline service\fR is used (e.g. \fIRadio Browser\fR) the list is reseted with every search that is performed.

.SH Search Function

On any window presenting a list of items (stations, playlists, themes) a \fBsearch function\fR is available by pressing "\fI/\fR".
Expand Down
2 changes: 1 addition & 1 deletion pyradio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" pyradio -- Console radio player. "

version_info = (0, 8, 9, 26)
version_info = (0, 8, 9, 27)

# Set it to True if new stations have been
# added to the package's stations.csv
Expand Down
147 changes: 146 additions & 1 deletion pyradio/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ def add_to_title(self):
def _get_title(self):
self.TITLE = 'RadioBrowser ({})'.format(country_from_server(self._server))

def set_station_history(self,
execute_funct,
pass_first_item_funct,
pass_last_item_funct,
no_items_funct):
self.stations_history = RadioBrowserStationsStack(
execute_function=execute_funct,
pass_first_item_function=pass_first_item_funct,
pass_last_item_function=pass_last_item_funct,
no_items_function=no_items_funct
)
return self.stations_history

def set_global_functions(self, global_functions):
self._global_functions = {}
if global_functions is not None:
Expand Down Expand Up @@ -976,7 +989,7 @@ def format_station_line(self, id_in_list, pad, width):
if PY3:
return out[0] + self._raw_stations[id_in_list]['name'], ' ' + out[2]
else:
return out[0] + self._raw_stations[id_in_list]['name'].encode('utf-8', 'replace'), out[2].encode('utf-8', 'replace')
return out[0] + self._raw_stations[id_in_list]['name'].encode('utf-8', 'replace'), ' ' + out[2].encode('utf-8', 'replace')

def set_encoding(self, id_in_list, new_encoding):
if id_in_list < len(self._raw_stations):
Expand Down Expand Up @@ -4182,6 +4195,138 @@ def keypress(self, char):

return 1

class RadioBrowserStationsStack(object):
pass_first_item_func=None
pass_last_item_func=None
no_items_func=None
play_from_history = False

''' items: list of lists
[
[name, station name, station id],
...
]
'''

def __init__(
self,
execute_function,
pass_first_item_function=None,
pass_last_item_function=None,
no_items_function=None
):
self.items = []
self.item = -1

######## DEBUG START
#self.items = [
# ['reversed', 'WKHR', 1],
# ['reversed', 'Jazz (Sonic Universe - SomaFM)', 11],
# ['stations', 'Celtic (ThistleRadio - SomaFM)', 3]
#]
#self.item = 0
#self.play_from_history = True
#self.clear()
######## DEBUG END

self.execute_func = execute_function
self.pass_first_item_func = pass_first_item_function
self.pass_last_item_func = pass_last_item_function
self.no_items_func = no_items_function

def _show_station_history_debug(self):
if logger.isEnabledFor(logging.DEBUG):
logger.debug('>>> Online browser stations history')
if self.items:
for n in self.items:
logger.debug(' {}'.format(n))
logger.debug(' item was = {}'.format(self.item))
else:
logger.debug(' No items in list')
logger.debug(' item = {}'.format(self.item))

def add(self, a_playlist, a_station, a_station_id):
a_playlist = 'Online Browser'
if self.item == -1:
self.items.append([a_playlist, a_station, a_station_id])
self.item = 0
self._show_station_history_debug()
else:
if not a_station.startswith('register_') and \
(not self.play_from_history) and \
self.items[self.item][1] != a_station:
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Adding station history item...')
self.items.append([a_playlist, a_station, a_station_id])
self.item = len(self.items) - 1
self._show_station_history_debug()
#else:
# if logger.isEnabledFor(logging.DEBUG):
# logger.debug('Not adding station history item...')
self.play_from_history = False

def clear(self):
self.items = []
self.item = -1
self.play_from_history = False

def remove_station(self, a_station):
for i in range(len(self.items) - 1, -1, -1):
if self.items[i][1] == a_station:
self.items.pop(i)
if self.item >= len(self.items):
self.item = len(self.items) - 1
self._show_station_history_debug()

def rename_station(self, playlist, orig_station, new_station):
# logger.error('playlist = "{}"'.format(playlist))
# logger.error('orig_station = "{}"'.format(orig_station))
# logger.error('new_station = "{}"'.format(new_station))
self._show_station_history_debug()
for i in range(len(self.items) - 1, -1, -1):
if self.items[i][1] == orig_station:
logger.error('item = {}'.format(self.items[i]))
self.items[i][1] = new_station
logger.error('item = {}'.format(self.items[i]))
self._show_station_history_debug()

def _get(self):
if self.item == -1:
if self.no_items_func is not None:
self.no_items_func()
return tuple(self.items[self.item])

def play_previous(self):
self._show_station_history_debug()
if self.item == -1:
if self.no_items_func is not None:
self.no_items_func()
elif self.item == 0:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(' Already on first item')
if self.pass_first_item_func is not None:
self.pass_first_item_func()
else:
self.item -= 1
if logger.isEnabledFor(logging.DEBUG):
logger.debug(' item is = {}'.format(self.item))
self.execute_func(self._get(), self.play_previous)

def play_next(self):
self._show_station_history_debug()
if self.item == -1:
if self.no_items_func is not None:
self.no_items_func()
elif self.item == len(self.items) - 1:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(' Already on last item')
if self.pass_last_item_func is not None:
self.pass_last_item_func()
else:
self.item += 1
if logger.isEnabledFor(logging.DEBUG):
logger.debug(' item is = {}'.format(self.item))
self.execute_func(self._get(), self.play_next)

def probeBrowsers(a_browser_url):
base_url = a_browser_url.split('/')[2]
Expand Down
7 changes: 5 additions & 2 deletions pyradio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class PyRadioStations(object):
station_history = None
play_from_history = False

normal_stations_history = None

def __init__(self, stationFile=''):
if platform.startswith('win'):
self._open_string_id = 1
Expand Down Expand Up @@ -300,12 +302,13 @@ def set_station_history(self,
pass_first_item_funct,
pass_last_item_funct,
no_items_funct):
self.stations_history = PyRadioStationsStack(
self.normal_stations_history = PyRadioStationsStack(
execute_function=execute_funct,
pass_first_item_function=pass_first_item_funct,
pass_last_item_function=pass_last_item_funct,
no_items_function=no_items_funct
)
self.stations_history = self.normal_stations_history

def save_last_playlist(self, sel):
lp = path.join(self.stations_dir, 'last_playlist')
Expand Down Expand Up @@ -905,7 +908,7 @@ def paste_station_to_named_playlist(self, a_station, a_playlist):
w_str = w_str[:-1]
try:
with open(a_playlist, 'a') as f:
f.write(w_str)
f.write('\n' + w_str)
return 0
except:
return -5
Expand Down
20 changes: 8 additions & 12 deletions pyradio/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import logging
import threading
from .common import player_start_stop_token
from .cjkwrap import cjklen, PY3
if not PY3:
import warnings
warnings.simplefilter("ignore")

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -325,19 +329,11 @@ def set_win_title(msg=None):
token_id = 0
break

if Log.old_window_title is not None:
''' fix for python2 '''
if Log.old_window_title == d_msg:
# if logger.isEnabledFor(logging.DEBUG):
# logger.debug('set_win_title(): Old title is "' + Log.old_window_title+ '"')
if Log.old_window_title == d_msg:
# if logger.isEnabledFor(logging.DEBUG):
# logger.debug('set_win_title(): same title... return')
return
Log.old_window_title = d_msg
else:
# if logger.isEnabledFor(logging.DEBUG):
# logger.debug('set_win_title(): set_win_title(): Old title is None')
Log.old_window_title = d_msg
# logger.debug('set_win_title(): same title... return')
return
Log.old_window_title = d_msg

# if logger.isEnabledFor(logging.DEBUG):
# logger.debug('set_win_title(): d_msg = "' + d_msg + '"')
Expand Down
Loading

0 comments on commit e4b4d06

Please sign in to comment.