Skip to content

Commit 42de00b

Browse files
committed
- adding buffering config file parameter
- config.py: buffering_data updated when player changes and when saving config (after editing) - diaplsy a message to manually remove the referer file if its deletion has failed - removing code to rename the referer file
1 parent e36a4c2 commit 42de00b

File tree

5 files changed

+197
-93
lines changed

5 files changed

+197
-93
lines changed

pyradio/config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ connection_timeout = 10
143143
# Default value: False
144144
force_http = False
145145

146+
# Buffering
147+
# This is the number of seconds the players will buffer data
148+
# before actually starting producing sound
149+
#
150+
# Valid values: 5 - 60 (0 to disable)
151+
# Default value = 0
152+
buffering = 0
153+
146154
# Default theme
147155
# Hard coded themes:
148156
# dark (default) (8 colors)

pyradio/config.py

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,12 @@ def read_playlist_file(
754754
referer = row[Station.referer].strip()
755755
this_row_version = Station.referer
756756

757+
if buffering:
758+
if '@' not in buffering:
759+
buffering += '@128'
760+
else:
761+
buffering = '0@128'
762+
757763
# Append the parsed values to the reading stations list
758764
station_info = [
759765
name, url, enc, {'image': icon} if icon else '',
@@ -924,37 +930,25 @@ def save_playlist_file(self, stationFile=''):
924930
logger.debug('Cannot rename playlist file...')
925931
return -2
926932
self.dirty_playlist = False
927-
if self.renamed_stations:
928-
for n in self.renamed_stations:
929-
chk_referer_file = path.join(self.stations_dir, n[0] + '.referer.txt')
930-
if path.exists(chk_referer_file):
931-
new_referer_file = path.join(self.stations_dir, n[1] + '.referer.txt')
932-
try:
933-
rename(chk_referer_file, new_referer_file)
934-
if logger.isEnabledFor(logging.DEBUG):
935-
logger.debug('referer file renamed from "{}" to "{}"'.format(
936-
path.basename(chk_referer_file),
937-
path.basename(new_referer_file)
938-
))
939-
except:
940-
pass
941-
if logger.isEnabledFor(logging.DEBUG):
942-
logger.debug('failed to rename referer file from "{}" to "{}"'.format(
943-
path.basename(chk_referer_file),
944-
path.basename(new_referer_file)
945-
))
946933
return 0
947934

948935
def _format_playlist_row(self, a_row):
949936
''' Return a row formatted according to the current playlist version,
950937
eliminating any empty fields that are not part of the specified version. '''
951938
this_row = deepcopy(a_row)
952-
939+
logger.error(f'{this_row}')
940+
logger.error(f'{self._playlist_version}')
953941
# Extract the 'image' from the icon dictionary if present
954-
if len(this_row) > 3 and 'image' in this_row[3]:
955-
this_row[3] = this_row[3]['image']
942+
if len(this_row) > Station.icon and 'image' in this_row[Station.icon]:
943+
this_row[Station.icon] = this_row[Station.icon]['image']
944+
945+
if len(this_row) > Station.buffering:
946+
if this_row[Station.buffering].startswith('0'):
947+
this_row[Station.buffering] = ''
956948

957-
return this_row
949+
ret = this_row[:self._playlist_version]
950+
logger.error(f'{ret = }')
951+
return this_row[:self._playlist_version]
958952

959953
def _set_playlist_elements(self, a_playlist, a_title=''):
960954
self.station_path = path.abspath(a_playlist)
@@ -1390,9 +1384,10 @@ class PyRadioConfig(PyRadioStations):
13901384
opts['confirm_station_deletion'] = ['Confirm station deletion: ', True]
13911385
opts['confirm_playlist_reload'] = ['Confirm playlist reload: ', True]
13921386
opts['auto_save_playlist'] = ['Auto save playlist: ', False]
1393-
opts['conn_title'] = ['Connection Options: ', '']
1387+
opts['conn_title'] = ['Connection Options', '']
13941388
opts['connection_timeout'] = ['Connection timeout: ', '10']
13951389
opts['force_http'] = ['Force http connections: ', False]
1390+
opts['buffering'] = ['Buffering (seconds): ', '20']
13961391
opts['notification'] = ['Notifications', '']
13971392
opts['enable_notifications'] = ['Enable notifications: ', '-1']
13981393
opts['use_station_icon'] = [' Use station icon: ', True]
@@ -1548,6 +1543,25 @@ def __init__(self, user_config_dir=None, headless=False):
15481543

15491544
self._read_notification_command()
15501545

1546+
@property
1547+
def buffering(self):
1548+
return self.opts['buffering'][1]
1549+
1550+
@buffering.setter
1551+
def buffering(self, val):
1552+
str_val = str(val)
1553+
old_val = self.opts['buffering'][1]
1554+
try:
1555+
if str_val == '0' or \
1556+
5 <= int(str_val) <= 60:
1557+
self.opts['buffering'][1] = str(int(str_val))
1558+
else:
1559+
self.opts['buffering'][1] = '0'
1560+
except ValueError:
1561+
self.opts['buffering'][1] = '0'
1562+
if old_val != self.opts['buffering'][1]:
1563+
self.dirty_config = True
1564+
15511565
@property
15521566
def log_titles(self):
15531567
return self.opts['log_titles'][1]
@@ -2555,6 +2569,15 @@ def _read_config(self, distro_config=False):
25552569
except (ValueError, TypeError):
25562570
tmp = '0'
25572571
self.opts['time_format'][1] = tmp
2572+
elif sp[0] == 'buffering':
2573+
try:
2574+
b = int(sp[1].strip())
2575+
except ValueError:
2576+
b = 0
2577+
if not (b == 0 or 5 <= b <= 60):
2578+
b = 0
2579+
self.opts['buffering'][1] = str(b)
2580+
25582581
elif sp[0] == 'localized_keys':
25592582
# logger.error(f'{sp[1] = }')
25602583
self.localize = None if sp[1].strip().lower() == 'none' else sp[1].strip().lower()

pyradio/config_window.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class PyRadioConfigWindow():
8585
'|', 'Valid values: 5 - 60, 0 disables check', 'Default value: 10'])
8686
_help_text.append(['Most radio stations use plain old http protocol to broadcast, but some of them use https.', '|', 'If this parameter is enabled, all connections will use http; results depend on the combination of station/player.', '|', 'This value is read at program startup, use "' + to_str('https') + '" to change its effect while mid-session.',
8787
'|', 'Default value: False'])
88+
_help_text.append(['This is the number of seconds the players will buffer data before actually staring playback.', '|', 'This is a global setting; it affects all stations.', '|', 'Please keep in mind that stations may have their own buffering value defined. In this case that value will be used instead of this global value.', '|', 'Accepted values:', ' 5 - 60 seconds', ' 0 disables buffering', '|', 'Default value: 0'])
8889
_help_text.append(None)
8990
_help_text.append(['If this options is enabled, a Desktop Notification will be displayed using the notification daemon / service.', '|', 'If enabled but no notification is displayed, please refer to', 'https://github.com/coderholic/pyradio/desktop-notification.md', '|', 'Valid values are:', ' -1: disabled ', ' 0: enabled (no repetition) ', ' x: repeat every x seconds ', '|', 'Default value: -1'])
9091
_help_text.append(['Notice: Not applicable on Windows!', '|', 'Online Radio Directory Services (like RadioBrowser) will usually provide an icon for the stations they advertise.', '|', 'PyRadio can use this icon (provided that one exists and is of JPG or PNG format) while displaying Desktop Notifications.', '|', 'Setting this option to True, will enable the behavior above.', '|', 'If this option is False, the default icon will be used.', '|', 'Default value: True'])
@@ -753,7 +754,7 @@ def keypress(self, char):
753754
self._max_start = len(self._config_options) -1 - self.maxY
754755
# logger.error('mas_start = {}'.format(self._max_start))
755756
val = list(self._config_options.items())[self.selection]
756-
# logger.error(f'{val[0] = }')
757+
# logger.error(f'{val = }')
757758
Y = self.selection - self._start + 1
758759

759760
if char in self._local_functions:
@@ -763,6 +764,7 @@ def keypress(self, char):
763764
'connection_timeout',
764765
'calculated_color_factor',
765766
'time_format',
767+
'buffering',
766768
) and char in (
767769
curses.KEY_LEFT,
768770
curses.KEY_RIGHT,
@@ -815,6 +817,37 @@ def keypress(self, char):
815817
]
816818
return Window_Stack_Constants.INSERT_RECORDINGS_DIR_MODE, []
817819

820+
elif val[0] == 'buffering':
821+
if char in (curses.KEY_RIGHT, kbkey['l']) or \
822+
check_localized(char, (kbkey['l'], )):
823+
t = int(val[1][1])
824+
if t == 0:
825+
t = 4
826+
if t < 60:
827+
t += 1
828+
self._config_options[val[0]][1] = str(t)
829+
self._win.addstr(
830+
Y, 3 + len(val[1][0]),
831+
str(t) + ' ', curses.color_pair(6))
832+
self._print_title()
833+
self._win.refresh()
834+
return -1, []
835+
836+
elif char in (curses.KEY_LEFT, kbkey['h']) or \
837+
check_localized(char, (kbkey['h'], )):
838+
t = int(val[1][1])
839+
if t > 5:
840+
t -= 1
841+
else:
842+
t = 0
843+
self._config_options[val[0]][1] = str(t)
844+
self._win.addstr(
845+
Y, 3 + len(val[1][0]),
846+
str(t) + ' ', curses.color_pair(6))
847+
self._print_title()
848+
self._win.refresh()
849+
return -1, []
850+
818851
elif val[0] == 'radiobrowser':
819852
if char in (curses.KEY_RIGHT, kbkey['l'], kbkey['pause'],
820853
curses.KEY_ENTER, ord('\r'), ord('\n')) or \

0 commit comments

Comments
 (0)