Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ojvribeiro/yotoojs
Tiny library to fetch videos from YouTube
https://github.com/ojvribeiro/yotoojs
Last synced: 12 days ago
JSON representation
Tiny library to fetch videos from YouTube
- Host: GitHub
- URL: https://github.com/ojvribeiro/yotoojs
- Owner: ojvribeiro
- License: mit
- Created: 2022-04-28T00:43:12.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-18T05:09:20.000Z (almost 2 years ago)
- Last Synced: 2024-11-22T21:49:37.832Z (2 months ago)
- Language: JavaScript
- Size: 261 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YotooJS
[![npm](https://img.shields.io/npm/v/yotoojs?color=d40416&style=for-the-badge)](https://www.npmjs.com/package/yotoojs) ![NPM](https://img.shields.io/npm/l/yotoojs?style=for-the-badge)
Tiny library to fetch videos from YouTube.
## Installation
You can install YotooJS via npm:
```bash
npm install yotoojs
```Or you can use it on browser via Unpkg's CDN:
```html
```
## Setup
First, import yotoo:
```js
import { yotoo } from 'yotoojs'
```Then set an API key.
```js
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](https://console.developers.google.com/apis/credentials).
## Examples
### Fetching a single video
```js
yotoo.get(
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',response => {
const video = response[0]console.log(`Video title: ${video.title}`)
}
)
```### Fetching multiple videos
```js
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:
```json
[
{
"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": ""
}
]
```## Dependencies
None. :)
## Author
Victor Ribeiro ([ojvribeiro](https://github.com/ojvribeiro))