npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

osu-downloader

v0.8.1

Published

A tool for downloading osu! beatmaps and beatmapsets.

Downloads

47

Readme

osu-downloader

CodeFactor License Package

This is a simple tool for downloading osu! beatmaps, beatmapsets and replays. This package provides the following features:

  • Built-in rate limiter to prevent too many requests to the servers.
  • Ability to choose the number of files that can be downloaded per second.
  • Ability to choose between .osu, .osz and .osr files.
  • Multiple downloading sources for beatmapsets.
  • Protection against multiple downloads of the same file.
  • File validation before every downloading.

Installation

Add a new dependency to your project via npm:

npm install osu-downloader

Requirements

This project relies on file system operations so it doesn't support browser environment. You need to use Node.js or rewrite it to support browser API by yourself.

Basic example of single file downloading

import { Downloader, DownloadEntry } from 'osu-downloader'

const downloader = new Downloader({
  rootPath: './cache', 
  
  /**
   * Unlimited downloading.
   * This is not safe as it may result to 429 error.
   * You can also use fractional values (like 0.1, 0.2)
   * if one second is too fast for your application. 
   */
  filesPerSecond: 0,
});

downloader.addSingleEntry(91);

await downloader.downloadSingle();

Basic example of multiple file downloading

import { Downloader } from 'osu-downloader'

const downloader = new Downloader({
  rootPath: './cache', 
  filesPerSecond: 2, // Limit to 2 files per second.
  synchronous: true, // Download each file one by one.
});

const entries = [
  new DownloadEntry({ id: '91' }),
  new DownloadEntry({ id: 1228616 }),
  '335628',
  1626530,
];

downloader.addMultipleEntries(entries);

await downloader.downloadSingle(); // First file will be downloaded.
await downloader.downloadSingle(); // Second file will be downloaded.
await downloader.downloadAll();    // Rest of the files will be downloaded.

Advanced example of file downloading

import { Downloader, DownloadEntry, DownloadTypes } from 'osu-downloader'

const downloader = new Downloader({
  rootPath: './cache', 
  filesPerSecond: 2,
});

/**
 * Adds a new entry for .osu file to the download query.
 */
downloader.addSingleEntry(new DownloadEntry({
  id: '91',
  save: false, // Don't save file on a disk.
}));

/**
 * Adds a new entry for .osz file to the download query.
 */
downloader.addSingleEntry(new DownloadEntry({
  id: 3,
  customName: 'myfavouritebeatmapset.osz',
  type: DownloadType.Set,
  redownload: true,
}));

/**
 * Adds multiple entries to the download query.
 * You can combine different styles of writing and file types.
 */
downloader.addMultipleEntries([
  /* Beatmapset with ID 773801. */
  new DownloadEntry({
    id: 773801;
    type: DownloadType.Set;
  }),

  /* Non-existent osu! beatmaps will return status code -3 (Failed to download) */
  new DownloadEntry({
    id: 1337;
  }),

  /* Already downloaded files will return status code 1 (Already exists). */
  new DownloadEntry({
    id: 773801;
    type: DownloadType.Set;
  }),

  /* This, however, should return status code 2 (Downloaded) as we have redownload flag. */
  new DownloadEntry({
    id: 773801;
    type: DownloadType.Set;
    redownload: true,
  }),

  /** 
   * Will download a replay file via custom URL. 
   * If there is no custom name then file will be named as MD5 hash of URL. 
   */
  new DownloadEntry({
    url: 'https://your-replay-url',
    type: DownloadType.Replay,
  }),
]);

/**
 * Print downloader progress to the console every 100ms.
 */
setInterval(() => {
  console.log(downloader.progress);
}, 100);

/**
 * Save results of downloading.
 */
const result0 = await downloader.downloadSingle(); // First file will be downloaded.
const result1 = await downloader.downloadSingle(); // Second file will be downloaded.
const results = await downloader.downloadAll();    // Rest of the files will be downloaded.

Status Codes

  • -3 - File failed to download.
  • -2 - Wrong file format.
  • -1 - File failed to write.
  • 0 - Empty file.
  • 1 - File already exists,
  • 2 - File downloaded successfuly.
  • 3 - Written on a disk.

File types

  • 0 - osu! beatmap (.osu file format).
  • 1 - osu! beatmapset (.osz file format).
  • 2 - osu! replay (.osr file format).

Documentation

Auto-generated documentation is available here.

Contributing

This project is being developed personally by me on pure enthusiasm. If you want to help with development or fix a problem, then feel free to create a new pull request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE for details.