How to use the slider.beatmap.Beatmap.parse function in slider

To help you get started, we’ve selected a few slider examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github llllllllll / slider / slider / library.py View on Github external
"""Save raw data for a beatmap at a given location.

        Parameters
        ----------
        data : bytes
            The unparsed beatmap data.
        beatmap : Beatmap, optional
            The parsed beatmap. If not provided, the raw data will be parsed.

        Returns
        -------
        beatmap : Beatmap
            The parsed beatmap.
        """
        if beatmap is None:
            beatmap = Beatmap.parse(data.decode('utf-8-sig'))

        path = self.path / sanitize_filename(
            f'{beatmap.artist} - '
            f'{beatmap.title} '
            f'({beatmap.creator})'
            f'[{beatmap.version}]'
            f'.osu'
        )
        with open(path, 'wb') as f:
            f.write(data)

        with self._db:
            self._write_to_db(beatmap, data, path)
        return beatmap
github llllllllll / slider / slider / beatmap.py View on Github external
The zipfile to read from.

        Returns
        -------
        beatmaps : dict[str, Beatmap]
            A mapping from difficulty name to the parsed Beatmap.

        Raises
        ------
        ValueError
            Raised when the file cannot be parsed as a ``.osz`` file.
        """
        return {
            beatmap.version: beatmap
            for beatmap in (
                Beatmap.parse(file.read(name).decode('utf-8-sig'))
                for name in
                file.namelist() if name.endswith('.osu')
            )
github llllllllll / slider / slider / library.py View on Github external
self = cls(path, cache=cache, download_url=download_url)
        write_to_db = self._write_to_db

        progress = maybe_show_progress(
            self._osu_files(path, recurse=recurse),
            show_progress,
            label='Processing beatmaps: ',
            item_show_func=lambda p: 'Done!' if p is None else str(p.stem),
        )
        with self._db, progress as it:
            for path in it:
                with open(path, 'rb') as f:
                    data = f.read()

                try:
                    beatmap = Beatmap.parse(data.decode('utf-8-sig'))
                except ValueError as e:
                    raise ValueError(f'failed to parse {path}') from e

                write_to_db(beatmap, data, path)

        return self
github llllllllll / slider / slider / library.py View on Github external
----------
        beatmap_id : int or str
            The id of the beatmap to download.
        save : bool, optional
            Save the beatmap to disk?

        Returns
        -------
        beatmap : Beatmap
            The downloaded beatmap.
        """
        beatmap_response = requests.get(f'{self._download_url}/{beatmap_id}')
        beatmap_response.raise_for_status()

        data = beatmap_response.content
        beatmap = Beatmap.parse(data.decode('utf-8-sig'))

        if save:
            self.save(data, beatmap=beatmap)

        return beatmap