@@ -425,9 +425,9 @@ def __init__(self, pyradio_config,
425
425
record = False ):
426
426
temp_dir = gettempdir ()
427
427
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' ),
431
431
)
432
432
self ._message_system_default_operation_mode = self .ws .MESSAGING_MODE
433
433
self ._request_recording = record
@@ -2256,6 +2256,7 @@ def playSelection(self, restart=False):
2256
2256
self .playing = self ._last_played_station_id
2257
2257
else :
2258
2258
self ._remove_station_images ()
2259
+ self ._cnf .notification_image_file = None
2259
2260
if self ._cnf .enable_notifications and \
2260
2261
self ._cnf .use_station_icon and \
2261
2262
not platform .startswith ('win' ):
@@ -2265,6 +2266,7 @@ def playSelection(self, restart=False):
2265
2266
self .log .write (msg = 'Downloading icon...' )
2266
2267
self ._download_station_image (
2267
2268
self .stations [self .selection ][3 ]['image' ],
2269
+ self .stations [self .selection ][0 ],
2268
2270
lambda : self .stop_update_notification_thread
2269
2271
)
2270
2272
# if self._cnf.browsing_station_service:
@@ -2458,18 +2460,39 @@ def _show_player_is_stopped(self, from_update_thread=False):
2458
2460
help_msg = True , suffix = self ._status_suffix , counter = ''
2459
2461
)
2460
2462
2461
- def _download_station_image (self , url , stop ):
2463
+ def _download_station_image (self , url , station_name , stop ):
2462
2464
threading .Thread (
2463
2465
target = self ._thread_download_station_image ,
2464
- args = (url , stop ),
2466
+ args = (url , station_name , self . _notification_icon , stop ),
2465
2467
).start ()
2466
2468
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
+ ):
2468
2486
if url :
2469
2487
if logger .isEnabledFor (logging .DEBUG ):
2470
2488
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
2473
2496
if stop ():
2474
2497
if logger .isEnabledFor (logging .DEBUG ):
2475
2498
logger .debug ('+++ icon download: asked to stop. Stopping...' )
@@ -2503,6 +2526,7 @@ def _thread_download_station_image(self, url, stop):
2503
2526
self ._remove_station_images ()
2504
2527
if logger .isEnabledFor (logging .DEBUG ):
2505
2528
logger .debug ('+++ icon downloaded...' )
2529
+ update_icon_name_function (file_to_write )
2506
2530
else :
2507
2531
if logger .isEnabledFor (logging .DEBUG ):
2508
2532
logger .debug ('+++ icon downloaded, but already exists...' )
0 commit comments