Пример #1
0
    def test_save_state(self):
        self.core.teardown()

        assert os.path.isfile(self.state_file)
        reload_data = storage.load(self.state_file)
        data = {}
        data['version'] = mopidy.__version__
        data['state'] = models.CoreState(
            tracklist=models.TracklistState(
                repeat=False, random=False,
                consume=False, single=False,
                next_tlid=1),
            history=models.HistoryState(),
            playback=models.PlaybackState(state='stopped',
                                          time_position=0),
            mixer=models.MixerState())
        assert data == reload_data
Пример #2
0
    def test_save_state(self):
        self.core.teardown()

        assert os.path.isfile(self.state_file)
        reload_data = storage.load(self.state_file)
        data = {}
        data['version'] = mopidy.__version__
        data['state'] = models.CoreState(
            tracklist=models.TracklistState(repeat=False,
                                            random=False,
                                            consume=False,
                                            single=False,
                                            next_tlid=1),
            history=models.HistoryState(),
            playback=models.PlaybackState(state='stopped', time_position=0),
            mixer=models.MixerState())
        assert data == reload_data
Пример #3
0
 def load(self):
     logger.debug('Loading library: %s', self._json_file)
     with timer.time_logger('Loading tracks'):
         if not os.path.isfile(self._json_file):
             logger.info(
                 'No local library metadata cache found at %s. Please run '
                 '`mopidy local scan` to index your local music library. '
                 'If you do not have a local music collection, you can '
                 'disable the local backend to hide this message.',
                 self._json_file)
             self._tracks = {}
         else:
             library = internal_storage.load(self._json_file)
             self._tracks = dict((t.uri, t) for t in
                                 library.get('tracks', []))
     with timer.time_logger('Building browse cache'):
         self._browse_cache = _BrowseCache(sorted(self._tracks.keys()))
     return len(self._tracks)
Пример #4
0
 def load(self):
     logger.debug('Loading library: %s', self._json_file)
     with timer.time_logger('Loading tracks'):
         if not os.path.isfile(self._json_file):
             logger.info(
                 'No local library metadata cache found at %s. Please run '
                 '`mopidy local scan` to index your local music library. '
                 'If you do not have a local music collection, you can '
                 'disable the local backend to hide this message.',
                 self._json_file)
             self._tracks = {}
         else:
             library = internal_storage.load(self._json_file)
             self._tracks = dict(
                 (t.uri, t) for t in library.get('tracks', []))
     with timer.time_logger('Building browse cache'):
         self._browse_cache = _BrowseCache(sorted(self._tracks.keys()))
     return len(self._tracks)
Пример #5
0
    def test_save_state(self):
        self.core._teardown()

        assert self.state_file.is_file()
        reload_data = storage.load(self.state_file)
        data = {}
        data["version"] = mopidy.__version__
        data["state"] = models.CoreState(
            tracklist=models.TracklistState(
                repeat=False,
                random=False,
                consume=False,
                single=False,
                next_tlid=1,
            ),
            history=models.HistoryState(),
            playback=models.PlaybackState(state="stopped", time_position=0),
            mixer=models.MixerState(),
        )
        assert data == reload_data
Пример #6
0
    def _load_state(self, coverage):
        """
        Restore state from disk.

        Load state from disk and restore it. Parameter ``coverage``
        limits the amount of data to restore. Possible
        values for ``coverage`` (list of one or more of):

            - 'tracklist' fill the tracklist
            - 'mode' set tracklist properties (consume, random, repeat, single)
            - 'play-last' restore play state ('tracklist' also required)
            - 'mixer' set mixer volume and mute state
            - 'history' restore history

        :param coverage: amount of data to restore
        :type coverage: list of strings
        """

        file_name = os.path.join(self._get_data_dir(), b'state.json.gz')
        logger.info('Loading state from %s', file_name)

        data = storage.load(file_name)

        try:
            # Try only once. If something goes wrong, the next start is clean.
            os.remove(file_name)
        except OSError:
            logger.info('Failed to delete %s', file_name)

        if 'state' in data:
            core_state = data['state']
            validation.check_instance(core_state, CoreState)
            self.history._load_state(core_state.history, coverage)
            self.tracklist._load_state(core_state.tracklist, coverage)
            self.mixer._load_state(core_state.mixer, coverage)
            # playback after tracklist
            self.playback._load_state(core_state.playback, coverage)
        logger.debug('Loading state done')
Пример #7
0
    def _load_state(self, coverage):
        """
        Restore state from disk.

        Load state from disk and restore it. Parameter ``coverage``
        limits the amount of data to restore. Possible
        values for ``coverage`` (list of one or more of):

            - 'tracklist' fill the tracklist
            - 'mode' set tracklist properties (consume, random, repeat, single)
            - 'play-last' restore play state ('tracklist' also required)
            - 'mixer' set mixer volume and mute state
            - 'history' restore history

        :param coverage: amount of data to restore
        :type coverage: list of strings
        """

        file_name = os.path.join(self._get_data_dir(), b'state.json.gz')
        logger.info('Loading state from %s', file_name)

        data = storage.load(file_name)

        try:
            # Try only once. If something goes wrong, the next start is clean.
            os.remove(file_name)
        except OSError:
            logger.info('Failed to delete %s', file_name)

        if 'state' in data:
            core_state = data['state']
            validation.check_instance(core_state, CoreState)
            self.history._load_state(core_state.history, coverage)
            self.tracklist._load_state(core_state.tracklist, coverage)
            self.mixer._load_state(core_state.mixer, coverage)
            # playback after tracklist
            self.playback._load_state(core_state.playback, coverage)
        logger.debug('Loading state done')
Пример #8
0
    def load(self):
        if not self._json_file.is_file():
            self.data = {
                "version":
                mopidy.__version__,
                "radio_banks": {
                    "AM": [
                        {
                            "name": "FIP",
                            "stream_url":
                            "http://direct.fipradio.fr/live/fip-midfi.mp3",
                            "position": 64,
                        },
                        {
                            "name": "Meeeuh",
                            "stream_url":
                            "http://radiomeuh.ice.infomaniak.ch/radiomeuh-128.mp3",
                            "position": 32,
                        },
                    ],
                    "FM": [
                        {
                            "name": "Inter",
                            "stream_url":
                            "http://direct.franceinter.fr/live/franceinter-midfi.mp3",
                            "position": 32,
                        },
                        {
                            "name": "Culture",
                            "stream_url":
                            "http://direct.franceculture.fr/live/franceculture-midfi.mp3",
                            "position": 64,
                        },
                    ],
                },
                "podcasts": [
                    {
                        "name": "TEDx",
                        "feed_url":
                        "http://www.npr.org/rss/podcast.php?id=510298",
                        "episodes": [],
                        "position": 64,
                    },
                    {
                        "name": "Revolt",
                        "feed_url": "http://wordsmith.podomatic.com/rss2.xml",
                        "episodes": [],
                        "position": 32,
                    },
                    {
                        "name": "Neo Geo",
                        "feed_url": "http://feeds.feedburner.com/NeoGeoNova",
                        "position": 10,
                    },
                    {
                        "name": "Juke Box",
                        "feed_url":
                        "http://radiofrance-podcast.net/podcast09/rss_16999.xml",
                        "position": 20,
                    },
                ],
            }
            self.save()

        self.data = internal_storage.load(self._json_file)