More function for config value core.restore_state
- New values for core.restore_state : "volume", "last" - Update changelog - Adjust logger output
This commit is contained in:
parent
e56c39ee78
commit
6746dd0196
@ -16,6 +16,9 @@ Core API
|
||||
- Start ``tlid`` counting at 1 instead of 0 to keep in sync with MPD's
|
||||
``songid``.
|
||||
|
||||
- Persist state between runs. The amount of data to persist can be
|
||||
controlled by config value :confval:`core/restore_state`
|
||||
|
||||
Local backend
|
||||
--------------
|
||||
|
||||
|
||||
@ -118,8 +118,11 @@ Core configuration
|
||||
Allowed values:
|
||||
|
||||
- ``off``: restore nothing
|
||||
- ``volume``: restore volume
|
||||
- ``load``: restore settings, volume and play queue
|
||||
- ``play``: restore settings, volume, play queue and start playback
|
||||
- ``last``: like ``load``, additional start playback if last state was
|
||||
'playing'
|
||||
- ``play``: like ``load``, additional start playback
|
||||
|
||||
Audio configuration
|
||||
-------------------
|
||||
|
||||
@ -143,10 +143,15 @@ class Core(
|
||||
amount = self._config['core']['restore_state']
|
||||
if not amount or 'off' == amount:
|
||||
pass
|
||||
elif 'volume' == amount:
|
||||
coverage = ['volume']
|
||||
elif 'load' == amount:
|
||||
coverage = ['tracklist', 'mode', 'volume', 'history']
|
||||
elif 'last' == amount:
|
||||
coverage = ['tracklist', 'mode', 'play-last', 'volume',
|
||||
'history']
|
||||
elif 'play' == amount:
|
||||
coverage = ['tracklist', 'mode', 'autoplay', 'volume',
|
||||
coverage = ['tracklist', 'mode', 'play-always', 'volume',
|
||||
'history']
|
||||
else:
|
||||
logger.warn('Unknown value for config '
|
||||
@ -175,14 +180,13 @@ class Core(
|
||||
:param name: a name (for later use with :meth:`load_state`)
|
||||
:type name: str
|
||||
"""
|
||||
logger.info('Save state: "%s"', name)
|
||||
if not name:
|
||||
raise TypeError('missing file name')
|
||||
|
||||
file_name = os.path.join(
|
||||
self._config['core']['data_dir'], name)
|
||||
file_name += '.state'
|
||||
logger.info('Save state to "%s"', file_name)
|
||||
logger.info('Save state to %s', file_name)
|
||||
|
||||
data = {}
|
||||
data['tracklist'] = self.tracklist._export_state()
|
||||
@ -190,6 +194,7 @@ class Core(
|
||||
data['playback'] = self.playback._export_state()
|
||||
data['mixer'] = self.mixer._export_state()
|
||||
storage.save(file_name, data)
|
||||
logger.debug('Save state done')
|
||||
|
||||
def load_state(self, name, coverage):
|
||||
"""
|
||||
@ -210,13 +215,13 @@ class Core(
|
||||
:param coverage: amount of data to restore
|
||||
:type coverage: list of string (see above)
|
||||
"""
|
||||
logger.info('Load state: "%s"', name)
|
||||
if not name:
|
||||
raise TypeError('missing file name')
|
||||
|
||||
file_name = os.path.join(
|
||||
self._config['core']['data_dir'], name)
|
||||
file_name += '.state'
|
||||
logger.info('Load state from %s', file_name)
|
||||
|
||||
data = storage.load(file_name)
|
||||
if 'history' in data:
|
||||
@ -224,10 +229,11 @@ class Core(
|
||||
if 'tracklist' in data:
|
||||
self.tracklist._restore_state(data['tracklist'], coverage)
|
||||
if 'playback' in data:
|
||||
# playback after tracklist
|
||||
self.playback._restore_state(data['playback'], coverage)
|
||||
if 'mixer' in data:
|
||||
self.mixer._restore_state(data['mixer'], coverage)
|
||||
logger.debug('Load state done. file_name="%s"', file_name)
|
||||
logger.debug('Load state done.')
|
||||
|
||||
|
||||
class Backends(list):
|
||||
|
||||
@ -536,7 +536,12 @@ class PlaybackController(object):
|
||||
if state:
|
||||
if not isinstance(state, models.PlaybackState):
|
||||
raise TypeError('Expect an argument of type "PlaybackState"')
|
||||
if 'autoplay' in coverage:
|
||||
if state.tl_track is not None:
|
||||
new_state = ''
|
||||
if 'play-always' in coverage:
|
||||
new_state = PlaybackState.PLAYING
|
||||
if 'play-last' in coverage:
|
||||
new_state = state.state
|
||||
if state.tl_track is not None:
|
||||
if PlaybackState.PLAYING == new_state:
|
||||
self.play(tl_track=state.tl_track)
|
||||
# TODO: seek to state.position?
|
||||
|
||||
@ -417,7 +417,7 @@ class PlaybackState(ValidatedImmutableObject):
|
||||
:param position: play position
|
||||
:type position: int
|
||||
:param state: playback state
|
||||
:type state: :class:`TlTrack`
|
||||
:type state: :class:`validation.PLAYBACK_STATES`
|
||||
"""
|
||||
|
||||
# The current playing track. Read-only.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user