Skip to content

Commit 92c3f1f

Browse files
committed
- fixing SyntaxWarning messages
- RadioBrowser: encoding and info are read from config - MPV _buildStartOpts options rearranged - fixing a crash when pressing "T" in limited mode
1 parent 8de926e commit 92c3f1f

File tree

7 files changed

+48
-30
lines changed

7 files changed

+48
-30
lines changed

pyradio/browser.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,8 @@ class RadioBrowser(PyRadioStationsBrowser):
346346

347347
def __init__(self,
348348
config,
349-
config_encoding,
350349
session=None,
351350
search=None,
352-
pyradio_info=None,
353351
search_return_function=None,
354352
message_function=None,
355353
cannot_delete_function=None):
@@ -372,10 +370,10 @@ def __init__(self,
372370
self._session = session
373371
else:
374372
self._session = requests.Session()
375-
self._pyradio_info = pyradio_info.strip()
373+
self._pyradio_info = self._cnf.user_agent_string
376374
if self._pyradio_info:
377-
self._headers['User-Agent'] = self._pyradio_info.replace(' ', '/')
378-
self._config_encoding = config_encoding
375+
self._headers['User-Agent'] = self._pyradio_info
376+
self._config_encoding = self._cnf.default_encoding
379377
self._message_function = message_function
380378
self._search_return_function = search_return_function
381379
self._cannot_delete_function = cannot_delete_function

pyradio/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def format_list(a_string):
1212
print(a_string.replace(
13-
'[', '\[').replace(']', ']').replace(
13+
r'[', r'\[').replace(']', ']').replace(
1414
'/x,y', '/[green]x[/green],[blue]y[/blue]').replace(
1515
'/x', '/[green]x[/green]').replace(
1616
'[x]', '[[green]x[/green]]').replace(
@@ -96,12 +96,12 @@ def last_reply(self):
9696
server_id = ''
9797
if self._type >= 0:
9898
if self._last_command:
99-
server_id = 'Server found: [green]{}[/green]:[green]{}[/green] {}\n'.format(
99+
server_id = 'Server: [green]{}[/green]:[green]{}[/green] {}\n'.format(
100100
self._host, self._port,
101101
'([blue]headless[/blue])' if self._type == 0 else ''
102102
)
103103
else:
104-
server_id = 'Server found: {}:{} {}\n'.format(
104+
server_id = 'Server: {}:{} {}\n'.format(
105105
self._host, self._port,
106106
'(headless)' if self._type == 0 else ''
107107
)

pyradio/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,6 @@ def current_playlist_index(self):
11851185
def open_browser(self, url, search_return_function, message_function, cannot_delete_function):
11861186
self._online_browser = probeBrowsers(url)(
11871187
self,
1188-
self.default_encoding,
1189-
pyradio_info=self.info,
11901188
search_return_function=search_return_function,
11911189
message_function=message_function,
11921190
cannot_delete_function=cannot_delete_function
@@ -1819,6 +1817,7 @@ def get_pyradio_version(self):
18191817
'''
18201818
ret = None
18211819
self.info = " PyRadio {0} ".format(version)
1820+
self.user_agent_string = r'PyRadio/{}'.format(version)
18221821
''' git_description can be set at build time
18231822
if so, revision will be shown along with the version
18241823
'''

pyradio/config_window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ def __init__(self,
11891189
self._widgets[0]._use_paste_mode = True
11901190
self._widgets[0]._mode_changed = self._show_alternative_modes
11911191
self._widgets[0].set_global_functions(self._global_functions)
1192-
''' enables direct insersion of ? and \ '''
1192+
''' enables direct insersion of ? and \\ '''
11931193
self._widgets[0]._paste_mode = False
11941194
self._line_editor = self._widgets[0]
11951195

pyradio/edit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def show(self, item=None):
557557
self._line_editor[ed].show(self._win, opening=False)
558558

559559
if self._focus == 1:
560-
''' Tip: Press \p before pasting here '''
560+
''' Tip: Press \\p before pasting here '''
561561
self._win.addstr(6, self.maxX - 41, 'Tip: ', curses.color_pair(4))
562562
self._win.addstr('Press ', curses.color_pair(5))
563563
self._win.addstr(r'\p', curses.color_pair(4))
@@ -568,7 +568,7 @@ def show(self, item=None):
568568
self._win.addstr('Group Header', curses.color_pair(4))
569569
self._win.refresh()
570570
elif self._focus == 2:
571-
''' Tip: Press \p before pasting here '''
571+
''' Tip: Press \\p before pasting here '''
572572
self._win.addstr(9, self.maxX - 41, 'Tip: ', curses.color_pair(4))
573573
self._win.addstr('Press ', curses.color_pair(5))
574574
self._win.addstr(r'\p', curses.color_pair(4))

pyradio/player.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,16 +2509,8 @@ def _buildStartOpts(self, streamUrl, playList=False):
25092509
if logger.isEnabledFor(logging.DEBUG):
25102510
logger.debug('--input-ipc-server is not supported.')
25112511
newerMpv = False
2512-
if playList:
2513-
if newerMpv:
2514-
opts = [self.PLAYER_CMD, '--no-video', '--quiet', '--playlist=' + self._url_to_use(streamUrl), '--input-ipc-server=' + self.mpvsocket]
2515-
else:
2516-
opts = [self.PLAYER_CMD, '--no-video', '--quiet', '--playlist=' + self._url_to_use(streamUrl), '--input-unix-socket=' + self.mpvsocket]
2517-
else:
2518-
if newerMpv:
2519-
opts = [self.PLAYER_CMD, '--no-video', '--quiet', self._url_to_use(streamUrl), '--input-ipc-server=' + self.mpvsocket]
2520-
else:
2521-
opts = [self.PLAYER_CMD, '--no-video', '--quiet', self._url_to_use(streamUrl), '--input-unix-socket=' + self.mpvsocket]
2512+
logger.error('\n\nself._cnf.user_agent_string = {}\n\n'.format(self._cnf.user_agent_string))
2513+
opts = [self.PLAYER_CMD, '--no-video', '--quiet']
25222514

25232515
if self._cnf.buffering_data:
25242516
opts.extend(self._cnf.buffering_data)
@@ -2561,6 +2553,27 @@ def _buildStartOpts(self, streamUrl, playList=False):
25612553
if logger.isEnabledFor(logging.DEBUG):
25622554
logger.debug('---=== Starting Recording: "{}" ===---',format(self.recording_filename))
25632555

2556+
# ##################################################################
2557+
# if streamUrl == r'https://player-culturaam.stream.uol.com.br/live/culturaam.m3u8' or \
2558+
# streamUrl == r'http://player-culturaam.stream.uol.com.br/live/culturaam.m3u8':
2559+
# opts.append(r'--http-header-fields="User-Agent: PyRadio,Referer: https://cultura.uol.com.br/aovivo/67_ao-vivo-radio-cultura-brasil.html"')
2560+
# ##################################################################
2561+
2562+
if playList:
2563+
if newerMpv:
2564+
opts.append('--input-ipc-server=' + self.mpvsocket)
2565+
opts.append('--playlist=' + self._url_to_use(streamUrl))
2566+
else:
2567+
opts.append('--input-unix-socket=' + self.mpvsocket)
2568+
opts.append('--playlist=' + self._url_to_use(streamUrl))
2569+
else:
2570+
if newerMpv:
2571+
opts.append('--input-ipc-server=' + self.mpvsocket)
2572+
opts.append(self._url_to_use(streamUrl))
2573+
else:
2574+
opts.append('--input-unix-socket=' + self.mpvsocket)
2575+
opts.append(self._url_to_use(streamUrl))
2576+
25642577
''' check if buffering '''
25652578
self.buffering = self._player_is_buffering(opts, self.buffering_tokens)
25662579
with self.buffering_lock:

pyradio/radio.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,8 +1670,8 @@ def __displayBodyLine(self, lineNum, pad, station, return_line=False):
16701670
''' return empty line '''
16711671
return line
16721672

1673-
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
16741673
try:
1674+
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
16751675
# logger.error('line: "{}"'.format(line))
16761676
self.bodyWin.addstr(lineNum, 0, line, col)
16771677
if column_num > 0:
@@ -4334,10 +4334,13 @@ def _toggle_transparency(
43344334
if self.ws.operation_mode == self.ws.THEME_MODE:
43354335
self._theme_selector.transparent = self._cnf.use_transparency
43364336
logger.error('self._theme_selector.transparent = {}\n=========================='.format(self._theme_selector.transparent))
4337-
self.headWin.refresh()
4338-
self.outerBodyWin.refresh()
4339-
self.bodyWin.refresh()
4340-
self.footerWin.refresh()
4337+
if not self._limited_height_mode and \
4338+
not self._limited_width_mode:
4339+
self.headWin.refresh()
4340+
self.outerBodyWin.refresh()
4341+
self.bodyWin.refresh()
4342+
if self.footerWin:
4343+
self.footerWin.refresh()
43414344
if self._config_win:
43424345
self._config_win._config_options['use_transparency'][1] = self._cnf.use_transparency
43434346
if not changed_from_config_window:
@@ -9196,10 +9199,15 @@ def _exit_browser_config(self):
91969199

91979200
def _can_display_help_msg(self, msg):
91989201
''' len("Press ? for help") = 16 '''
9199-
if msg is None:
9202+
if (not self._limited_height_mode and \
9203+
not self._limited_width_mode) or \
9204+
msg is None:
92009205
ret = False
92019206
else:
9202-
ret = self.outerBodyMaxX - len(msg) - 16 > 10 if msg else True
9207+
if self.outerBodyWin:
9208+
ret = self.outerBodyMaxX - len(msg) - 16 > 10 if msg else True
9209+
else:
9210+
ret = False
92039211
# if logger.isEnabledFor(logging.DEBUG):
92049212
# logger.debug('Display "Press ? for help": {}'.format(ret))
92059213
return ret

0 commit comments

Comments
 (0)