Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
v1.1.0 - ts rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
LewdHuTao committed May 29, 2024
1 parent e56cb28 commit a00b65e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
</div>
<br>

# 💫 Features

- **TypeScript Support**: llyrics is written in TypeScript, providing type safety and ease of use. Thanks to [RemyK](https://github.com/RemyK888) for Typescript rewrite ❤.
- **Support for Different Sources**: You can search for lyrics from YouTube, Musixmatch, or Genius by specifying the desired source(s) in the search options.
- **Auto Search**: If a search fails on the first specified search engine, llyrics automatically retries the search on another available search engine for a better lyrics result.
- **Easy to Use**: You can quickly search for song lyrics by providing the song title and, optionally, the artist name.


# 🪓 Installation
```sh
$ npm install llyrics
Expand All @@ -28,11 +36,10 @@ client.on(Events.InteractionCreate, async interaction => {

const response = await find({
song: 'Bohemian Rhapsody',
engine: 'musixmatch'
engine: 'youtube'
forceSearch: true,
});

console.log(response.artist);

if (interaction.commandName === 'lyrics') {
await interaction.reply({ content: response.lyrics, ephemeral: true });
}
Expand All @@ -45,34 +52,31 @@ client.login('token');

**Function parameters**

```
```js
{
song: string,
artist?: string,
geniusApiKey?: string,
engine?: 'musixmatch' | 'genius' | 'youtube',
forceSearch?: boolean
song: string, // The title of the song
artist?: string, // Optional: Use this for more accurate lyrics results on the Musixmatch endpoint
geniusApiKey?: string, // Optional: API key for the Genius search engine
engine?: 'musixmatch' | 'genius' | 'youtube', // Specify the desired search engine: 'musixmatch', 'genius', or 'youtube'
forceSearch?: boolean // Optional: If true and the search fails on the first specified search engine, llyrics automatically retries the search on another available search engine
}

```

The force search method requires a Genius API key and automatically changes search engine if the song is not found.

**Response format**
```
```js
{
artist: string,
title: string,
id: number,
engine: string,
atworkURL: string,
lyrics: string,
status: number
artist: string, // Artist's name
title: string, // Song title
id: number, // Musixmatch track ID (only for Musixmatch endpoint)
engine: string, // Search engine used
artworkURL: string, // Artwork URL
lyrics: string, // Song lyrics
}
```

*Note: the id is only available if the request was made with Musixmatch, otherwise it will be 0. This corresponds to the Musixmatch identifier of the song.*

The default search engine is Genius, so in order to use it, a Genius API key is required.
*Note: the id is only available if the request was made with Musixmatch. This corresponds to the Musixmatch identifier of the song.*

The default search engine is YouTube. If you prefer not to use YouTube, you can specify your desired search engine.

## **Made by LewdHuTao, rewritten with ❤ by RemyK**
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "llyrics",
"version": "1.0.9",
"version": "1.1.0",
"description": "A simple package to fetch lyrics from Genius API",
"main": "./index.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
"build": "rimraf dist && tsc && gen-esm-wrapper ./dist/index.js ./dist/index.mjs",
"docs": "ts-docs",
"fix": "eslint src --ext .ts --fix",
"test": "ts-node ./test/index.ts"
"test": "ts-node ./test/index.test.ts"
},
"author": "LewdHuTao",
"license": "ISC",
Expand Down
32 changes: 32 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { find } from '../src/index';

(async () => {
try {
const response = await find({
song: "rickroll",
engine: "youtube",
forceSearch: true,
geniusApiKey: process.env.GENIUS_API || "", // Genius API Key
});

async function getLyrics() {
try {
if (response) {
console.log('Artist:', response.artist);
console.log('Title:', response.title);
console.log('Engine:', response.engine);
console.log('Artwork URL:', response.artworkURL);
console.log('Lyrics:', response.lyrics);
} else {
console.log('No lyrics found.');
}
} catch (error) {
console.error('Error fetching lyrics:', error);
}
}

await getLyrics();
} catch (error) {
console.error('Error with find function:', error);
}
})();

0 comments on commit a00b65e

Please sign in to comment.