Skip to content

Commit

Permalink
- titles log: fixing a bug that would disallow writing
Browse files Browse the repository at this point in the history
  the station name to the log
- adding icon station detection for mplayer (critival disabled)
  • Loading branch information
s-n-g committed Jan 5, 2025
1 parent 32131bc commit 6f82bd1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
59 changes: 46 additions & 13 deletions pyradio/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def __init__(self, config, get_web_song_title):
self._x_start = 1
self._stop_thread = False
self.timer = None
self._started_station_name = None

def __del__(self):
self._stop_desktop_notification_thread = True
Expand Down Expand Up @@ -837,7 +838,7 @@ def _get_desktop_notification_data(self, msg):
return d_title, d_msg

def _write_title_to_log(self, msg=None, force=False):
# logger.error('msg = "{}"'.format(msg))
# logger.error('\n\nmsg = "{}"'.format(msg))
if msg is None:
d_msg = None
else:
Expand All @@ -852,26 +853,56 @@ def _write_title_to_log(self, msg=None, force=False):
logger.critical('Error writing LIKED title...')
else:
if d_msg:
if d_msg.startswith('Initialization: '):
self._started_station_name = d_msg[16:]
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Early station name (initialization): "{}"'.format(self._started_station_name))
if d_msg.startswith('Station: ') and ' - Opening connection' in d_msg:
self._started_station_name = d_msg[9:].split(' - Opening connection')[0]
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Early station name (station): "{}"'.format(self._started_station_name))

if d_msg.startswith('Title: '):
if logger.isEnabledFor(logging.CRITICAL):
''' print Early station name '''
if self._started_station_name is not None:
try:
if force or d_msg not in self._cnf._old_log_title:
try:
logger.critical(d_msg.replace('Title: ', ' '))
except:
logger.critical('Error writing title...')
self._cnf._old_log_title = d_msg
try:
logger.critical('>>> Station: ' + self._started_station_name)
self._started_station_name = None
except:
logger.critical('>>> Error writing station name...')
# self._cnf._old_log_title = d_msg
except UnicodeDecodeError:
''' try to handle it for python2 '''
try:
if force or d_msg.decode('utf-8', 'replace') not in self._cnf._old_log_title.decode('utf-8', 'replace'):
try:
logger.critical(d_msg.replace('Title: ', ' '))
logger.critical('>>> Station: ' + self._started_station_name.decode('utf-8', 'replace'))
self._started_station_name = None
except:
logger.critical('Error writing title...')
logger.critical('>>> Error writing station name...')
self._cnf._old_log_title = d_msg
except:
logger.critical('>>> Error writing station name...')

try:
if force or d_msg not in self._cnf._old_log_title:
try:
logger.critical(d_msg.replace('Title: ', ' '))
except:
logger.critical('Error writing title...')
self._cnf._old_log_title = d_msg
except UnicodeDecodeError:
''' try to handle it for python2 '''
try:
if force or d_msg.decode('utf-8', 'replace') not in self._cnf._old_log_title.decode('utf-8', 'replace'):
try:
logger.critical(d_msg.replace('Title: ', ' '))
except:
logger.critical('Error writing title...')
self._cnf._old_log_title = d_msg
except:
logger.critical('Error writing title...')
self._cnf._current_log_title = d_msg
elif d_msg.startswith('Playing: ') or \
d_msg.startswith('Buffering: '):
Expand All @@ -885,19 +916,21 @@ def _write_title_to_log(self, msg=None, force=False):
try:
logger.critical(d_msg.replace(tok, '>>> Station: '))
except:
logger.critical('Error writing station name...')
logger.critical('>>> Error writing station name...')
self._cnf._old_log_station = d_msg
self._started_station_name = None
except UnicodeDecodeError:
''' try to handle it for python2 '''
try:
if force or d_msg.decode('utf-8', 'replace') not in self._cnf._old_log_title.decode('utf-8', 'replace'):
try:
logger.critical(d_msg.replace(tok, '>>> Station: '))
except:
logger.critical('Error writing station name...')
logger.critical('>>> Error writing station name...')
self._cnf._old_log_station = d_msg
self._started_station_name = None
except:
logger.critical('Error writing station name...')
logger.critical('>>> Error writing station name...')
self._cnf._current_log_station = d_msg

def write_start_log_station_and_title(self):
Expand Down
20 changes: 19 additions & 1 deletion pyradio/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def updateStatus(self, *args):
subsystemOut = subsystemOutRaw.decode('utf-8', 'replace')
if subsystemOut == '':
break
# logger.error('DE subsystemOut = "{0}"'.format(subsystemOut))
logger.error('DE subsystemOut = "{0}"'.format(subsystemOut))
with recording_lock:
tmp = self._is_accepted_input(subsystemOut)
if not tmp:
Expand Down Expand Up @@ -3119,6 +3119,24 @@ def _format_title_string(self, title_string):
ret_string = tmp[:tmp.find("';")]
else:
ret_string = title_string

if logger.isEnabledFor(logging.DEBUG):
''' detect icon url in StreamUrl '''
if 'StreamUrl=' in title_string:
splitted = title_string.split(';')
logger.error(title_string.split(';'))
for i in (-1, -2):
if 'StreamUrl=' in splitted[i]:
icon_url = splitted[i].replace('StreamUrl=', '').replace("'", "")
logger.error(f'{icon_url = }')
if icon_url.endswith('.jpg') or icon_url.endswith('.png'):
self._detected_icon_url = icon_url
logger.error('found!!!')
# logger.critical(' icon: {}'.format(self._detected_icon_url))
break
else:
self._detected_icon_url = None

if '"artist":"' in ret_string:
''' work on format:
ICY Info: START_SONG='{"artist":"Clelia Cafiero","title":"M. Mussorgsky-Quadri di un'esposizione"}';
Expand Down

0 comments on commit 6f82bd1

Please sign in to comment.