Exemple #1
0
def read_file(filename,
              scale=1,
              colors=None,
              hr=False,
              dt=False,
              mods=None,
              lazy=True):
    if hr or dt:
        logger.warning("hr args is depecrated")

    # checks if filename is a path
    if os.path.isdir(filename):
        raise NotAnBeatmap()

    fiel = open(filename, "r", encoding="utf-8")
    content = fiel.read()
    delimiters = [
        "[General]", "[Editor]", "[Metadata]", "[Difficulty]", "[Events]",
        "[TimingPoints]", "[Colours]", "[HitObjects]"
    ]
    info = split(delimiters, content)
    fiel.close()
    bmap = Beatmap(info, scale, colors, mods=mods, lazy=lazy)
    bmap.path = filename
    bmap.hash = osuhash(filename)
    return bmap
def getaudiofromfile(filename,
                     path,
                     defaultpath,
                     settings,
                     volume=1.0,
                     speed=1.0):
    fmts = ["wav", "mp3", "ogg"]
    for fmt in fmts:
        try:
            return read(os.path.join(path, filename + "." + fmt),
                        settings,
                        volume=volume,
                        speed=speed)
        except FileNotFoundError:
            pass

        except exceptions.CouldntDecodeError as e:
            logger.error(
                repr(e) + " filename " +
                os.path.join(path, filename + "." + fmt))
            return 1, np.zeros((0, 2), dtype=np.float32)

    logger.warning("file not found %s, using default skin", filename)

    if defaultpath is not None:
        return getaudiofromfile(filename,
                                defaultpath,
                                None,
                                settings,
                                volume=volume,
                                speed=speed)

    logger.error("file not found %s", filename)
    return 1, np.zeros((0, 2), dtype=np.float32)
Exemple #3
0
def read_file(filename: str,
              scale: float = 1,
              colors: dict = {},
              mods: int = None,
              lazy: bool = True,
              **kwargs: dict):
    if 'hr' in kwargs or 'dt' in kwargs:
        logger.warning("HR/DT args is deprecated.")

    # checks if filename is a path
    if os.path.isdir(filename):
        raise NotAnBeatmap()

    delimiters = [
        "[General]", "[Editor]", "[Metadata]", "[Difficulty]", "[Events]",
        "[TimingPoints]", "[Colours]", "[HitObjects]"
    ]

    with open(filename, 'r', encoding='utf-8') as file:
        info = split(delimiters, file.read())

    bmap = Beatmap(info, scale, colors, mods=mods, lazy=lazy)
    bmap.path = filename
    bmap.hash = osuhash(filename)
    return bmap