示例#1
0
    def update_playlist(self, path):
        if os.path.isdir(os.path.realpath(path)):

            existing = self.query(PlaylistTreeModel).filter(
                PlaylistTreeModel.path == path
            ).first()
            if existing is None:
                raise SoundforestError('Playlist tree not found: {0}'.format(path))

            existing.update(self, m3uPlaylistDirectory(path))

        elif os.path.isfile(os.path.realpath(path)):
            directory = os.path.dirname(path)
            name, extension = os.path.splitext(os.path.basename(path))
            extension = extension[1:]

            existing = self.query(PlaylistModel).filter(
                PlaylistModel.directory == directory,
                PlaylistModel.name == name,
                PlaylistModel.extension == extension,
            ).first()
            if existing is None:
                raise SoundforestError('Playlist not found: {0}'.format(path))

            existing.update(self, m3uPlaylist(path))
示例#2
0
    def add_playlist(self, path, name='Playlists'):
        """Register playlist or playlist tree

        """
        if os.path.isdir(os.path.realpath(path)):
            existing = self.query(PlaylistTreeModel).filter(PlaylistTreeModel.path==path).first()
            if existing is not None:
                raise SoundforestError('Playlist source is already in database: {0}'.format(path))

            tree = PlaylistTreeModel(path=path, name=name)
            self.add(tree)
            tree.update(self, m3uPlaylistDirectory(path))

        elif os.path.isfile(os.path.realpath(path)):
            directory = os.path.dirname(path)
            name, extension = os.path.splitext(os.path.basename(path))
            extension = extension[1:]

            existing = self.query(PlaylistModel).filter(
                PlaylistModel.directory == directory,
                PlaylistModel.name == name,
                PlaylistModel.extension == extension,
            ).first()
            if existing is not None:
                raise SoundforestError('Playlist is already in database: {0}'.format(path))

            playlist = PlaylistModel(directory=directory, name=name, extension=extension)
            playlist.update(self, m3uPlaylist(path))
            self.add(playlist)