Skip to content

Commit 77d7a99

Browse files
committed
adding mplayer_save_br config option
1 parent 862d018 commit 77d7a99

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

pyradio/config

+13
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ force_http = False
151151
# Default value = 0
152152
buffering = 0
153153

154+
# MPlayer auto update bitrate
155+
# This option is only relevant if MPlayer is installed.
156+
# In this case, if the station's bitrate is different to 128kbps,
157+
# the station will be updated and the playlist will be silently saved.
158+
#
159+
# This is because MPlayer buffering uses KB instead of seconds (as
160+
# MPV and VLC do). Since buffering (the previous option) is expressed
161+
# in seconds, having the station's real bitrate is essential in
162+
# order to calculate the correct value (seconds to KB).
163+
#
164+
# Default value: False
165+
mplayer_save_br = False
166+
154167
# Default theme
155168
# Hard coded themes:
156169
# dark (default) (8 colors)

pyradio/config.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ class PyRadioConfig(PyRadioStations):
13851385
opts['connection_timeout'] = ['Connection timeout: ', '10']
13861386
opts['force_http'] = ['Force http connections: ', False]
13871387
opts['buffering'] = ['Buffering (seconds): ', '20']
1388+
opts['mplayer_save_br'] = [' MPlayer auto save br: ', False]
13881389
opts['notification'] = ['Notifications', '']
13891390
opts['enable_notifications'] = ['Enable notifications: ', '-1']
13901391
opts['use_station_icon'] = [' Use station icon: ', True]
@@ -1541,6 +1542,15 @@ def __init__(self, user_config_dir=None, headless=False):
15411542

15421543
self._read_notification_command()
15431544

1545+
@property
1546+
def mplayer_save_br(self):
1547+
return self.opts['mplayer_save_br'][1]
1548+
1549+
@mplayer_save_br.setter
1550+
def mplayer_save_br(self, val):
1551+
self.opts['mplayer_save_br'][1] = val
1552+
self.opts['dirty_config'][1] = True
1553+
15441554
@property
15451555
def buffering(self):
15461556
return self.opts['buffering'][1]
@@ -2369,7 +2379,12 @@ def _read_config(self, distro_config=False):
23692379
return -2
23702380
for i in range(len(sp)):
23712381
sp[i] = sp[i].strip()
2372-
if sp[0] == 'show_no_themes_message':
2382+
if sp[0] == 'mplayer_save_br':
2383+
self.mplayer_save_br = True
2384+
st = sp[1].strip()
2385+
if st.lower() == 'false':
2386+
self.mplayer_save_br = False
2387+
elif sp[0] == 'show_no_themes_message':
23732388
self.show_no_themes_message = True
23742389
st = sp[1].strip()
23752390
if st.lower() == 'false':
@@ -4396,8 +4411,11 @@ def add(self, an_item):
43964411
0 : Item added
43974412
1 : Item already in favorites
43984413
'''
4414+
if an_item[0] == '' or \
4415+
an_item[1] == '':
4416+
return -1, '___Station is invalid!___'
4417+
43994418
items = self._read_csv()
4400-
url = an_item[1]
44014419
updated = False
44024420
write_it = True
44034421

@@ -4407,19 +4425,11 @@ def add(self, an_item):
44074425
while this_item[-1] == '':
44084426
this_item.pop()
44094427

4410-
for i, item in enumerate(this_item):
4411-
if item is None:
4412-
if i in range(0, 2):
4413-
return -1, '___Station is invalid!___'
4414-
this_item[i] = ''
4415-
if this_item[0] == '' or \
4416-
this_item[1] == '':
4417-
return -1, '___Station is invalid!___'
44184428
if isinstance(this_item[-1], dict):
44194429
this_item[-1] = this_item[-1]['image']
44204430
msg = None
44214431
for i, item in enumerate(items):
4422-
if item[1] == url:
4432+
if item[1] == this_item[1]:
44234433
if item == this_item:
44244434
return 1, '___Already in favorites!___'
44254435
items[i] = this_item
@@ -4434,15 +4444,6 @@ def add(self, an_item):
44344444
return ret[0], msg if msg else ret[1]
44354445
return 1, '___Already in favorites!___'
44364446

4437-
# def remove(self, an_item):
4438-
# items = self._read_csv()
4439-
# name = an_item[0]
4440-
# url = an_item[1]
4441-
# new_items = [item for item in items if item[0] != name and item[1] != url]
4442-
4443-
# if len(new_items) != len(items):
4444-
# self._write_csv(new_items)
4445-
44464447
def _read_csv(self):
44474448
items = []
44484449
try:

pyradio/config_window.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class PyRadioConfigWindow():
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'])
8888
_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'])
89+
_help_text.append(['This option is only relevant if MPlayer is installed.', '|', "In this case, if the station's bitrate is different to 128kbps, the station will be updated and the playlist will be silently saved.", '|', "This is because MPlayer buffering uses KB instead of seconds (as MPV and VLC do). Since buffering (the previous option) is expressed in seconds, having the station's real bitrate is essential in order to calculate the correct value (seconds to KB).", '|', 'Default value: False'])
8990
_help_text.append(None)
9091
_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'])
9192
_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'])
@@ -765,6 +766,7 @@ def keypress(self, char):
765766
'calculated_color_factor',
766767
'time_format',
767768
'buffering',
769+
'mplayer_save_br',
768770
) and char in (
769771
curses.KEY_LEFT,
770772
curses.KEY_RIGHT,
@@ -1089,7 +1091,8 @@ def keypress(self, char):
10891091
sel == 'enable_clock' or \
10901092
sel == 'wheel_adjusts_volume' or \
10911093
sel == 'log_titles' or \
1092-
sel == 'remove_station_icons':
1094+
sel == 'remove_station_icons' or \
1095+
sel == 'mplayer_save_br':
10931096
self._config_options[sel][1] = not self._config_options[sel][1]
10941097
# # if sel == 'open_last_playlist':
10951098
# # if self._config_options[sel][1]:

pyradio/radio.py

+4
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,10 @@ def _update_config_buffering_data(self, reset=True):
10701070
x = None
10711071

10721072
def _update_bitrate(self, bitrate):
1073+
if not self._cnf.mplayer_save_br:
1074+
if logger.isEnabledFor(logging.DEBUG):
1075+
logger.debug('not updating bitrate, mplayer_save_br = False')
1076+
return
10731077
if self.playing > -1:
10741078
if self._last_played_station == self.stations[self.playing]:
10751079
# make sure mplayer is installed

0 commit comments

Comments
 (0)