Skip to content

Commit e4b4d06

Browse files
committed
- version 0.8.9.27 (0.9-beta24)
- implementing Stations History for RadioBrowser - station encoding will be checked before used - fixing station paste to playlist - updating docs
1 parent 5995d7c commit e4b4d06

File tree

9 files changed

+298
-72
lines changed

9 files changed

+298
-72
lines changed

Changelog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2022-09-18 s-n-g
2+
* version 0.8.9.27 (0.9-beta24)
3+
* Implementing Stations History as per #161
4+
* Station encoding will be checked before used
5+
* Fixing several crashes
6+
* Fixing several Python 2 errors
7+
* Fixing station paste to playlist
8+
* Fixing RadioBrowser columns when CJK characters are
9+
present, on Windows
10+
111
2022-08-28 s-n-g
212
* version 0.8.9.26 (0.9-beta23)
313
* adding calculated messages windows color

README.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ <h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><
7070
<li><a href="#managing-%22foreign%22-playlists">Managing “foreign” playlists</a></li>
7171
<li><a href="#playlist-history">Playlist history</a></li>
7272
</ul></li>
73+
<li><a href="#stations-history">Stations history</a></li>
7374
<li><a href="#search-function">Search function</a></li>
7475
<li><a href="#line-editor">Line editor</a>
7576
<ul>
@@ -179,6 +180,16 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
179180
<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>
180181
<pre style="height: 200px;">
181182

183+
2022-09-18 s-n-g
184+
* version 0.8.9.27 (0.9-beta24)
185+
* Implementing Stations History as per #161
186+
* Station encoding will be checked before used
187+
* Fixing several crashes
188+
* Fixing several Python 2 errors
189+
* Fixing station paste to playlist
190+
* Fixing RadioBrowser columns when CJK characters are
191+
present, on Windows
192+
182193
2022-08-28 s-n-g
183194
* version 0.8.9.26 (0.9-beta23)
184195
* adding calculated messages windows color
@@ -892,6 +903,7 @@ <h2 id="controls">Controls <span style="padding-left: 10px;"><sup style="font-si
892903
E Change station&#39;s encoding - -
893904
DEL,x Delete selected station - -
894905
O Open RadioBrowser - -
906+
&lt; &gt; Browse the Stations history list - -
895907
t T Load theme / Toggle transparency [Valid] [Valid]
896908
c Open Configuration window. - -
897909
/ n N Search, go to next / previous result [Valid] [Valid]
@@ -1053,6 +1065,11 @@ <h3 id="playlist-history">Playlist history</h3>
10531065
<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>
10541066
<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>
10551067
<p>Going forward in history is not supported.</p>
1068+
<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>
1069+
<p>Playing several stations, sometimes among different playlists, and returning to them is sometimes a tedious operation.</p>
1070+
<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>
1071+
<p>The user can go back and forth in this list using the “<strong>&lt;</strong>” and “<strong>&gt;</strong>” keys.</p>
1072+
<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>
10561073
<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>
10571074
<p>On any window presenting a list of items (stations, playlists, themes) a <strong>search function</strong> is available by pressing “<strong>/</strong>”.</p>
10581075
<p>The <em>Search Window</em> supports normal and extend editing and in session history.</p>

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
2828
* [Managing playlists (within PyRadio)](#managing-playlists-(within-pyradio))
2929
* [Managing "foreign" playlists](#managing-"foreign"-playlists)
3030
* [Playlist history](#playlist-history)
31+
* [Stations history](#stations-history)
3132
* [Search function](#search-function)
3233
* [Line editor](#line-editor)
3334
* [CJK characters support](#cjk-characters-support)
@@ -209,6 +210,7 @@ The following options can also be set in **PyRadio**'s [configuration file](#con
209210
E Change station's encoding - -
210211
DEL,x Delete selected station - -
211212
O Open RadioBrowser - -
213+
< > Browse the Stations history list - -
212214
t T Load theme / Toggle transparency [Valid] [Valid]
213215
c Open Configuration window. - -
214216
/ n N Search, go to next / previous result [Valid] [Valid]
@@ -421,6 +423,16 @@ In order to go back to the previous playlist, the user just has to press "**\\\\
421423

422424
Going forward in history is not supported.
423425

426+
## Stations history
427+
428+
Playing several stations, sometimes among different playlists, and returning to them is sometimes a tedious operation.
429+
430+
This problem is addressed with the "**Station history**" functionality, which is actually a list of stations which have been played back.
431+
432+
The user can go back and forth in this list using the "**<**" and "**>**" keys.
433+
434+
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.
435+
424436
## Search function
425437

426438
On any window presenting a list of items (stations, playlists, themes) a **search function** is available by pressing "**/**".

pyradio.1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Copyright (C) 2011 Ben Dowling <http://www.coderholic.com/pyradio>
22
.\" This manual is freely distributable under the terms of the GPL.
33
.\"
4-
.TH pyradio 1 "August 2022" PyRadio
4+
.TH pyradio 1 "September 2022" PyRadio
55

66
.SH Name
77
.PP
@@ -116,6 +116,10 @@ Edit current station
116116
Change current station's encoding
117117
.IP \fBDEL\fR,\fBx
118118
Delete selected station
119+
.IP \fBO\fR
120+
Open \fIRadio Browser\fR
121+
.IP \fB<\fR\ /\ \fB>\fR
122+
Browse the \fIStations history\fR list
119123
.IP \fBJ
120124
Create a \fIJump tag
121125
.IP \fI<n>\fB^U\fR,\fI<n>\fB^D
@@ -392,6 +396,16 @@ In order to go back to the previous playlist, the user just has to press "\fI\\\
392396

393397
Going forward in history is not supported.
394398

399+
.SH Stations history
400+
401+
Playing several stations, sometimes among different playlists, and returning to them is sometimes a tedious operation.
402+
403+
This problem is addressed with the \fBStation history\fR functionality, which is actually a list of stations which have been played back.
404+
405+
The user can go back and forth in this list using the "\fI<\fR" and "\fI>\fR" keys.
406+
407+
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.
408+
395409
.SH Search Function
396410

397411
On any window presenting a list of items (stations, playlists, themes) a \fBsearch function\fR is available by pressing "\fI/\fR".

pyradio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" pyradio -- Console radio player. "
22

3-
version_info = (0, 8, 9, 26)
3+
version_info = (0, 8, 9, 27)
44

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

pyradio/browser.py

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,19 @@ def add_to_title(self):
397397
def _get_title(self):
398398
self.TITLE = 'RadioBrowser ({})'.format(country_from_server(self._server))
399399

400+
def set_station_history(self,
401+
execute_funct,
402+
pass_first_item_funct,
403+
pass_last_item_funct,
404+
no_items_funct):
405+
self.stations_history = RadioBrowserStationsStack(
406+
execute_function=execute_funct,
407+
pass_first_item_function=pass_first_item_funct,
408+
pass_last_item_function=pass_last_item_funct,
409+
no_items_function=no_items_funct
410+
)
411+
return self.stations_history
412+
400413
def set_global_functions(self, global_functions):
401414
self._global_functions = {}
402415
if global_functions is not None:
@@ -976,7 +989,7 @@ def format_station_line(self, id_in_list, pad, width):
976989
if PY3:
977990
return out[0] + self._raw_stations[id_in_list]['name'], ' ' + out[2]
978991
else:
979-
return out[0] + self._raw_stations[id_in_list]['name'].encode('utf-8', 'replace'), out[2].encode('utf-8', 'replace')
992+
return out[0] + self._raw_stations[id_in_list]['name'].encode('utf-8', 'replace'), ' ' + out[2].encode('utf-8', 'replace')
980993

981994
def set_encoding(self, id_in_list, new_encoding):
982995
if id_in_list < len(self._raw_stations):
@@ -4182,6 +4195,138 @@ def keypress(self, char):
41824195

41834196
return 1
41844197

4198+
class RadioBrowserStationsStack(object):
4199+
pass_first_item_func=None
4200+
pass_last_item_func=None
4201+
no_items_func=None
4202+
play_from_history = False
4203+
4204+
''' items: list of lists
4205+
[
4206+
[name, station name, station id],
4207+
...
4208+
]
4209+
'''
4210+
4211+
def __init__(
4212+
self,
4213+
execute_function,
4214+
pass_first_item_function=None,
4215+
pass_last_item_function=None,
4216+
no_items_function=None
4217+
):
4218+
self.items = []
4219+
self.item = -1
4220+
4221+
######## DEBUG START
4222+
#self.items = [
4223+
# ['reversed', 'WKHR', 1],
4224+
# ['reversed', 'Jazz (Sonic Universe - SomaFM)', 11],
4225+
# ['stations', 'Celtic (ThistleRadio - SomaFM)', 3]
4226+
#]
4227+
#self.item = 0
4228+
#self.play_from_history = True
4229+
#self.clear()
4230+
######## DEBUG END
4231+
4232+
self.execute_func = execute_function
4233+
self.pass_first_item_func = pass_first_item_function
4234+
self.pass_last_item_func = pass_last_item_function
4235+
self.no_items_func = no_items_function
4236+
4237+
def _show_station_history_debug(self):
4238+
if logger.isEnabledFor(logging.DEBUG):
4239+
logger.debug('>>> Online browser stations history')
4240+
if self.items:
4241+
for n in self.items:
4242+
logger.debug(' {}'.format(n))
4243+
logger.debug(' item was = {}'.format(self.item))
4244+
else:
4245+
logger.debug(' No items in list')
4246+
logger.debug(' item = {}'.format(self.item))
4247+
4248+
def add(self, a_playlist, a_station, a_station_id):
4249+
a_playlist = 'Online Browser'
4250+
if self.item == -1:
4251+
self.items.append([a_playlist, a_station, a_station_id])
4252+
self.item = 0
4253+
self._show_station_history_debug()
4254+
else:
4255+
if not a_station.startswith('register_') and \
4256+
(not self.play_from_history) and \
4257+
self.items[self.item][1] != a_station:
4258+
if logger.isEnabledFor(logging.DEBUG):
4259+
logger.debug('Adding station history item...')
4260+
self.items.append([a_playlist, a_station, a_station_id])
4261+
self.item = len(self.items) - 1
4262+
self._show_station_history_debug()
4263+
#else:
4264+
# if logger.isEnabledFor(logging.DEBUG):
4265+
# logger.debug('Not adding station history item...')
4266+
self.play_from_history = False
4267+
4268+
def clear(self):
4269+
self.items = []
4270+
self.item = -1
4271+
self.play_from_history = False
4272+
4273+
def remove_station(self, a_station):
4274+
for i in range(len(self.items) - 1, -1, -1):
4275+
if self.items[i][1] == a_station:
4276+
self.items.pop(i)
4277+
if self.item >= len(self.items):
4278+
self.item = len(self.items) - 1
4279+
self._show_station_history_debug()
4280+
4281+
def rename_station(self, playlist, orig_station, new_station):
4282+
# logger.error('playlist = "{}"'.format(playlist))
4283+
# logger.error('orig_station = "{}"'.format(orig_station))
4284+
# logger.error('new_station = "{}"'.format(new_station))
4285+
self._show_station_history_debug()
4286+
for i in range(len(self.items) - 1, -1, -1):
4287+
if self.items[i][1] == orig_station:
4288+
logger.error('item = {}'.format(self.items[i]))
4289+
self.items[i][1] = new_station
4290+
logger.error('item = {}'.format(self.items[i]))
4291+
self._show_station_history_debug()
4292+
4293+
def _get(self):
4294+
if self.item == -1:
4295+
if self.no_items_func is not None:
4296+
self.no_items_func()
4297+
return tuple(self.items[self.item])
4298+
4299+
def play_previous(self):
4300+
self._show_station_history_debug()
4301+
if self.item == -1:
4302+
if self.no_items_func is not None:
4303+
self.no_items_func()
4304+
elif self.item == 0:
4305+
if logger.isEnabledFor(logging.DEBUG):
4306+
logger.debug(' Already on first item')
4307+
if self.pass_first_item_func is not None:
4308+
self.pass_first_item_func()
4309+
else:
4310+
self.item -= 1
4311+
if logger.isEnabledFor(logging.DEBUG):
4312+
logger.debug(' item is = {}'.format(self.item))
4313+
self.execute_func(self._get(), self.play_previous)
4314+
4315+
def play_next(self):
4316+
self._show_station_history_debug()
4317+
if self.item == -1:
4318+
if self.no_items_func is not None:
4319+
self.no_items_func()
4320+
elif self.item == len(self.items) - 1:
4321+
if logger.isEnabledFor(logging.DEBUG):
4322+
logger.debug(' Already on last item')
4323+
if self.pass_last_item_func is not None:
4324+
self.pass_last_item_func()
4325+
else:
4326+
self.item += 1
4327+
if logger.isEnabledFor(logging.DEBUG):
4328+
logger.debug(' item is = {}'.format(self.item))
4329+
self.execute_func(self._get(), self.play_next)
41854330

41864331
def probeBrowsers(a_browser_url):
41874332
base_url = a_browser_url.split('/')[2]

pyradio/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class PyRadioStations(object):
107107
station_history = None
108108
play_from_history = False
109109

110+
normal_stations_history = None
111+
110112
def __init__(self, stationFile=''):
111113
if platform.startswith('win'):
112114
self._open_string_id = 1
@@ -300,12 +302,13 @@ def set_station_history(self,
300302
pass_first_item_funct,
301303
pass_last_item_funct,
302304
no_items_funct):
303-
self.stations_history = PyRadioStationsStack(
305+
self.normal_stations_history = PyRadioStationsStack(
304306
execute_function=execute_funct,
305307
pass_first_item_function=pass_first_item_funct,
306308
pass_last_item_function=pass_last_item_funct,
307309
no_items_function=no_items_funct
308310
)
311+
self.stations_history = self.normal_stations_history
309312

310313
def save_last_playlist(self, sel):
311314
lp = path.join(self.stations_dir, 'last_playlist')
@@ -905,7 +908,7 @@ def paste_station_to_named_playlist(self, a_station, a_playlist):
905908
w_str = w_str[:-1]
906909
try:
907910
with open(a_playlist, 'a') as f:
908-
f.write(w_str)
911+
f.write('\n' + w_str)
909912
return 0
910913
except:
911914
return -5

pyradio/log.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import logging
55
import threading
66
from .common import player_start_stop_token
7+
from .cjkwrap import cjklen, PY3
8+
if not PY3:
9+
import warnings
10+
warnings.simplefilter("ignore")
711

812
logger = logging.getLogger(__name__)
913

@@ -325,19 +329,11 @@ def set_win_title(msg=None):
325329
token_id = 0
326330
break
327331

328-
if Log.old_window_title is not None:
329-
''' fix for python2 '''
332+
if Log.old_window_title == d_msg:
330333
# if logger.isEnabledFor(logging.DEBUG):
331-
# logger.debug('set_win_title(): Old title is "' + Log.old_window_title+ '"')
332-
if Log.old_window_title == d_msg:
333-
# if logger.isEnabledFor(logging.DEBUG):
334-
# logger.debug('set_win_title(): same title... return')
335-
return
336-
Log.old_window_title = d_msg
337-
else:
338-
# if logger.isEnabledFor(logging.DEBUG):
339-
# logger.debug('set_win_title(): set_win_title(): Old title is None')
340-
Log.old_window_title = d_msg
334+
# logger.debug('set_win_title(): same title... return')
335+
return
336+
Log.old_window_title = d_msg
341337

342338
# if logger.isEnabledFor(logging.DEBUG):
343339
# logger.debug('set_win_title(): d_msg = "' + d_msg + '"')

0 commit comments

Comments
 (0)