From a00b65e1ef98f33a96f6f297a44722d0406fc162 Mon Sep 17 00:00:00 2001 From: LewdHuTao Date: Wed, 29 May 2024 21:57:42 +0800 Subject: [PATCH] v1.1.0 - ts rewrite --- README.md | 48 +++++++++++++++++++++++++--------------------- package-lock.json | 4 ++-- package.json | 4 ++-- test/index.test.ts | 32 +++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 test/index.test.ts diff --git a/README.md b/README.md index d6357a6..32e848f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,14 @@
+# 💫 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 @@ -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 }); } @@ -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** \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index b3032a4..4509bfd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "llyrics", - "version": "1.0.9", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "llyrics", - "version": "1.0.9", + "version": "1.1.0", "license": "ISC", "dependencies": { "axios": "^1.7.2" diff --git a/package.json b/package.json index 5d1567c..d145ad8 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/test/index.test.ts b/test/index.test.ts new file mode 100644 index 0000000..318760c --- /dev/null +++ b/test/index.test.ts @@ -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); + } +})();