Skip to content

Commit e44a761

Browse files
committed
fixing a couple of python 2 crashes
1 parent faec2e8 commit e44a761

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Changelog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* RadioBrowser: if limit=0, disable result limit
66
* RadioBrowser: finalized config save / read function
77
* RadioBrowser: Better navigation in the Search Window
8-
* Updating docs
8+
* Fixed a couple of python 2 crashes
9+
* Updated docs
910

1011
2021-08-15
1112
* Version 0.8.9.6 (0.9-beta3)

pyradio/browser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def get_info_string(self, a_station, max_width=60):
504504
''' do this here for python 2
505505
TODO: make the previous statement work on py2
506506
'''
507-
pass
507+
info[n[0]] = self._raw_stations[a_station][n[1]].encode('utf-8', 'replace')
508508
if n[1] == 'bitrate':
509509
info[n[0]] += ' kb/s'
510510

@@ -1446,7 +1446,10 @@ def save_config(self,
14461446
'''
14471447
for n in range(1, len(search_history)):
14481448
asterisk = '*' if n == search_default_history_index else ''
1449-
txt += 'SEARCH_TERM = ' + asterisk + str(search_history[n]) + '\n'
1449+
if PY3:
1450+
txt += 'SEARCH_TERM = ' + asterisk + str(search_history[n]) + '\n'
1451+
else:
1452+
txt += 'SEARCH_TERM = ' + asterisk + str(search_history[n]).replace('{u\'', '{\'').replace('u\'', '\'') + '\n'
14501453

14511454
try:
14521455
with open(self.config_file, 'w') as cfgfile:

pyradio/player.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ def info_dict_to_list(info, fix_highlight, max_width):
120120
for a_title in info.keys():
121121
if len(a_title) > max_len:
122122
max_len = len(a_title)
123-
if version_info < (3, 0):
124-
info[a_title] = info[a_title].encode('utf-8', 'replace')
123+
if version_info < (3, 0) and type(info[a_title]).__name__ != 'str':
124+
try:
125+
info[a_title] = info[a_title].encode('utf-8', 'replace')
126+
except:
127+
info[a_title] = ''
125128
info[a_title] = info[a_title].replace('_','¸')
126129
# logger.error('DE info\n{}\n\n'.format(info))
127130

pyradio/radio.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,10 @@ def _get_stations_ids(self, find):
34193419
for j, a_find in enumerate(find):
34203420
if a_find.strip():
34213421
if logger.isEnabledFor(logging.DEBUG):
3422-
logger.debug('** Looking for {0} station: "{1}"'.format(debug_str[j], a_find))
3422+
try:
3423+
logger.debug('** Looking for {0} station: "{1}"'.format(debug_str[j], a_find))
3424+
except:
3425+
logger.debug('** Looking for {0} station: "{1}"'.format(debug_str[j], a_find.encode('utf-8', 'replace')))
34233426

34243427
for i, a_station in enumerate(self.stations):
34253428
if i_find[j] == -1:
@@ -5117,6 +5120,7 @@ def keypress(self, char):
51175120
# (char == ord('?') or char not in self._chars_to_bypass):
51185121
elif self.ws.operation_mode == self.ws.BROWSER_SEARCH_MODE:
51195122

5123+
''' return from browser search '''
51205124
ret = self._cnf._online_browser.keypress(char)
51215125
if ret == 0:
51225126
''' Ok, search term is valid '''

0 commit comments

Comments
 (0)