yt-mp3-converter
Version:
YouTube to MP3 converter and Dwonload
95 lines (65 loc) • 3.07 kB
Markdown
Here is a `README.md` file for your `yt-mp3-converter` package:
```markdown
# yt-mp3-converter
`yt-mp3-converter` is a simple and efficient Node.js package that allows you to convert YouTube videos to MP3 audio files. This package leverages `ytdl-core` for video downloading and `fluent-ffmpeg` for converting video files to MP3 format.
## Features
- Convert YouTube videos to MP3 format.
- Simple and easy-to-use API.
- Lightweight and fast.
- Generates an HTML download button for the converted MP3 file.
## Installation
You can install the package via npm:
```bash
npm install yt-mp3-converter
```
## Usage
### Importing the Package
First, import the necessary functions from the `yt-mp3-converter` package:
```javascript
import { convertYouTubeToMp3, generateDownloadButton } from 'yt-mp3-converter';
```
### Example
Here’s an example of how to use `yt-mp3-converter` to convert a YouTube video to MP3 and generate a download button:
```typescript
import { convertYouTubeToMp3, generateDownloadButton } from 'yt-mp3-converter';
async function example() {
const outputFilePath = './output.mp3';
try {
await convertYouTubeToMp3({
videoUrl: 'https://www.youtube.com/watch?v=VIDEO_ID',
outputFilePath
});
const downloadButtonHtml = generateDownloadButton(outputFilePath);
console.log('Download Button HTML:', downloadButtonHtml);
} catch (error) {
console.error('Error converting video:', error);
}
}
example();
```
### API
#### `convertYouTubeToMp3(options: ConvertOptions): Promise<string>`
- **Description**: Downloads the audio from a YouTube video and converts it to MP3 format.
- **Parameters**:
- `options`: An object containing the following properties:
- `videoUrl`: The URL of the YouTube video.
- `outputFilePath`: The path where the MP3 file should be saved.
- **Returns**: A promise that resolves to the file path of the converted MP3 file.
#### `generateDownloadButton(filePath: string): string`
- **Description**: Generates an HTML download button for the converted MP3 file.
- **Parameters**:
- `filePath`: The path to the MP3 file.
- **Returns**: A string containing the HTML for the download button.
## Prerequisites
- Node.js (version 12 or higher)
- FFmpeg must be installed and accessible in your system's PATH.
## License
This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
## Disclaimer
Please ensure you comply with YouTube's Terms of Service when using this package. Converting and downloading YouTube videos may violate their policies if used improperly.
```
### How to Use This `README.md`
1. Save the `README.md` file in the root directory of your package.
2. Update any sections with additional details or changes specific to your implementation.
3. Ensure you have a `LICENSE` file if you reference a license in your `README.md`.
4. When you're ready, include this `README.md` when you publish the package to npm.