Socket
Book a DemoInstallSign in
Socket

@onepunya/yt-converter-js

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onepunya/yt-converter-js

```markdown # @onepunya/yt-converter-js

1.0.8-a
latest
npmnpm
Version published
Weekly downloads
3
-75%
Maintainers
1
Weekly downloads
 
Created
Source
# @onepunya/yt-converter-js

A simple Node.js class to interact with YouTube video search and conversion services.

## Installation

To use this package, you need to have Node.js installed. You can install this package via npm:

```bash
npm install @onepunya/yt-converter-js

Usage

Importing the Class

import Youtube from '@onepunya/yt-converter-js';

or

const Youtube = require('@onepunya/yt-converter-js');

Creating an Instance

const youtube = new Youtube();

Searching for Videos

Use the search method to search for videos based on a query.

const query = 'Kokoronashi';

youtube.search(query)
  .then(result => {
    console.log(result);
  })
  .catch(error => {
    console.error('Error:', error);
  });

Parameters:

  • query (string): The search query string.

Returns: A promise that resolves to an object with the following structure:

{
  "status": "ok",
  "message": "",
  "query": "faded",
  "items": [
    {
      "videoId": "60ItHLz5WEA",
      "title": "Alan Walker - Faded",
      "youtubeUrl": "https://youtu.be/60ItHLz5WEA"
    },
    {
      "videoId": "jlKOSk-tXFQ",
      "title": "Alan Walker - Fade (Official Music Video)",
      "youtubeUrl": "https://youtu.be/jlKOSk-tXFQ"
    }
  ],
  "platform": "YouTube"
}

Converting Videos

Use the download method to convert a YouTube video to MP3 or MP4.

const videoUrl = 'https://www.youtube.com/watch?v=video_id';

youtube.download(videoUrl)
  .then(result => {
    console.log(result);
  })
  .catch(error => {
    console.error('Error:', error);
  });

Parameters:

  • videoUrl (string): The URL of the YouTube video.

Returns: A promise that resolves to an object with the following structure:

{
  "title": "video_title",
  "thumbnail": [], 
  //thumbnail format 
  //preview: 'https://i.ytimg.com/vi/9O_1dxvEduM/hqdefault.jpg',
  // resolution: 'High (480x360)'
  "mp4DownloadLink": "link_to_mp4_file",
  "mp3DownloadLink": "link_to_mp3_file"
}

Error Handling

Both methods return promises that will be rejected if an error occurs. Handle errors using .catch in your promise chain.

License

This project is licensed under the MIT License.

Follow Me

  • GitHub
  • Instagram
  • Community

Keywords

yt

FAQs

Package last updated on 08 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.