1.3.2-alpha • Published 2 years ago

yotoojs v1.3.2-alpha

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

YotooJS

npm NPM

Tiny library to fetch videos from YouTube.

Installation

You can install YotooJS via npm:

npm install yotoojs

Or you can use it on browser via Unpkg's CDN:

<script src="https://unpkg.com/yotoojs@latest/dist/yotoo.js"></script>

Setup

First, import yotoo:

import { yotoo } from 'yotoojs'

Then set an API key.

yotoo.setApiKey('YOUR_API_KEY')

:warning: Important: the previous method yotoo.apiKey() is deprecated. Use yotoo.setApiKey() instead.

You can get an API key from Google Developers Console.

Examples

Fetching a single video

yotoo.get(
  'https://www.youtube.com/watch?v=dQw4w9WgXcQ',

  response => {
    const video = response[0]

    console.log(`Video title: ${video.title}`)
  }
)

Fetching multiple videos

yotoo.get(
  [
    'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
    'https://www.youtube.com/watch?v=HyWYpM_S-2c',
    'https://www.youtube.com/watch?v=taTTt7dH4Ig',
  ],

  response => {
    response.forEach(video => {
      console.log(`Video title: ${video.title}`)
    })
  }
)

The response returned is an array of video objects.

Below you can see a sample JSON response:

[
  {
    "id": "dQw4w9WgXcQ",

    "title": "Rick Astley - Never Gonna Give You Up (Official Music Video)",

    "description": "The official video for “Never Gonna Give You Up” by Rick Astley",

    "channelTitle": "Rick Astley",

    "duration": "PT3M33S",

    "date": Sun Oct 25 2009 04:57:33 GMT-0200 (Horário de Verão de Brasília),

    "tags": [
      "rick astley",
      "Never Gonna Give You Up",
      "nggyu",
      "never gonna give you up lyrics",
      "rick rolled"
    ],

    "thumb": {
      "default": "https://i.ytimg.com/vi/dQw4w9WgXcQ/default.jpg",
      "sd": "https://i.ytimg.com/vi/dQw4w9WgXcQ/mqdefault.jpg",
      "hd": "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg"
    },

    "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",

    "shortUrl": "https://youtu.be/dQw4w9WgXcQ",

    "embedUrl": "https://www.youtube.com/embed/dQw4w9WgXcQ",

    "embed": "<iframe src=\"https://www.youtube.com/embed/dQw4w9WgXcQ\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
  }
]

Dependencies

None. :)

Author

Victor Ribeiro (ojvribeiro)

1.3.2-alpha

2 years ago

1.3.1-alpha

2 years ago

1.3.0-alpha

2 years ago

1.2.21-alpha

2 years ago

1.2.2-alpha

2 years ago

1.2.1-alpha

2 years ago

1.2.0-alpha

2 years ago

1.1.2-alpha

2 years ago

1.1.1-alpha

2 years ago

1.1.0-alpha

2 years ago

1.0.1-alpha

2 years ago

1.0.0

2 years ago