refactor!: welp, a lot of stuff

- Use the OS temp folder to cache the player, closes #57.
- Added support for editing channel name, closes #40.
- Added support for editing channel description.
- Added support for retrieving basic channel analytics, closes #54.
- Moved `Innertube#getAccountInfo()` to `Innertube#account`, and renamed it to `getInfo()`.
- `getInfo()` is now able to return email, channel id, etc.
- Improved jsdoc.
This commit is contained in:
LuanRT
2022-05-27 08:17:16 -03:00
parent 865b6870a1
commit a85e9ef667
25 changed files with 1275 additions and 754 deletions

View File

@@ -1,7 +1,5 @@
'use strict';
const Utils = require('./Utils');
module.exports = {
URLS: {
YT_BASE: 'https://www.youtube.com',
@@ -44,15 +42,15 @@ module.exports = {
}
},
STREAM_HEADERS: {
'Accept': '*/*',
'User-Agent': Utils.getRandomUserAgent('desktop').userAgent,
'Connection': 'keep-alive',
'Origin': 'https://www.youtube.com',
'Referer': 'https://www.youtube.com',
'accept': '*/*',
'connection': 'keep-alive',
'origin': 'https://www.youtube.com',
'referer': 'https://www.youtube.com',
'DNT': '?1'
},
INNERTUBE_HEADERS_BASE: {
'accept': '*/*',
'accept-encoding': 'gzip, deflate',
'content-type': 'application/json',
},
METADATA_KEYS: [

View File

@@ -4,7 +4,12 @@ const Axios = require('axios');
const Utils = require('./Utils');
const Constants = require('./Constants');
/** @namespace */
class Request {
/**
* @param {Innertube} session
* @constructor
*/
constructor(session) {
this.session = session;
@@ -68,14 +73,17 @@ class Request {
}, (error) => {
throw new Utils.InnertubeError(error.message, error);
});
/**
* Standardizes the API response and catches all errors.
*/
this.instance.interceptors.response.use((res) => {
const response = {
success: res.status === 200,
status_code: res.status,
data: res.data
};
if (res.status !== 200)
throw new Utils.InnertubeError(`Request to ${res.config.url} failed with status code ${res.status} ${res.statusText}`, response);
@@ -89,7 +97,9 @@ class Request {
}
/**
* Adjusts the context according to the given client.
* @todo refactor this?
* @returns
*/
#adjustContext(ctx, client) {
switch (client) {

View File

@@ -4,6 +4,7 @@ const Crypto = require('crypto');
const UserAgent = require('user-agents');
const Flatten = require('flat');
/** @namespace */
class InnertubeError extends Error {
constructor (message, info) {
super(message);