def on_title_read(self, title):
assert threading.current_thread() == threading.main_thread()
if title is None:
return
if title != self._last_title:
self._last_title = title
# TODO: Fade volume gradually
# TODO: Allow user to choose what to do when an advertisement block is detected.
# Ideas for possible options:
# * reduce or mute volume
# * play random audio file from a local directory
# * switch to another radio station
# * repeat part of last song
print("Title changed to %s" % title)
# If the title contains a blacklisted tag, reduce volume
if BlacklistStorage.is_blacklisted(title):
if not self._in_ad_block:
print('Advertisement tag detected.')
if config.block_mode in (config.BlockMode.REDUCE_VOLUME, config.BlockMode.REDUCE_AND_SWITCH):
print('Reducing volume.')
self.volume = config.ad_block_volume
self._in_ad_block = True
self._last_ad_time = time.time()
elif config.block_mode == config.BlockMode.SWITCH_STATION:
self.switch_to_another_station()
else:
if self._in_ad_block:
print('Restoring volume to maximum.')
if config.block_mode in (config.BlockMode.REDUCE_VOLUME, config.BlockMode.REDUCE_AND_SWITCH):
self.volume = config.max_volume
self._in_ad_block = False
self._last_ad_time = None
self._just_switched = False
dispatchers.player.song_changed(title)
评论列表
文章目录