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

youtubei.js

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

youtubei.js - npm Package Compare versions

Comparing version 1.0.0 to 1.0.5

lib/OAuth.js

14

lib/Actions.js

@@ -14,3 +14,3 @@ 'use strict';

const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/subscription/subscribe?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
const response = await axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/subscription/subscribe${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
if (response instanceof Error) {

@@ -37,3 +37,3 @@ return {

const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/subscription/unsubscribe?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
const response = await axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/subscription/unsubscribe${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
if (response instanceof Error) {

@@ -62,3 +62,3 @@ return {

const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/like/like?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
const response = await axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/like/like${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
if (response instanceof Error) {

@@ -87,3 +87,3 @@ return {

const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/like/dislike?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
const response = await axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/like/dislike${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
if (response instanceof Error) {

@@ -112,3 +112,3 @@ return {

const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/like/removelike?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
const response = await axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/like/removelike${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
if (response instanceof Error) {

@@ -138,3 +138,3 @@ return {

const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/comment/create_comment?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
const response = await axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/comment/create_comment${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
if (response instanceof Error) {

@@ -161,3 +161,3 @@ return {

const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/notification/get_notification_menu?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, data, desktop: true })).catch((error) => error);
const response = await axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/notification/get_notification_menu${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, data, desktop: true })).catch((error) => error);
if (response instanceof Error) {

@@ -164,0 +164,0 @@ return {

@@ -8,5 +8,23 @@ 'use strict';

YT_MOBILE_URL: 'https://m.youtube.com',
YT_WATCH_PAGE: 'https://m.youtube.com/watch'
YT_WATCH_PAGE: 'https://m.youtube.com/watch',
};
const oauth = {
scope: 'http://gdata.youtube.com https://www.googleapis.com/auth/youtube-paid-content',
grant_type: 'http://oauth.net/grant_type/device/1.0',
model_name: 'ytlr::'
};
const oauth_reqopts = {
headers: {
'accept': '*/*',
'origin': urls.YT_BASE_URL,
'user-agent': 'Mozilla/5.0 (ChromiumStylePlatform) Cobalt/Version',
'content-type': 'application/json',
'x-requested-with': 'mark.via.gp',
'referer': `${urls.YT_BASE_URL}/tv`,
'accept-language': 'en-US'
}
};
const default_headers = (session) => {

@@ -46,3 +64,3 @@ return {

req_opts.headers.Cookie = info.session.cookie;
req_opts.headers.authorization = info.session.auth_apisid;
req_opts.headers.authorization = info.session.cookie.length < 1 ? `Bearer ${info.session.access_token}` : info.session.auth_apisid;
}

@@ -61,3 +79,3 @@

const video_details_req_body = (id, sts, context) => {
const video_details_reqbody = (id, sts, context) => {
return {

@@ -313,2 +331,2 @@ playbackContext: {

module.exports = { urls, default_headers, innertube_request_opts, video_details_req_body, stream_headers, formatVideoData, filters };
module.exports = { urls, oauth, oauth_reqopts, default_headers, innertube_request_opts, video_details_reqbody, stream_headers, formatVideoData, filters };
'use strict';
const axios = require('axios');
const Axios = require('axios');
const Stream = require('stream');
const OAuth = require('./OAuth');
const Utils = require('./Utils');

@@ -10,14 +11,16 @@ const Player = require('./Player');

const SigDecipher = require('./SigDecipher');
const EventEmitter = require('events');
const TimeToSeconds = require('time-to-seconds');
const CancelToken = axios.CancelToken;
const CancelToken = Axios.CancelToken;
class Innertube {
constructor(cookie) {
class Innertube extends EventEmitter {
constructor(cookie, sign_in) {
super();
this.cookie = cookie || '';
return new Promise(async (resolve, reject) => resolve(await this.init()));
return this.init();
}
async init() {
const response = await axios.get(Constants.urls.YT_BASE_URL, Constants.default_headers(this)).catch((error) => error);
if (response instanceof Error) throw new Error('Could not retrieve InnerTube configuration data: ' + response.message);
const response = await Axios.get(Constants.urls.YT_BASE_URL, Constants.default_headers(this)).catch((error) => error);
if (response instanceof Error) throw new Error('Could not retrieve Innertube configuration data: ' + response.message);
let innertube_data = JSON.parse('{' + Utils.getStringBetweenStrings(response.data, 'ytcfg.set({', '});') + '}');

@@ -34,7 +37,7 @@ if (innertube_data.INNERTUBE_CONTEXT) {

this.context.client.gl = 'US';
this.player = new Player(this);
await this.player.init();
if (this.logged_in) {
if (this.logged_in && this.cookie.length > 1) {
this.auth_apisid = Utils.getStringBetweenStrings(this.cookie, 'PAPISID=', ';');

@@ -50,9 +53,49 @@ this.auth_apisid = Utils.generateSidAuth(this.auth_apisid);

}
async signIn(credentials = {}) {
const oauth = new OAuth(credentials);
if (credentials.access_token && credentials.refresh_token) {
let token_validity = await oauth.checkTokenValidity(credentials.access_token, this);
if (token_validity === 'VALID') {
this.access_token = credentials.access_token;
this.refresh_token = credentials.refresh_token;
this.logged_in = true;
} else {
oauth.refreshAccessToken(credentials.refresh_token);
oauth.on('refresh-token', (data) => {
this.access_token = data.access_token;
this.refresh_token = credentials.refresh_token;
this.logged_in = true;
this.emit('update-credentials', {
access_token: data.access_token,
refresh_token: credentials.refresh_token,
status: data.status
});
});
}
return;
}
return new Promise((resolve, reject) => {
oauth.on('auth', (data) => {
if (data.status === 'SUCCESS') {
this.emit('auth', data);
this.access_token = data.access_token;
this.refresh_token = data.refresh_token;
this.logged_in = true;
resolve();
} else {
this.emit('auth', data);
}
});
});
}
async search(query, options = { period: 'any', order: 'relevance', duration: 'any', quantity: 100 }) {
if (!this.initialized) throw new Error('Missing Innertube data.');
const yt_response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/search?key=' + this.key, JSON.stringify({ context: this.context, params: Constants.filters(options.period + ',' + options.duration + ',' + options.order), query }), Constants.innertube_request_opts({ session: this })).catch((error) => error);
const yt_response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/search${this.logged_in && this.cookie.length < 1 ? '' : `?key=${this.key}`}`, JSON.stringify({ context: this.context, params: Constants.filters(options.period + ',' + options.duration + ',' + options.order), query }), Constants.innertube_request_opts({ session: this })).catch((error) => error);
if (yt_response instanceof Error) throw new Error('Could not search on YouTube: ' + yt_response.message);
let content = yt_response.data.contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents[0].itemSectionRenderer.contents;

@@ -95,3 +138,3 @@ let search_response = {};

}
async getDetails(id) {

@@ -133,5 +176,5 @@ const data = await this.requestVideoInfo(id, false);

if (!desktop) {
response = await axios.get(Constants.urls.YT_WATCH_PAGE + '?v=' + id + 't=8s&pbj=1&bpctr=9999999999&has_verified=1&', Constants.innertube_request_opts({ session: this, id, desktop: false })).catch((error) => error);
response = await Axios.get(Constants.urls.YT_WATCH_PAGE + '?v=' + id + 't=8s&pbj=1&bpctr=9999999999&has_verified=1&', Constants.innertube_request_opts({ session: this, id, desktop: false })).catch((error) => error);
} else {
response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/player?key=' + this.key, JSON.stringify(Constants.video_details_req_body(id, this.sts, this.context)), Constants.innertube_request_opts({ session: this, id, desktop: true })).catch((error) => error);
response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/player${this.logged_in && this.cookie.length < 1 ? '' : `?key=${this.key}`}`, JSON.stringify(Constants.video_details_reqbody(id, this.sts, this.context)), Constants.innertube_request_opts({ session: this, id, desktop: true })).catch((error) => error);
}

@@ -227,3 +270,3 @@ if (response instanceof Error) throw new Error('Could not retrieve watch page info: ' + response.message);

if (options.type == 'videoandaudio') {
const response = await axios.get(selected_format.url, { cancelToken: new CancelToken(function executor(c) { cancel = c; }), responseType: 'stream', reponseEncoding: 'binary', headers: Constants.stream_headers() }).catch((error) => error);
const response = await Axios.get(selected_format.url, { cancelToken: new CancelToken(function executor(c) { cancel = c; }), responseType: 'stream', reponseEncoding: 'binary', headers: Constants.stream_headers() }).catch((error) => error);
if (response instanceof Error) {

@@ -263,3 +306,3 @@ stream.emit('error', { message: response.message, type: 'REQUEST_FAILED' });

const downloadChunk = async () => {
const response = await axios.get(selected_format.url, { cancelToken: new CancelToken(function executor(c) { cancel = c; }), responseType: 'stream', headers: Constants.stream_headers(`bytes=${chunk_start}-${chunk_end || ''}`) }).catch((error) => error);
const response = await Axios.get(selected_format.url, { cancelToken: new CancelToken(function executor(c) { cancel = c; }), responseType: 'stream', headers: Constants.stream_headers(`bytes=${chunk_start}-${chunk_end || ''}`) }).catch((error) => error);
if (response instanceof Error) {

@@ -280,5 +323,7 @@ stream.emit('error', { message: response.message, type: 'REQUEST_FAILED' });

chunk_end += chunk_size;
if (downloaded_size < selected_format.contentLength) {
downloadChunk();
} else {
stream.emit('end');
}

@@ -295,3 +340,3 @@ });

response.data.pipe(stream);
response.data.pipe(stream, { end: false });
};

@@ -298,0 +343,0 @@ downloadChunk();

{
"name": "youtubei.js",
"version": "1.0.0",
"version": "1.0.5",
"description": "An object-oriented library that allows you to search, get detailed info about videos, subscribe, unsubscribe, like, dislike, comment, download videos and much more!",

@@ -18,3 +18,4 @@ "main": "index.js",

"time-to-seconds": "^1.1.5",
"user-agents": "^1.0.778"
"user-agents": "^1.0.778",
"uuid": "^8.3.2"
},

@@ -36,2 +37,3 @@ "repository": {

"downloader",
"automation",
"youtube-downloader"

@@ -38,0 +40,0 @@ ],

@@ -9,4 +9,10 @@ # YouTube.js

Well currently this library is able to: search, get detailed info about videos, subscribe/unsubscribe/like/dislike/comment and fetch video notifications (Cookies required). Last but not least, you can also download videos.
As of now, this is one of the most advanced & stable YouTube libraries out there, and it can:
- Search.
- Get detailed info about videos.
- Fetch notifications (sign-in required).
- Subscribe/Unsubscribe/Like/Dislike/Comment (sign-in required).
- Last but not least, you can also download videos!
#### Do I need an API key to use this?

@@ -23,2 +29,13 @@

## Usage
[1. Basic Usage](https://www.npmjs.com/package/youtubei.js#usage)
[2. Interactions](https://www.npmjs.com/package/youtubei.js#interactions)
[3. Downloading Videos](https://www.npmjs.com/package/youtubei.js#downloading-videos)
[4. Signing-in](https://www.npmjs.com/package/youtubei.js#signing-in)
[5. Disclaimer](https://www.npmjs.com/package/youtubei.js#disclaimer)
First of all we're gonna start by initializing the Innertube class:

@@ -28,6 +45,5 @@

const Innertube = require('youtubei.js');
const COOKIE = 'YT_COOKIE_HERE'; // Optional, but highly recommended
async function start() {
const youtube = await new Innertube(COOKIE);
const youtube = await new Innertube();
//...

@@ -97,664 +113,4 @@ }

}
},
{
"title":"The Search For Life On Mars | Space Science Documentary 2019",
"description":"The possibility of life on Mars is a subject of significant interest to astrobiology due to its proximity and similarities to ...",
"author":"Biological Science",
"id":"BCNRVfk2edw",
"url":"https://youtu.be/BCNRVfk2edw",
"channel_url":"https://www.youtube.com/channel/UCF2ipIbOaSw39RgT-wTL7Aw",
"metadata":{
"view_count":"7,197 views",
"short_view_count_text":{
"simple_text":"7.1K views",
"accessibility_label":"7.1K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/BCNRVfk2edw/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDkfu4hnuuFv7CoWyGCH9WuKr7Abw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/BCNRVfk2edw/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDzffJrXYnCV3jjG2xsbP9FA6nUUg",
"width":720,
"height":404
}
],
"duration":{
"seconds":3006,
"simple_text":"50:06",
"accessibility_label":"50 minutes, 6 seconds"
},
"published":"2 years ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Is There Life on Mars | Space Documentary 2020 Full HD 1080p",
"description":"Is There Life on Mars | Space Documentary 2020 Full HD 1080p Some of our friends at the Lakeview Museum of Arts and ...",
"author":"TL Documentary",
"id":"jR7ZB63VF5s",
"url":"https://youtu.be/jR7ZB63VF5s",
"channel_url":"https://www.youtube.com/channel/UCm_F-N7ZC8l_wpGLbUXTY1A",
"metadata":{
"view_count":"122,195 views",
"short_view_count_text":{
"simple_text":"122K views",
"accessibility_label":"122K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/jR7ZB63VF5s/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAIie5XOCknLvm8Raw6Rmo6vOVjgw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/jR7ZB63VF5s/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDW1-VZFHJgWuNELAHXwHAugan9OA",
"width":720,
"height":404
}
],
"duration":{
"seconds":3356,
"simple_text":"55:56",
"accessibility_label":"55 minutes, 56 seconds"
},
"published":"1 year ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Space Isn't What You Think It Is - Space Documentary",
"description":"Buy us a coffee! buymeacoffee.com/factnomenal Deep space discoveries and space facts all in one stream! This space ...",
"author":"Factnomenal",
"id":"bMa2QI64uhA",
"url":"https://youtu.be/bMa2QI64uhA",
"channel_url":"https://www.youtube.com/channel/UC1pUFgoqKqy_sfzF0_rtQzQ",
"metadata":{
"short_view_count_text":{
"accessibility_label":"N/A"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/bMa2QI64uhA/hqdefault.jpg?sqp=-oaymwEcCOADEI4CSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDv3Oh_IeyTYGEbINgNTSJbzEqlfQ",
"width":480,
"height":270
}
],
"duration":{
"seconds":0,
"simple_text":"N/A",
"accessibility_label":"N/A"
},
"published":"N/A",
"badges":[
"LIVE NOW"
],
"owner_badges":[
"Verified"
]
}
},
{
"title":"History's Mysteries - The Search For Life on Mars (History Channel Documentary)",
"description":"Narrated by David Ackroyd.",
"author":"Alien Documentary",
"id":"ZzR7YgxTLns",
"url":"https://youtu.be/ZzR7YgxTLns",
"channel_url":"https://www.youtube.com/channel/UCSnoNN2uMUuU52zNLwLAFTg",
"metadata":{
"view_count":"935 views",
"short_view_count_text":{
"simple_text":"935 views",
"accessibility_label":"935 views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/ZzR7YgxTLns/hqdefault.jpg?sqp=-oaymwEcCOADEI4CSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBBGqBoXlPNqq3sZN8ZfYgy3oJvHA",
"width":480,
"height":270
}
],
"duration":{
"seconds":2526,
"simple_text":"42:06",
"accessibility_label":"42 minutes, 6 seconds"
},
"published":"1 year ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Mars Making the New Earth | Full Documentary",
"description":"In National Geographic Channel's “Mars: Making the New Earth”, award winning writer/producer Mark Davis and legendary Mars ...",
"author":"space and astronomy",
"id":"_50N5QoQoc4",
"url":"https://youtu.be/_50N5QoQoc4",
"channel_url":"https://www.youtube.com/channel/UC1-7mA0mKsCTyCMG4JNO3EQ",
"metadata":{
"view_count":"6,414,888 views",
"short_view_count_text":{
"simple_text":"6.4M views",
"accessibility_label":"6.4 million views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/_50N5QoQoc4/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBOZEjjn2hydUIxl5VnNr7JLoaEtg",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/_50N5QoQoc4/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAL7FaRfHi6rYjIgd8U2YGWN7C87Q",
"width":720,
"height":404
}
],
"duration":{
"seconds":3001,
"simple_text":"50:01",
"accessibility_label":"50 minutes, 1 second"
},
"published":"4 years ago",
"badges":"N/A",
"owner_badges":[
"Verified"
]
}
},
{
"title":"NASA Searching for Signs of Ancient Life on Mars with Perseverance Rover Launch",
"description":"According to NASA, the Perseverance rover will seek signs of ancient life and collect rock and soil samples for possible return to ...",
"author":"Curiosity Stream",
"id":"E1xiWgMX2xQ",
"url":"https://youtu.be/E1xiWgMX2xQ",
"channel_url":"https://www.youtube.com/channel/UCd7zlpSjvUuUwsQdqV3LF3w",
"metadata":{
"view_count":"24,042 views",
"short_view_count_text":{
"simple_text":"24K views",
"accessibility_label":"24K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/E1xiWgMX2xQ/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDqIaqzfBlb1XdOpaGggB2rfarCfw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/E1xiWgMX2xQ/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDiGXMnhlKDamCUo1eMDDVL8G1csQ",
"width":720,
"height":404
}
],
"duration":{
"seconds":1413,
"simple_text":"23:33",
"accessibility_label":"23 minutes, 33 seconds"
},
"published":"1 year ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Searching for Life on Mars - KQED QUEST",
"description":"After multiple unmanned missions to Mars, we still don't know if life has ever existed there. NASA scientists are hoping a new ...",
"author":"KQED",
"id":"iV5S1OSmYns",
"url":"https://youtu.be/iV5S1OSmYns",
"channel_url":"https://www.youtube.com/user/KQEDondemand",
"metadata":{
"view_count":"9,113 views",
"short_view_count_text":{
"simple_text":"9.1K views",
"accessibility_label":"9.1K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/iV5S1OSmYns/hqdefault.jpg?sqp=-oaymwEcCOADEI4CSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLB3SX8N5ovnFz57XyirGN1mXt2xMg",
"width":480,
"height":270
}
],
"duration":{
"seconds":602,
"simple_text":"10:02",
"accessibility_label":"10 minutes, 2 seconds"
},
"published":"10 years ago",
"badges":"N/A",
"owner_badges":[
"Verified"
]
}
},
{
"title":"Searching for Life on Mars",
"description":"On August 2012, the one-ton NASA Curiosity rover descended onto a massive crater on Mars. Since its landing, the Curiosity ...",
"author":"KQED QUEST",
"id":"LHMQyQ_YwL8",
"url":"https://youtu.be/LHMQyQ_YwL8",
"channel_url":"https://www.youtube.com/user/QUESTScienceMedia",
"metadata":{
"view_count":"7,204 views",
"short_view_count_text":{
"simple_text":"7.2K views",
"accessibility_label":"7.2K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/LHMQyQ_YwL8/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDMpYDrGTMNh1S1LtJEVSqcr2Rprw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/LHMQyQ_YwL8/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBP23wWbq0mhq3uxYuatHBdKS79GA",
"width":720,
"height":404
}
],
"duration":{
"seconds":443,
"simple_text":"7:23",
"accessibility_label":"7 minutes, 23 seconds"
},
"published":"6 years ago",
"badges":[
"CC"
],
"owner_badges":"N/A "
}
},
{
"title":"Promo: NOVA: Looking for Life on Mars",
"description":"N/A",
"author":"WOSU Public Media",
"id":"Osl1VlikjBM",
"url":"https://youtu.be/Osl1VlikjBM",
"channel_url":"https://www.youtube.com/user/WOSUColumbus",
"metadata":{
"view_count":"971 views",
"short_view_count_text":{
"simple_text":"971 views",
"accessibility_label":"971 views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/Osl1VlikjBM/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCAggkvbtQPhtWPbwZgfvD-f-tWdQ",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/Osl1VlikjBM/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDwab8LaEP-09ObvzKbno49nNpeBQ",
"width":720,
"height":404
}
],
"duration":{
"seconds":31,
"simple_text":"0:31",
"accessibility_label":"31 seconds"
},
"published":"7 months ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"David Bowie – Life On Mars? (Official Video)",
"description":"Official video for Life On Mars? by David Bowie. Stream David Bowie's greatest hits here ...",
"author":"David Bowie",
"id":"AZKcl4-tcuo",
"url":"https://youtu.be/AZKcl4-tcuo",
"channel_url":"https://www.youtube.com/channel/UC8YgWcDKi1rLbQ1OtrOHeDw",
"metadata":{
"view_count":"32,825,957 views",
"short_view_count_text":{
"simple_text":"32M views",
"accessibility_label":"32 million views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/AZKcl4-tcuo/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLA0e_NS5xIi1mWV_pxKTQL478S7Pw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/AZKcl4-tcuo/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCb60te4rgCzCatEhZKV6Kc7Q6Xig",
"width":720,
"height":404
}
],
"duration":{
"seconds":250,
"simple_text":"4:10",
"accessibility_label":"4 minutes, 10 seconds"
},
"published":"6 years ago",
"badges":"N/A",
"owner_badges":[
"Official Artist Channel"
]
}
},
{
"title":"Looking for Life on Mars",
"description":"One of the primary goals of the Mars Perseverance Rover is to look for life on the red planet. Learn about how they are going to do ...",
"author":"Smithsonian National Air and Space Museum",
"id":"WrVrPi_TeaM",
"url":"https://youtu.be/WrVrPi_TeaM",
"channel_url":"https://www.youtube.com/user/airandspace",
"metadata":{
"view_count":"390 views",
"short_view_count_text":{
"simple_text":"390 views",
"accessibility_label":"390 views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/WrVrPi_TeaM/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLD9cZWMCOYAxIptsQHlOSsV2OK1Yg",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/WrVrPi_TeaM/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAHmQWVCCYxcQ6qIqj9OMDS-qeyPQ",
"width":720,
"height":404
}
],
"duration":{
"seconds":254,
"simple_text":"4:14",
"accessibility_label":"4 minutes, 14 seconds"
},
"published":"8 months ago",
"badges":[
"CC"
],
"owner_badges":[
"Verified"
]
}
},
{
"title":"Disney's Tomorrowland - Life on Mars [SCARY VERSION]",
"description":"Science fiction bleeds into science fact with Disney's realistic look at life on Mars and beyond. A truly beautiful piece of lost ...",
"author":"Laser Time",
"id":"mQ-T5VEueW0",
"url":"https://youtu.be/mQ-T5VEueW0",
"channel_url":"https://www.youtube.com/user/LaserTimeNetwork",
"metadata":{
"view_count":"52,346 views",
"short_view_count_text":{
"simple_text":"52K views",
"accessibility_label":"52K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/mQ-T5VEueW0/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDyC9Zm6CfRnh0kvpFHI8TawmKvcg",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/mQ-T5VEueW0/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCkiB-XL_1l5MS5Xc9lwt2gnw3s-A",
"width":720,
"height":404
}
],
"duration":{
"seconds":285,
"simple_text":"4:45",
"accessibility_label":"4 minutes, 45 seconds"
},
"published":"6 years ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Looking for Life on Mars",
"description":"Mars has changed since it formed 4.6 billion years ago. When life started on Earth ~4 billion years ago, Mars was habitable too, ...",
"author":"Gresham College",
"id":"ymQfqE3L09w",
"url":"https://youtu.be/ymQfqE3L09w",
"channel_url":"https://www.youtube.com/user/GreshamCollege",
"metadata":{
"view_count":"3,493 views",
"short_view_count_text":{
"simple_text":"3.4K views",
"accessibility_label":"3.4K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/ymQfqE3L09w/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLC8gNkm5OTBZs8xqeVdu9i5nyFvZA",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/ymQfqE3L09w/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBOmozAYVQ9t8i1tm3p168W4GFN5A",
"width":720,
"height":404
}
],
"duration":{
"seconds":3632,
"simple_text":"1:00:32",
"accessibility_label":"1 hour, 32 seconds"
},
"published":"11 months ago",
"badges":[
"CC"
],
"owner_badges":[
"Verified"
]
}
},
{
"title":"MARS: The Search Begins (1974) - NASA Documentary - Carl Sagan, Life on Mars",
"description":"NASA documentary about the 1970's hopes for life on Mars and the (then) future Viking missions to search for it. The Mariner ...",
"author":"Retro Space HD",
"id":"zMTZ0nKMfdQ",
"url":"https://youtu.be/zMTZ0nKMfdQ",
"channel_url":"https://www.youtube.com/channel/UCZJgMAoS30yYoLOYUe_lAXQ",
"metadata":{
"view_count":"753 views",
"short_view_count_text":{
"simple_text":"753 views",
"accessibility_label":"753 views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/zMTZ0nKMfdQ/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLD8u3eXdHt-JTMhIipL6xc9NLKnqw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/zMTZ0nKMfdQ/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDeg8_cb41r6RmnT8Lw-rcTt6JXLw",
"width":720,
"height":404
}
],
"duration":{
"seconds":1726,
"simple_text":"28:46",
"accessibility_label":"28 minutes, 46 seconds"
},
"published":"1 year ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Journey to the Mars | Space Documentary | Mars documentary",
"description":"Journey to the #Mars | #Space #Documentary #Marsdocumentary space brothers documentary space documentary channel 4 ...",
"author":"Rovin karki",
"id":"bz7JS_OPIOs",
"url":"https://youtu.be/bz7JS_OPIOs",
"channel_url":"https://www.youtube.com/channel/UC6EEJgTVlfIXPVfNnCTHpjQ",
"metadata":{
"view_count":"12,746 views",
"short_view_count_text":{
"simple_text":"12K views",
"accessibility_label":"12K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/bz7JS_OPIOs/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLA7PcjRkokQcFnVVzpzck2mg_Yr4g",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/bz7JS_OPIOs/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCUKTTUao4CcYdfnK6ZbGi9eCifKQ",
"width":720,
"height":404
}
],
"duration":{
"seconds":3001,
"simple_text":"50:01",
"accessibility_label":"50 minutes, 1 second"
},
"published":"8 months ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Mars Pioneers | Space Documentary 2020 Full HD 1080p",
"description":"Mars Pioneers | Space Documentary 2020 Full HD 1080p This film captures the spirit of Mars pioneers who refuse to let their ...",
"author":"TL Documentary",
"id":"cPpPKriqR1Y",
"url":"https://youtu.be/cPpPKriqR1Y",
"channel_url":"https://www.youtube.com/channel/UCm_F-N7ZC8l_wpGLbUXTY1A",
"metadata":{
"view_count":"19,998 views",
"short_view_count_text":{
"simple_text":"19K views",
"accessibility_label":"19K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/cPpPKriqR1Y/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLB3k4zBaar5byu-eQI-p8leg6TWAw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/cPpPKriqR1Y/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDDmBNYLntlnb-LcZlWACftp168Sg",
"width":720,
"height":404
}
],
"duration":{
"seconds":4406,
"simple_text":"1:13:26",
"accessibility_label":"1 hour, 13 minutes, 26 seconds"
},
"published":"1 year ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"The Search for Life and Water on Mars | Space documentary",
"description":"Since the dawn of the space age, several probes have been sent to the Red Planet, providing interesting facts and stunning ...",
"author":"Sven Piper",
"id":"A1aW02SMl_Q",
"url":"https://youtu.be/A1aW02SMl_Q",
"channel_url":"https://www.youtube.com/channel/UCapd-epIfx73sgVRLiu0kdQ",
"metadata":{
"view_count":"8,528 views",
"short_view_count_text":{
"simple_text":"8.5K views",
"accessibility_label":"8.5K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/A1aW02SMl_Q/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDzef7tTDKqI1H_yK4Zud67A4XoZw",
"width":360,
"height":202
},
{
"url":"https://i.ytimg.com/vi/A1aW02SMl_Q/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBmIdJlTV0j8H4P6OMSRv4-nlBCpg",
"width":720,
"height":404
}
],
"duration":{
"seconds":421,
"simple_text":"7:01",
"accessibility_label":"7 minutes, 1 second"
},
"published":"11 months ago",
"badges":[
"4K",
"CC"
],
"owner_badges":"N/A "
}
},
{
"title":"Life on Mars Planet",
"description":"From \"Cosmic Capers (1957)\" documentary. Directed by Ward Kimball and narrated by Paul Frees, made in 1957. This video is a ...",
"author":"Leandro Machado Rocha",
"id":"SQJ8loydnlA",
"url":"https://youtu.be/SQJ8loydnlA",
"channel_url":"https://www.youtube.com/user/lemaro1977",
"metadata":{
"view_count":"89,295 views",
"short_view_count_text":{
"simple_text":"89K views",
"accessibility_label":"89K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/SQJ8loydnlA/hqdefault.jpg?sqp=-oaymwEcCOADEI4CSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCguSQHRYzEmVcQex3hunct2FNRbQ",
"width":480,
"height":270
}
],
"duration":{
"seconds":285,
"simple_text":"4:45",
"accessibility_label":"4 minutes, 45 seconds"
},
"published":"13 years ago",
"badges":"N/A",
"owner_badges":"N/A "
}
},
{
"title":"Is there Life on Mars HD",
"description":"N/A",
"author":"Star Stuff",
"id":"tPzlY5F1ejI",
"url":"https://youtu.be/tPzlY5F1ejI",
"channel_url":"https://www.youtube.com/user/thewonderroad",
"metadata":{
"view_count":"66,903 views",
"short_view_count_text":{
"simple_text":"66K views",
"accessibility_label":"66K views"
},
"thumbnails":[
{
"url":"https://i.ytimg.com/vi/tPzlY5F1ejI/hqdefault.jpg?sqp=-oaymwEcCOADEI4CSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAr_y4W-jnZKHT8e4EHmB1y5lLmjA",
"width":480,
"height":270
}
],
"duration":{
"seconds":3020,
"simple_text":"50:20",
"accessibility_label":"50 minutes, 20 seconds"
},
"published":"7 years ago",
"badges":"N/A",
"owner_badges":"N/A "
}
}
//...
]

@@ -767,2 +123,4 @@ }

Getting details about a specific video:

@@ -826,3 +184,3 @@

</p>
</details>
</details>

@@ -869,2 +227,4 @@

---
* Subscribing/Unsubscribing to channels:

@@ -895,2 +255,58 @@ ```js

### Signing-in:
---
This library allows you to sign-in in two different ways:
- Using OAuth 2.0, easy, simple & reliable.
- Cookies, usually more complicated to get and unreliable.
OAuth 2.0:
```js
const fs = require('fs');
const Innertube = require('youtubei.js');
const creds_path = './yt_oauth_creds.json';
async function start() {
const creds = fs.existsSync(creds_path) && JSON.parse(fs.readFileSync(creds_path).toString()) || {};
const youtube = await new Innertube();
// Only triggered when signing-in.
youtube.on('auth', (data) => {
if (data.status === 'AUTHORIZATION_PENDING') {
console.info(`Hello!\nOn your phone or computer, go to ${data.verification_url} and enter the code ${data.code}`);
} else if (data.status === 'SUCCESS') {
fs.writeFileSync(creds_path, JSON.stringify({ access_token: data.access_token, refresh_token: data.refresh_token }));
console.info('Successfully signed-in, enjoy!');
}
});
// Triggered whenever the access token is refreshed.
youtube.on('update-credentials', (data) => {
fs.writeFileSync(creds_path, JSON.stringify({ access_token: data.access_token, refresh_token: data.refresh_token }));
console.info('Credentials updated!', data);
});
await youtube.signIn(creds);
//...
}
start();
```
Cookies:
```js
const Innertube = require('youtubei.js');
async function start() {
const youtube = await new Innertube(COOKIE_HERE);
//...
}
start();
```
### Downloading videos:

@@ -901,6 +317,5 @@

const Innertube = require('youtubei.js');
const COOKIE = 'YT_COOKIE_HERE';
async function start() {
const youtube = await new Innertube(COOKIE);
const youtube = await new Innertube();
const search = await youtube.search('Looking for life on Mars - documentary');

@@ -907,0 +322,0 @@ const stream = youtube.download(search.videos[0].id, {

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