Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onepunya/yt-converter-js

Package Overview
Dependencies
Maintainers
0
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.5-a
  • npm
  • Socket score

Version published
Weekly downloads
200
decreased by-3.38%
Maintainers
0
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',
  mess: '',
  q: 'faded',
  items: [
    {
      v: '60ItHLz5WEA',
      t: 'Alan Walker - Faded',
      youtubeUrl: 'https://youtu.be/60ItHLz5WEA'
    },
    {
      v: 'jlKOSk-tXFQ',
      t: 'Alan Walker - Fade (Official Music Video)',
      youtubeUrl: 'https://youtu.be/jlKOSk-tXFQ'
    }
  ],
  p: 'search'
}

Converting Videos

Use the ytdlnew 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",
  duration": "duration",
  thumbnail: "thumbnail"
  "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

FAQs

Package last updated on 04 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc