Skip to content

Commit fcd0570

Browse files
committed
- fixing a couple of stations history bugs
- starting moving stations history to global functions
1 parent ddc8a1b commit fcd0570

File tree

3 files changed

+63
-34
lines changed

3 files changed

+63
-34
lines changed

pyradio/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,13 +2497,13 @@ def __init__(
24972497
self.item = -1
24982498

24992499
######## DEBUG START
2500-
#self.items = [
2501-
# ['reversed', 'WKHR', 1],
2502-
# ['reversed', 'Jazz (Sonic Universe - SomaFM)', 11],
2503-
# ['stations', 'Celtic (ThistleRadio - SomaFM)', 3]
2504-
#]
2505-
#self.item = 0
2506-
#self.play_from_history = True
2500+
self.items = [
2501+
['reversed', 'Lounge (Illinois Street Lounge - SomaFM)', 10],
2502+
['reversed', 'Folk (Folk Forward - SomaFM)', 17],
2503+
['Κέρκυρα', 'Ράδιο Επτάνησα 98,8', 11]
2504+
]
2505+
self.item = 0
2506+
self.play_from_history = True
25072507
#self.clear()
25082508
######## DEBUG END
25092509

pyradio/log.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ def set_win_title(msg=None):
293293
just_return = (
294294
'Config saved',
295295
'Online service Config',
296+
'Error saving config',
297+
'Already at',
298+
'History is empty',
299+
'Operation not supported',
300+
'Please wait for the player to settle',
296301
)
297302
do_not_update = (
298303
': Playback stopped',

pyradio/radio.py

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ def __init__(self, pyradio_config,
516516
ord('m'): self._volume_mute,
517517
ord('v'): self._volume_save,
518518
ord('~'): self._toggle_claculated_colors,
519+
ord('<'): self._stations_history_previous,
520+
ord('>'): self._stations_history_next,
519521
}
520522

521523

@@ -5228,6 +5230,28 @@ def _show_stations_history_notification(self, msg_id):
52285230
callback_function=self.refreshBody
52295231
)
52305232

5233+
def _stations_history_previous(self):
5234+
self._update_status_bar_right(status_suffix='')
5235+
if int(self._cnf.connection_timeout_int) == 0:
5236+
self._show_stations_history_notification(0)
5237+
else:
5238+
if self.player.connecting:
5239+
self._show_stations_history_notification(1)
5240+
else:
5241+
self._cnf.play_from_history = True
5242+
self._cnf.stations_history.play_previous()
5243+
5244+
def _stations_history_next(self):
5245+
self._update_status_bar_right(status_suffix='')
5246+
if int(self._cnf.connection_timeout_int) == 0:
5247+
self._show_stations_history_notification(0)
5248+
else:
5249+
if self.player.connecting:
5250+
self._show_stations_history_notification(1)
5251+
else:
5252+
self._cnf.play_from_history = True
5253+
self._cnf.stations_history.play_next()
5254+
52315255
def keypress(self, char):
52325256
if self._system_asked_to_terminate:
52335257
''' Make sure we exit when signal received '''
@@ -7182,27 +7206,7 @@ def keypress(self, char):
71827206
return
71837207

71847208
if self.ws.operation_mode == self.ws.NORMAL_MODE:
7185-
if char == ord('<'):
7186-
self._update_status_bar_right(status_suffix='')
7187-
if int(self._cnf.connection_timeout_int) == 0:
7188-
self._show_stations_history_notification(0)
7189-
else:
7190-
if self.player.connecting:
7191-
self._show_stations_history_notification(1)
7192-
else:
7193-
self._cnf.play_from_history = True
7194-
self._cnf.stations_history.play_previous()
7195-
elif char == ord('>'):
7196-
self._update_status_bar_right(status_suffix='')
7197-
if int(self._cnf.connection_timeout_int) == 0:
7198-
self._show_stations_history_notification(0)
7199-
else:
7200-
if self.player.connecting:
7201-
self._show_stations_history_notification(1)
7202-
else:
7203-
self._cnf.play_from_history = True
7204-
self._cnf.stations_history.play_next()
7205-
elif char == curses.KEY_F8 and platform.startswith('win'):
7209+
if char == curses.KEY_F8 and platform.startswith('win'):
72067210
''' manage players on Windows
72077211
will present them after curses end
72087212
'''
@@ -8482,19 +8486,19 @@ def _add_station_to_stations_history(self):
84828486
self._cnf.stations_history.add(self._cnf.station_file_name[:-4], self.stations[self.playing][0], self.playing)
84838487

84848488
def _load_playlist_and_station_from_station_history(self, h_item, func):
8489+
num = -1
8490+
current_playlist = self._cnf.station_file_name[:-4]
84858491
if h_item[0] == h_item[1] or \
84868492
h_item[1].startswith('register_') or \
84878493
h_item[-1] < 0 or \
8488-
h_item[-1] >= self.number_of_items:
8494+
(h_item[-1] >= self.number_of_items and current_playlist == h_item[0]):
84898495
if logger.isEnabledFor(logging.ERROR):
84908496
logger.error('\n===============\nInvalid h_item: "{0}"\nNumber of stations = {1}\n==============='.format(h_item, self.number_of_items))
84918497
func()
84928498
return
84938499
if logger.isEnabledFor(logging.DEBUG):
84948500
logger.debug('Activating station history item: {}'.format(h_item))
84958501

8496-
num = -1
8497-
current_playlist = self._cnf.station_file_name[:-4]
84988502
if current_playlist == h_item[0] or \
84998503
h_item[0] == 'Online Browser':
85008504
''' I am moving within the loaded playlist '''
@@ -8568,13 +8572,18 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
85688572
self._playlist_in_editor = self._cnf.station_path
85698573
self._playlist_error_message = ''
85708574
''' update station header on top of window '''
8571-
self.outerBodyWin.box()
8572-
self._print_body_header()
8573-
self.outerBodyWin.refresh()
8575+
if not (self._limited_height_mode or self._limited_width_mode):
8576+
logger.error('==== update outer Body!')
8577+
self.outerBodyWin.box()
8578+
self._print_body_header()
8579+
self.outerBodyWin.refresh()
85748580
self.playSelection()
85758581
self._set_active_stations()
85768582
self._get_playlists_data_from_playlist_name(h_item[0])
85778583
self.saved_active_stations = [['', 0], ['', -1]]
8584+
if self._limited_height_mode or self._limited_width_mode:
8585+
logger.error('==== update body')
8586+
self._print_limited_info()
85788587
return
85798588

85808589
try:
@@ -8597,6 +8606,9 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
85978606
self.stations
85988607
]
85998608
self.saved_active_stations = [['', 0], ['', -1]]
8609+
if self._limited_height_mode or self._limited_width_mode:
8610+
logger.error('==== update body')
8611+
self._print_limited_info()
86008612

86018613
def _get_playlists_data_from_playlist_name(self, a_playlist):
86028614
change_regs_too = False
@@ -8636,14 +8648,22 @@ def _scan_playlist_for_station(self, stations, start, station_to_find):
86368648
logger.error('Scanning playlist...')
86378649
up = down = 0
86388650
num = -1
8651+
if logger.isEnabledFor(logging.DEBUG):
8652+
logger.debug(' checking start={0}: "{1}"'.format(start, stations[start]))
8653+
if stations[start][0] == station_to_find:
8654+
return start
86398655
for i in range(start, -1, -1):
86408656
up = i + 1
86418657
down = i - 1
86428658
if down > -1 :
8659+
if logger.isEnabledFor(logging.DEBUG):
8660+
logger.debug(' checking down={0}: "{1}"'.format(down, stations[down]))
86438661
if stations[down][0] == station_to_find:
86448662
num = down
86458663
break
86468664
if up < self._cnf.number_of_stations:
8665+
if logger.isEnabledFor(logging.DEBUG):
8666+
logger.debug(' checking up={0}: "{1}"'.format(up, stations[up]))
86478667
if stations[up][0] == station_to_find:
86488668
num = up
86498669
break
@@ -8653,6 +8673,8 @@ def _scan_playlist_for_station(self, stations, start, station_to_find):
86538673
if logger.isEnabledFor(logging.DEBUG):
86548674
logger.debug('Station not found... Scanning to top...')
86558675
for i in range(down, -1, -1):
8676+
if logger.isEnabledFor(logging.DEBUG):
8677+
logger.debug(' checking {0}: "{1}"'.format(i, stations[i]))
86568678
if stations[i][0] == station_to_find:
86578679
num = i
86588680
break
@@ -8661,6 +8683,8 @@ def _scan_playlist_for_station(self, stations, start, station_to_find):
86618683
if logger.isEnabledFor(logging.DEBUG):
86628684
logger.debug('Station not found... Scanning to bottom...')
86638685
for i in range(up, self._cnf.number_of_stations - 1):
8686+
if logger.isEnabledFor(logging.DEBUG):
8687+
logger.debug(' checking {0}: "{1}"'.format(i, stations[i]))
86648688
if stations[i][0] == station_to_find:
86658689
num = i
86668690
break

0 commit comments

Comments
 (0)