Skip to content

Commit d87e9cf

Browse files
committed
- Remote Control Client: hiding "retry: " responses; displaying "Command executed"
- Adding config parameter remove_station_icons, to remove downloaded files on program exit
1 parent 17e573d commit d87e9cf

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

pyradio/client.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,14 @@ def last_reply(self):
106106
'(headless)' if self._type == 0 else ''
107107
)
108108
if self._last_reply:
109-
# out = None
110-
# ss = self._last_reply.splitlines()
111-
# for n in range(0, len(ss)):
112-
# if ss[n] == '':
113-
# out = ss[n+1:]
114-
# break
115-
# if out:
116-
# if self._type == -1:
117-
# return '\n'.join(out)
118-
# else:
119-
# return server_id + '\n' + '\n'.join(out)
120-
return server_id + '\n' + self._last_reply if server_id else self._last_reply
121-
109+
if 'retry: ' in self._last_reply:
110+
self._last_reply = 'Command executed\n'
111+
return server_id + self._last_reply if server_id else self._last_reply
122112
# empty reply
123113
if self._type == -1:
124-
return 'Command executed'
114+
return 'Command executed\n'
125115
else:
126-
return server_id + '\nCommand Executed'
116+
return server_id + 'Command Executed\n'
127117

128118
def _get_files(self):
129119
if self._files is None:

pyradio/config

+10
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ enable_notifications = -1
7878
# Default value: True
7979
use_station_icon = True
8080

81+
# Cached Station Icons Handling
82+
# If use_station_incon is True, stations' icons will be saved under the
83+
# DATA_DIR, in a folder called staions-logos.
84+
# If this option is True (the default), all files under this folder will be
85+
# deleted at program exit. Otherwise, all downloaded logos will remain in the
86+
# folder for future use.
87+
#
88+
# Default value: True
89+
remove_station_icons = True
90+
8191
# Connection timeout
8292
# PyRadio will wait for this number of seconds to get a station/server message
8393
# indicating that playback has actually started. If this does not happen

pyradio/config.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ class PyRadioConfig(PyRadioStations):
12891289
opts['enable_mouse'] = ['Enable mouse support: ', False]
12901290
opts['enable_notifications'] = ['Enable notifications: ', '-1']
12911291
opts['use_station_icon'] = [' Use station icon: ', True]
1292+
opts['remove_station_icons'] = [' Remove cached icons: ', True]
12921293
opts['recording_dir'] = ['Recordings dir: ', '']
12931294
opts['resource_opener'] = ['Resource Opener: ', 'auto']
12941295
opts['conn_title'] = ['Connection Options: ', '']
@@ -1521,6 +1522,15 @@ def use_station_icon(self, val):
15211522
self.opts['use_station_icon'][1] = val
15221523
self.opts['dirty_config'][1] = True
15231524

1525+
@property
1526+
def remove_station_icons(self):
1527+
return self.opts['remove_station_icons'][1]
1528+
1529+
@remove_station_icons.setter
1530+
def remove_station_icons(self, val):
1531+
self.opts['remove_station_icons'][1] = val
1532+
self.opts['dirty_config'][1] = True
1533+
15241534
@property
15251535
def player(self):
15261536
return self.opts['player'][1]
@@ -2094,15 +2104,16 @@ def re_read_config(self):
20942104
self.create_stations_images_dir()
20952105

20962106
def create_stations_images_dir(self, to_console=False):
2097-
if int(self.enable_notifications) >= 0:
2107+
if int(self.enable_notifications) >= 0 and \
2108+
self.use_station_icon and \
2109+
not sys.platform.startswith('win'):
20982110
try:
20992111
makedirs(self.stations_images_dir, exist_ok = True)
21002112
except:
21012113
if to_console:
21022114
print('[red]Error[/red]: Cannot create fir: "{}"\n'.format(self.stations_images_dir))
21032115
return False
2104-
2105-
2116+
# move old dir if necessary
21062117
src_dir = path.join(
21072118
getenv(
21082119
'XDG_CONFIG_HOME',
@@ -2236,6 +2247,11 @@ def _read_config(self, distro_config=False):
22362247
self.opts['use_station_icon'][1] = False
22372248
else:
22382249
self.opts['use_station_icon'][1] = True
2250+
elif sp[0] == 'remove_station_icons':
2251+
if sp[1].lower() == 'false':
2252+
self.opts['remove_station_icons'][1] = False
2253+
else:
2254+
self.opts['remove_station_icons'][1] = True
22392255
elif sp[0] == 'confirm_station_deletion':
22402256
if sp[1].lower() == 'false':
22412257
self.opts['confirm_station_deletion'][1] = False

pyradio/config_window.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class PyRadioConfigWindow(object):
6969
_help_text.append(['If this options is enabled, the mouse can be used to scroll the playlist, start, stop and mute the player, adjust its volume etc.', '|', 'Mouse support is highly terminal dependent, that\'s why it is disabled by default.', '|', 'Default value: False'])
7070
_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'])
7171
_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'])
72+
_help_text.append(['Notice: Not applicable on Windows!', '|', 'If the previous option is enabled, Stations Icons will be cached.', '|', 'If this option is set to True, all icons will be deleted at program exit.', '|', 'If set to False, the icons will be available for future use.', '|', 'Default value: True'])
7273
_help_text.append([ 'This is the folder where recorded files will be saved', '|', 'Tip: When you open the window "h" will display HTML help about this parameter (not in Line Editor).', '|', 'Default value: "pyradio-recordings" in home dir' ])
7374
_help_text.append(['This is a Linux (et al) only parameter. It has no effect on Windows or MacOS.', '|',
7475
'A Resource Opener is a program used to open files passed to it as arguments. PyRadio will use it to open either directories or HTML files.', '|',
@@ -985,7 +986,8 @@ def keypress(self, char):
985986
sel == 'auto_save_playlist' or \
986987
sel == 'force_http' or \
987988
sel == 'remote_control_server_auto_start' or \
988-
sel == 'use_station_icon':
989+
sel == 'use_station_icon' or \
990+
sel == 'remove_station_icons':
989991
self._config_options[sel][1] = not self._config_options[sel][1]
990992
# # if sel == 'open_last_playlist':
991993
# # if self._config_options[sel][1]:

pyradio/radio.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,7 @@ def ctrl_c_handler(self, signum, frame, save_playlist=True):
20912091
self._remote_control_server = None
20922092
self.restore_colors()
20932093
self._remove_station_images()
2094+
self._remove_icons()
20942095

20952096
def _wait_for_threads(self):
20962097
self.log._stop_desktop_notification_thread = True
@@ -2231,6 +2232,17 @@ def _remove_station_images(self):
22312232
except:
22322233
pass
22332234

2235+
def _remove_icons(self):
2236+
''' remove the stations-logos directory '''
2237+
if int(self._cnf.enable_notifications) >= 0 and \
2238+
self._cnf.use_station_icon and \
2239+
self._cnf.remove_station_icons and \
2240+
not sys.platform.startswith('win'):
2241+
if self._cnf.stations_images_dir:
2242+
if path.exists(self._cnf.stations_images_dir):
2243+
from shutil import rmtree
2244+
rmtree(self._cnf.stations_images_dir, ignore_errors=True)
2245+
22342246
def playSelection(self, restart=False):
22352247
''' start playback using current selection
22362248
if restart = True, start the station that has
@@ -2475,7 +2487,6 @@ def _notification_icon(self, a_name):
24752487
if logger.isEnabledFor(logging.DEBUG):
24762488
logger.debug('Notification image is invalid; reverting to default...')
24772489

2478-
24792490
def _thread_download_station_image(
24802491
self,
24812492
url,
@@ -7017,6 +7028,8 @@ def keypress(self, char):
70177028
if logger.isEnabledFor(logging.DEBUG):
70187029
logger.debug('Asked to move recordings but source and target are the same\nsource: {0}\ntarget: {1}'.format(self._cnf.xdg._old_dirs[self._cnf.xdg.RECORDINGS], self._cnf.xdg._new_dirs[self._cnf.xdg.RECORDINGS]))
70197030

7031+
self._cnf.create_stations_images_dir()
7032+
70207033
elif ret == 1:
70217034
''' config not modified '''
70227035
self._show_notification_with_delay(

0 commit comments

Comments
 (0)