Skip to content

Commit 09bc1d9

Browse files
committed
-ep parameter will be active for the session only
-ep "vlc:profile:...." will display error message and exit
1 parent 359c69d commit 09bc1d9

File tree

7 files changed

+67
-57
lines changed

7 files changed

+67
-57
lines changed

README.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ <h2 id="command-line-options">Command line options <span style="padding-left: 10
9797
manager.
9898
-ep EXTRA_PLAYER_PARAMETERS, --extra-player_parameters EXTRA_PLAYER_PARAMETERS
9999
Provide extra player parameters as a string. The
100-
string&#39;s format is [player_name:parameters].
101-
player_name can be &#39;mpv&#39;, &#39;mplayer&#39; or &#39;vlc&#39;.
102-
Alternative format to pass a profile:
103-
[player_name:profile:profile_name]. In this case, the
104-
profile_name must be a valid profile defined in the
105-
player&#39;s config file (not for VLC).
100+
parameter is saved in the configuration file and is
101+
activated for the current session. The string&#39;s format
102+
is [player_name:parameters]. player_name can be &#39;mpv&#39;,
103+
&#39;mplayer&#39; or &#39;vlc&#39;. Alternative format to pass a
104+
profile: [player_name:profile:profile_name]. In this
105+
case, the profile_name must be a valid profile defined
106+
in the player&#39;s config file (not for VLC).
106107
-ap ACTIVE_PLAYER_PARAM_ID, --active-player-param-id ACTIVE_PLAYER_PARAM_ID
107108
Specify the extra player parameter set to be used with
108109
the default player. ACTIVE_PLAYER_PARAM_ID is 1-11

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ optional arguments:
7878
manager.
7979
-ep EXTRA_PLAYER_PARAMETERS, --extra-player_parameters EXTRA_PLAYER_PARAMETERS
8080
Provide extra player parameters as a string. The
81-
string's format is [player_name:parameters].
82-
player_name can be 'mpv', 'mplayer' or 'vlc'.
83-
Alternative format to pass a profile:
84-
[player_name:profile:profile_name]. In this case, the
85-
profile_name must be a valid profile defined in the
86-
player's config file (not for VLC).
81+
parameter is saved in the configuration file and is
82+
activated for the current session. The string's format
83+
is [player_name:parameters]. player_name can be 'mpv',
84+
'mplayer' or 'vlc'. Alternative format to pass a
85+
profile: [player_name:profile:profile_name]. In this
86+
case, the profile_name must be a valid profile defined
87+
in the player's config file (not for VLC).
8788
-ap ACTIVE_PLAYER_PARAM_ID, --active-player-param-id ACTIVE_PLAYER_PARAM_ID
8889
Specify the extra player parameter set to be used with
8990
the default player. ACTIVE_PLAYER_PARAM_ID is 1-11

pyradio/browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def search(self, data):
330330
r.raise_for_status()
331331
logger.error(r.text)
332332
self._raw_stations = self._extract_data(json.loads(r.text))
333-
logger.error('DE {}'.format(self._raw_stations))
333+
# logger.error('DE {}'.format(self._raw_stations))
334334
except requests.exceptions.RequestException as e:
335335
if logger.isEnabledFor(logging.ERROR):
336336
logger.error(e)

pyradio/config.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ class PyRadioConfig(PyRadioStations):
10041004
PROGRAM_UPDATE = None
10051005

10061006
def __init__(self):
1007-
self.backup_player_params = [[]]
1007+
self.backup_player_params = None
10081008
self._profile_name = 'pyradio'
10091009
self.player = ''
10101010
self.requested_player = ''
@@ -1062,36 +1062,46 @@ def command_line_params(self):
10621062
def command_line_params(self, val):
10631063
self.command_line_params_not_ready = None
10641064
if val:
1065+
if val.startswith('vlc:profile'):
1066+
if logger.isEnabledFor(logging.ERROR):
1067+
logger.error('VLC does not support profiles')
1068+
self.init_backup_player_params()
1069+
return
1070+
10651071
if self.PLAYER_NAME:
10661072
parts = val.replace('\'', '').replace('"', '').split(':')
10671073
if len(parts) > 1 and parts[0] in SUPPORTED_PLAYERS:
1068-
if self.PLAYER_NAME == 'vlc' and parts[1] == 'profile':
1069-
if logger.isEnabledFor(logging.DEBUG):
1070-
logger.debug('VLC does not support profiles')
1074+
''' add to params '''
1075+
# logger.error('DE \n\n{0}\n{1}'.format(self.saved_params, self.params))
1076+
to_add = ':'.join(parts[1:])
1077+
if to_add in self.params[parts[0]]:
1078+
added_id = self.params[parts[0]].index(to_add)
10711079
else:
1072-
''' add to params '''
1073-
logger.error('DE \n\n{0}\n{1}'.format(self.saved_params, self.params))
1074-
self.params[parts[0]].append(':'.join(parts[1:]))
1075-
''' change first params item to point to this new item '''
1076-
self.params[parts[0]][0] = len(self.params[parts[0]]) - 1
1077-
logger.error('DE \n{0}\n{1}\n\n'.format(self.saved_params, self.params))
1078-
1079-
self.dirty_config = True
1080-
if logger.isEnabledFor(logging.DEBUG):
1081-
logger.debug(self.params)
1082-
print(self.params)
1083-
1084-
if len(parts) > 2:
1085-
if parts[1] == 'profile':
1086-
''' Custom profile for player '''
1087-
self.command_line_params_not_ready = val
1088-
self.set_profile_from_command_line()
1080+
self.params[parts[0]].append(to_add)
1081+
added_id = len(self.params[parts[0]]) - 1
1082+
# logger.error('DE \n{0}\n{1}\n\n'.format(self.saved_params, self.params))
1083+
1084+
self.dirty_config = True
1085+
1086+
if len(parts) > 2:
1087+
if parts[1] == 'profile':
1088+
''' Custom profile for player '''
1089+
self.command_line_params_not_ready = val
1090+
self.set_profile_from_command_line()
1091+
1092+
''' change second backup params item to point to this new item
1093+
if the parameter belongs to the player pyradio currently uses
1094+
'''
1095+
if parts[0] == self.PLAYER_NAME:
1096+
self.init_backup_player_params()
1097+
self.backup_player_params[1][0] = added_id
1098+
if logger.isEnabledFor(logging.DEBUG):
1099+
logger.debug('Setting active parameters: "{}"'.format(self.backup_player_params[1]))
10891100
else:
10901101
''' Since we don't know which player we use yet
10911102
we do not know if this profile has to be
10921103
applied. So set evaluate for later...
10931104
'''
1094-
print('Will check command line parameters later...({})'.format(val))
10951105
self.command_line_params_not_ready = val
10961106

10971107
@property
@@ -1521,7 +1531,6 @@ def save_config(self):
15211531
0: Config saved successfully
15221532
1: Config not saved (not modified)
15231533
TODO: 2: Config not saved (session locked) '''
1524-
logger.error('DE buckup_params = {}'.format(self.backup_player_params))
15251534
if self.locked:
15261535
if logger.isEnabledFor(logging.INFO):
15271536
logger.info('Config not saved (session locked)')
@@ -1720,8 +1729,6 @@ def save_config(self):
17201729
logger.info('Config saved')
17211730
self.dirty_config = False
17221731
self.params_changed = False
1723-
# Do not touch the active value
1724-
# self.init_backup_player_params()
17251732
return 0
17261733

17271734
def read_playlist_file(self, stationFile='', is_register=False):

pyradio/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def shell():
8181
parser.add_argument('-ocd', '--open-config-dir', action='store_true',
8282
help='Open config directory [CONFIG DIR] with default file manager.')
8383
parser.add_argument('-ep', '--extra-player_parameters', default=None,
84-
help="Provide extra player parameters as a string. The string\'s format is [player_name:parameters]. player_name can be 'mpv', 'mplayer' or 'vlc'. Alternative format to pass a profile: [player_name:profile:profile_name]. In this case, the profile_name must be a valid profile defined in the player\'s config file (not for VLC).")
84+
help="Provide extra player parameters as a string. The parameter is saved in the configuration file and is activated for the current session. The string\'s format is [player_name:parameters]. player_name can be 'mpv', 'mplayer' or 'vlc'. Alternative format to pass a profile: [player_name:profile:profile_name]. In this case, the profile_name must be a valid profile defined in the player\'s config file (not for VLC).")
8585
parser.add_argument('-ap', '--active-player-param-id', default=0, help='Specify the extra player parameter set to be used with the default player. ACTIVE_PLAYER_PARAM_ID is 1-11 (refer to the output of the -lp option)')
8686
parser.add_argument('-lp', '--list-player-parameters', default=None,
8787
action='store_true',
@@ -140,11 +140,21 @@ def shell():
140140
print('')
141141
sys.exit()
142142

143-
144143
''' extra player parameters '''
145144
if args.extra_player_parameters:
146145
if ':' in args.extra_player_parameters:
147-
pyradio_config.command_line_params = args.extra_player_parameters
146+
if pyradio_config.locked:
147+
print('Error: This session is locked!')
148+
print(' Please exist any other instances of the program')
149+
print(' that are currently running and try again.')
150+
sys.exit(1)
151+
else:
152+
if args.extra_player_parameters.startswith('vlc:profile'):
153+
print('Error in parameter: "-ep".')
154+
print(' VLC does not supports profiles\n')
155+
sys.exit()
156+
else:
157+
pyradio_config.command_line_params = args.extra_player_parameters
148158
else:
149159
print('Error in parameter: "-ep".')
150160
print(' Parameter format: "player_name:parameters"')

pyradio/player.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,13 @@ def __init__(self,
190190

191191
self.config_files = []
192192
self._get_all_config_files()
193-
if self._cnf.command_line_params_not_ready is not None:
194-
self._cnf.command_line_params = self._cnf.command_line_params_not_ready
195-
if logger.isEnabledFor(logging.DEBUG):
196-
logger.debug('Setting command line parameters to: "{0}" <- "{1}"'.format(self._cnf.command_line_params, self._cnf.command_line_params_not_ready))
197-
198193
#if self.WIN and self.PLAYER_NAME == 'vlc':
199194
if platform == 'win32':
200195
''' delete old vlc files (vlc_log.*) '''
201196
from .del_vlc_log import RemoveWinVlcLogFiles
202197
threading.Thread(target=RemoveWinVlcLogFiles(self.config_dir)).start()
203198

204199
def _get_all_config_files(self):
205-
206200
''' MPV config files '''
207201
config_files = []
208202
config_files = [expanduser("~") + "/.config/mpv/mpv.conf"]

pyradio/radio.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -509,18 +509,17 @@ def setup(self, stdscr):
509509
self.playbackTimeoutCounter,
510510
self.connectionFailed,
511511
self._show_station_info_from_thread)
512-
self._cnf.init_backup_player_params()
513-
514-
''' activate user specified player parameter set '''
515-
if self._cnf.user_param_id > 0:
516-
if self.set_param_set_by_id(self._cnf.user_param_id):
517-
self._cnf.user_param_id = 0
518-
else:
519-
self._cnf.user_param_id = -1
520512
except:
521513
''' no player '''
522514
self.ws.operation_mode = self.ws.NO_PLAYER_ERROR_MODE
523515

516+
if self.ws.operation_mode != self.ws.NO_PLAYER_ERROR_MODE:
517+
if self._cnf.command_line_params_not_ready is not None:
518+
self._cnf.command_line_params = self._cnf.command_line_params_not_ready
519+
else:
520+
if self._cnf.backup_player_params is None:
521+
self._cnf.init_backup_player_params()
522+
524523
self.stdscr.nodelay(0)
525524
self.setupAndDrawScreen(init_from_setup=True)
526525

@@ -4190,8 +4189,6 @@ def keypress(self, char):
41904189
self.player.threadUpdateTitle()
41914190
else:
41924191
self.log.write(msg=msg[1], help_msg=True, suffix=self._status_suffix)
4193-
# Do not touch the active value
4194-
# self._cnf.init_backup_player_params()
41954192
self._old_config_encoding = self._cnf.opts['default_encoding'][1]
41964193
# Do not update the active force_http
41974194
# self.player.force_http = self._cnf.opts['force_http'][1]

0 commit comments

Comments
 (0)