@@ -425,9 +425,9 @@ def __init__(self, pyradio_config,
425425 record = False ):
426426 temp_dir = gettempdir ()
427427 self ._station_images = (
428- join (temp_dir , 'station.jpg' ),
429- join (temp_dir , 'station.png' ),
430- join (temp_dir , 'station-icon.raw' ),
428+ join (pyradio_config . stations_images_dir , 'station.jpg' ),
429+ join (pyradio_config . stations_images_dir , 'station.png' ),
430+ join (pyradio_config . stations_images_dir , 'station-icon.raw' ),
431431 )
432432 self ._message_system_default_operation_mode = self .ws .MESSAGING_MODE
433433 self ._request_recording = record
@@ -2256,6 +2256,7 @@ def playSelection(self, restart=False):
22562256 self .playing = self ._last_played_station_id
22572257 else :
22582258 self ._remove_station_images ()
2259+ self ._cnf .notification_image_file = None
22592260 if self ._cnf .enable_notifications and \
22602261 self ._cnf .use_station_icon and \
22612262 not platform .startswith ('win' ):
@@ -2265,6 +2266,7 @@ def playSelection(self, restart=False):
22652266 self .log .write (msg = 'Downloading icon...' )
22662267 self ._download_station_image (
22672268 self .stations [self .selection ][3 ]['image' ],
2269+ self .stations [self .selection ][0 ],
22682270 lambda : self .stop_update_notification_thread
22692271 )
22702272 # if self._cnf.browsing_station_service:
@@ -2458,18 +2460,39 @@ def _show_player_is_stopped(self, from_update_thread=False):
24582460 help_msg = True , suffix = self ._status_suffix , counter = ''
24592461 )
24602462
2461- def _download_station_image (self , url , stop ):
2463+ def _download_station_image (self , url , station_name , stop ):
24622464 threading .Thread (
24632465 target = self ._thread_download_station_image ,
2464- args = (url , stop ),
2466+ args = (url , station_name , self . _notification_icon , stop ),
24652467 ).start ()
24662468
2467- def _thread_download_station_image (self , url , stop ):
2469+ def _notification_icon (self , a_name ):
2470+ if path .exists (a_name ):
2471+ self ._cnf .notification_image_file = a_name
2472+ if logger .isEnabledFor (logging .DEBUG ):
2473+ logger .debug ('Notification image: "{}"' .format (self ._cnf .notification_image_file ))
2474+ else :
2475+ if logger .isEnabledFor (logging .DEBUG ):
2476+ logger .debug ('Notification image is invalid; reverting to default...' )
2477+
2478+
2479+ def _thread_download_station_image (
2480+ self ,
2481+ url ,
2482+ station_name ,
2483+ update_icon_name_function ,
2484+ stop
2485+ ):
24682486 if url :
24692487 if logger .isEnabledFor (logging .DEBUG ):
24702488 logger .debug ('+++ downloading icon...' )
2471- logger .error ('\n \n {}\n \n ' .format (self ._station_images ))
2472- file_to_write = self ._station_images [0 ] if url .endswith ('.jpg' ) else self ._station_images [1 ]
2489+ template_image = self ._station_images [0 ] if url .endswith ('.jpg' ) else self ._station_images [1 ]
2490+ file_to_write = template_image .replace ('station.' , station_name .replace (' ' , '_' ) + '.' )
2491+ if path .exists (file_to_write ):
2492+ if logger .isEnabledFor (logging .DEBUG ):
2493+ logger .debug ('+++ icon download: aleready downloaded...' )
2494+ update_icon_name_function (file_to_write )
2495+ return
24732496 if stop ():
24742497 if logger .isEnabledFor (logging .DEBUG ):
24752498 logger .debug ('+++ icon download: asked to stop. Stopping...' )
@@ -2503,6 +2526,7 @@ def _thread_download_station_image(self, url, stop):
25032526 self ._remove_station_images ()
25042527 if logger .isEnabledFor (logging .DEBUG ):
25052528 logger .debug ('+++ icon downloaded...' )
2529+ update_icon_name_function (file_to_write )
25062530 else :
25072531 if logger .isEnabledFor (logging .DEBUG ):
25082532 logger .debug ('+++ icon downloaded, but already exists...' )
0 commit comments