Skip to content

Commit

Permalink
Update package.json and add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
KorigamiK committed Feb 14, 2024
1 parent 43d933a commit 80692b1
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 76 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish Package to npmjs

on:
push:
tags:
- '*'


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
# osu!play
<h1 align="center">
<br>
osu!play
<br>

Listen to your favourite [osu!lazer](https://lazer.ppy.sh) beatmaps as a spotify playlist from the terminal
[![NPM version](https://img.shields.io/npm/v/osu-play.svg?style=flat)](https://npmjs.org/package/osu-play)
[![Downloads](https://badgen.net/npm/dt/osu-play)](https://www.npmjs.com/package/osu-play)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)

</h1>

> Listen to your favourite [osu!lazer](https://lazer.ppy.sh) beatmaps as a
> spotify playlist from the terminal
## Installation

### Requirements

- [Node.js](https://nodejs.org/en/) (v18 or higher)
- [osu!lazer](https://lazer.ppy.sh/home/download) with some beatmaps to listen to 😉
- [osu!lazer](https://lazer.ppy.sh/home/download) with some beatmaps to listen
to 😉
- That's it!

### Quick start

- Try out the latest release without installing anything:

```sh
npx osu-play # using npm
pnpm dlx osu-play # using pnpm
```
```sh
npx osu-play # using npm
pnpm dlx osu-play # using pnpm
```

- Install the latest release globally:

```sh
npm i -g osu-play # using npm
pnpm i -g osu-play # using pnpm
```
```sh
npm i -g osu-play # using npm
pnpm i -g osu-play # using pnpm
```

## Usage

The `osu-play` command can be used with the following options:

```sh
➜ korigamik git:(main) ✗ osu-play --help
Play music from your osu!lazer beatmaps from the terminal
Expand All @@ -55,4 +67,3 @@ import { lazer } from "osu-play";
const realm = getLazerDB();
```

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osu-play",
"version": "1.0.6",
"version": "1.0.7",
"description": "Play music from your osu!lazer beatmaps from the terminal.",
"type": "module",
"main": "bin/osu-play.js",
Expand Down Expand Up @@ -31,11 +31,11 @@
"devDependencies": {
"@types/node": "^20.8.9",
"@types/prompts": "^2.4.7",
"tsup": "^7.2.0",
"tsup": "^8.0.2",
"typescript": "^5.2.2"
},
"dependencies": {
"@types/yargs": "^17.0.29",
"@types/yargs": "^17.0.32",
"prompts": "^2.4.2",
"realm": "^12.2.1",
"yargs": "^17.7.2"
Expand All @@ -53,4 +53,4 @@
"url": "https://github.com/KorigamiK/osu-play"
},
"bugs": "https://github.com/KorigamiK/osu-play/issues"
}
}
113 changes: 53 additions & 60 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from "node:path";
import { existsSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";

import Realm from "realm";
import prompts from "prompts";
Expand All @@ -10,45 +9,49 @@ import { getLazerDB, getNamedFileHash, hashedFilePath } from "../realm/mod.js";

import yargs from "yargs/yargs";
import { hideBin } from "yargs/helpers";
import util from "node:util";
import { execFile } from "node:child_process";

const execFilePromise = util.promisify(execFile);

export function getArgs() {
const argv = yargs(hideBin(process.argv))
.usage("Play music from your osu!lazer beatmaps from the terminal\nUsage: $0 [options]")
.options({
reload: {
type: "boolean",
default: false,
alias: "r",
describe: "Reload lazer database",
},
exportPlaylist: {
type: "string",
describe: "Export playlist to a file",
},
osuDataDir: {
type: "string",
default: path.join(getDataDir() || ".", "osu"),
alias: "d",
describe: "Osu!lazer data directory",
},
configDir: {
type: "string",
default: path.join(getConfigDir() || ".", "osu-play"),
alias: "c",
describe: "Config directory",
},
loop: {
type: "boolean",
default: false,
alias: "l",
describe: "Loop the playlist on end",
},
help: {
type: "boolean",
alias: "h",
describe: "Show help",
}
}).argv;
reload: {
type: "boolean",
default: false,
alias: "r",
describe: "Reload lazer database",
},
exportPlaylist: {
type: "string",
describe: "Export playlist to a file",
},
osuDataDir: {
type: "string",
default: path.join(getDataDir() || ".", "osu"),
alias: "d",
describe: "Osu!lazer data directory",
},
configDir: {
type: "string",
default: path.join(getConfigDir() || ".", "osu-play"),
alias: "c",
describe: "Config directory",
},
loop: {
type: "boolean",
default: false,
alias: "l",
describe: "Loop the playlist on end",
},
help: {
type: "boolean",
alias: "h",
describe: "Show help",
}
}).argv;
return argv;
}

Expand All @@ -65,7 +68,7 @@ export async function main() {
}

if (argv.osuDataDir !== getDataDir()) {
console.log(`[INFO] Using osu!lazer data directory: ${argv.osuDataDir}`);
console.log(`[INFO] Using osu!lazer data directory: ${ argv.osuDataDir }`);
}

const realmDBPath = getRealmDBPath(argv.configDir, { reload, osuDataDir });
Expand All @@ -76,14 +79,12 @@ export async function main() {
}

const currentSchema = Realm.schemaVersion(realmDBPath);
console.log(`currentSchema: ${currentSchema}`);
console.log(`currentSchema: ${ currentSchema }`);

Realm.flags.ALLOW_CLEAR_TEST_STATE = true;

const realm: Realm = await getLazerDB(realmDBPath);

console.log(`realm.isClosed: ${realm.isClosed}`);

const beatmapSets = realm.objects(BeatmapSet);

const songSet = new Set<string>();
Expand All @@ -101,22 +102,21 @@ export async function main() {
songSet.add(hash);
const meta = beatmap.Metadata;
const path = hashedFilePath(hash);
const title = `${meta.Title} : ${meta.Artist} - ${meta.TitleUnicode} : ${meta.ArtistUnicode}`;
const title = `${ meta.Title } : ${ meta.Artist } - ${ meta.TitleUnicode } : ${ meta.ArtistUnicode }`;
uniqueBeatmaps.push({ title, path });
}
}

console.log(`beatmap songs: ${beatmapSets.length}`);
console.log(`beatmap songs: ${ beatmapSets.length }`);

if (argv.exportPlaylist) {
console.log(`[INFO] Exporting playlist to ${argv.exportPlaylist}`);
console.log(`[INFO] Exporting playlist to ${ argv.exportPlaylist }`);
const playlist = uniqueBeatmaps.map((mp) => mp.path).join("\n");
writeFileSync(argv.exportPlaylist, playlist);
console.log(`[INFO] Done. Use something like \`mpv --playlist=${argv.exportPlaylist}\` to play the playlist`);
console.log(`[INFO] Done. Use something like \`mpv --playlist=${ argv.exportPlaylist }\` to play the playlist`);
return;
}

// Get the map index from the user
let selectedBeatmap: number = (
await prompts({
type: "autocomplete",
Expand All @@ -128,36 +128,29 @@ export async function main() {
})),
})
).beatmap;
console.log(`Selected: ${ selectedBeatmap }`);

for (let i = selectedBeatmap; i < uniqueBeatmaps.length; ++i) {
let i = selectedBeatmap

for (; i < uniqueBeatmaps.length; ++i) {
const beatmap = uniqueBeatmaps[i];
console.log(`Map : ${beatmap.title}`);
console.log(`Map : ${ beatmap.title }`);
if (beatmap.path && existsSync(beatmap.path)) {
// Open file using exo-open.
console.log(`File exists: ${beatmap.path}`);
console.log(`Playing ${beatmap.title}`);
try {
execFileSync("exo-open", [beatmap.path]);
} catch (err) {
console.log(`Error: ${err}`);
break;
}
console.log(`Playing ${ beatmap.title }`);
await execFilePromise('exo-open', [beatmap.path]);
} else {
console.log(`File does not exist: ${beatmap.path}`);
console.log(`File does not exist: ${ beatmap.path }`);
}
if (i < uniqueBeatmaps.length - 1) {
// Wait 1 second between
await new Promise((resolve) => setTimeout(resolve, 1000));
} else if (argv.loop) {
console.log('[INFO] Looping playlist');
i = 0;
} else {
} else {
console.log('[INFO] Done. Use --loop to loop the playlist');
}
}

realm.close();
console.log(`realm.isClosed: ${realm.isClosed}`);

// Realm.clearTestState();
}

0 comments on commit 80692b1

Please sign in to comment.