youtube-browser-api
v0.0.9
Published
Fully typed endpoints that parse HTML/JSON data from youtube.com from any environment.
Downloads
11
Maintainers
Readme
Fully typed endpoints that parse HTML/JSON data from youtube.com from any environment.
YouTube Browser API
Features
- Get data on YouTube videos, channels, playlists, heatmap, chapters and more
- Get YouTube video transcripts
- Simple and user-friendly API wrapper
- Works from any environment
Install
npm install youtube-browser-api
REST API is also available
Endpoints
/query: Extract data by passing schemas on video ids
:
- 🔥 You can make granular request as complex as the Javascript Object Notation allows.Go to the playground
| JSON | Interface | Source Code |
|--------|--------|--------|
| Examine the shape of the Response from a Video using a JSON Viewer | The autogenerated Interfaces for the playerResponse, videoData, apiToken, context and transcriptMeta
| The source code from a YouTube Video website - how to |
| Dummy - Skeleton | Inspect | view-source:https://www.youtube.com/watch?v=s-I_dV5oY8c |
⠀
// typescript
import Api from 'youtube-browser-api'
const myVideoQuery = await Api.query({
id: 'ZwLekxsSY3Y',
schema: {
playerResponse: {
videoDetails: {
title: true,
shortDescription: true,
thumbnail: {
thumbnails: {
1: {
url: true,
height: true,
width: true,
},
},
},
},
},
},
})
For complex queries you may enable tsAny: true
to bypass typechecking. Help to solve the issue https://github.com/kauderk/youtube-browser-api/issues/1
// javascript
const partialChapterQuery = {
id: 'ZwLekxsSY3Y',
schema: {
initialData: { playerOverlays: { playerOverlayRenderer: { decoratedPlayerBarRenderer: { decoratedPlayerBarRenderer: { playerBar: { multiMarkersPlayerBarRenderer: { markersMap: { 0: { value: { chapters: { 1: { chapterRenderer: { title: true, }, }, }, }, }, }, }, }, }, }, }, }, }
},
// optional paths|paths[]
paths: 'playerResponse.streamingData.formats.0.url',
};
const fetchUrl = 'https://youtube-browser-api.netlify.app/query?' + new URLSearchParams(partialChapterQuery).toString()
// https://youtube-browser-api.netlify.app/query?id=ZwLekxsSY3Y&paths=playerResponse.streamingData.formats.0.url
fetch(fetchUrl)
.then(res => res.json())
.then(console.log)
/content: Extract all or some video data by a video ID.
// typescript
import Api from 'youtube-browser-api'
const titleData = await Api.content({
id: 'pOEyYwKtHJo',
params: ['title'],
})
// javascript
const query = {
id: 'pOEyYwKtHJo',
params: ['title'], // ['title','suggestions','storyboard','heatmapPath','isLive','channel','description','initialData','playerResponse','apiToken','context','auto_chapters','chapters','heatmap']
}
const fetchUrl = `https://youtube-browser-api.netlify.app/content?id=${query.id}¶ms=` + query.params.join()
// https://youtube-browser-api.netlify.app/content?id=pOEyYwKtHJo¶ms=title
fetch(fetchUrl)
.then(res => res.json())
.then(console.log)
/data: Search for narrower data by passing keywords in the query parameter. For example search
:
// typescript
import Api from 'youtube-browser-api'
const mySearch = await Api.data('search', {
keyword: 'AI',
limit: 1,
})
// javascript
const query = {
keyword: 'AI',
withPlaylist: false,
limit: 1,
option: ''
};
const fetchUrl = 'https://youtube-browser-api.netlify.app/data/search?' + new URLSearchParams(query).toString()
// https://youtube-browser-api.netlify.app/data/search?keyword=record&withPlaylist=false&limit=1&option=
fetch(fetchUrl)
.then(res => res.json())
.then(console.log)
/transcript: Extract transcripts by passing video IDs in the query parameter. For example video ids
:
// typescript
import Api from 'youtube-browser-api'
const myTranscript = await Api.transcript({
videoId: 'pOEyYwKtHJo',
})
// javascript
const query = {
videoId: 'pOEyYwKtHJo'
};
const fetchUrl = 'https://youtube-browser-api.netlify.app/transcript?' + new URLSearchParams(query).toString()
// https://youtube-browser-api.netlify.app/transcript?videoId=pOEyYwKtHJo
fetch(fetchUrl)
.then(res => res.json())
.then(console.log)
Description
This YouTube API Wrapper website offers a simple and user-friendly interface to access YouTube's API. It is tailored to the needs of developers; it provides data through fully typed endpoints. Whether you need to extract video analytics, search for specific data, or extract transcripts, the API wrapper can help you do it quickly and easily.
License
This project is licensed under the MIT License.