1.2.0 • Published 7 months ago

like-youtube v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

like-youtube

Search and download YouTube videos

npm i like-youtube

It uses some libraries but it simplifies the usage. Eventually can be built-in.

Usage

const YouTube = require('like-youtube')

const yt = new YouTube()
const page = await yt.search('How to create a variable in JS')

for (const item of page.items) {
  const download1 = yt.download(item.id, { filename: './video-' + item.id + '.mp4' })
  const download2 = yt.audio(item.id, { filename: './audio-' + item.id + '.webm' })

  await download1.done()
  await download2.done()
}

const page2 = await yt.search(null, { next: page.next })
// ...

const details = await yt.getVideoDetails(videoId)
// E.g. details.suggestions

Stream without saving into a file:

for (const item of page.items) {
  const dl1 = yt.download(item.id)
  const dl2 = yt.audio(item.id)

  // dl1.stream ...
  // dl2.stream ...

  await dl1.done()
  await dl2.done()
}

API

youtube = new YouTube()

Creates a YouTube instance.

page = await youtube.search(input, [options])

Search by keywords. Returns { items, next }.

Input becomes optional if you're getting a next page.

Options:

{
  limit: 10,
  type: 'video', // Possible values: 'video', 'channel', 'playlist', 'movie'
  next // Accepts a page.next
}

Items from search are like:

{
  id,
  type,
  title,
  channelTitle,
  shortBylineText,
  length: Number,
  isLive: Boolean,
  thumbnail: { url, width, height },
  thumbnails: Array
}

download = youtube.video(idOrUrl, [options])

download = youtube.audio(idOrUrl, [options])

Creates a downloader. Use download.stream.

Wait for completion: await download.done() Cancel the download: await download.close()

Options:

{
  // Passing a filename will save the content into a file 
  // Then you only need to await dl.done()
  filename
}

Example: await yt.video(id, { filename }).done()

details = await youtube.getVideoDetails(id)

Get the details of a video.

Returns like:

{
  id,
  title,
  channel,
  channelId,
  description,
  keywords: Array,
  isLive: Boolean,
  thumbnail: { url, width, height },
  thumbnails: Array,
  suggestions: Array // Same format as search results
}

License

MIT

1.2.0

7 months ago

1.1.0

7 months ago

1.0.1

8 months ago

1.0.0

8 months ago