mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
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:
@@ -7,6 +7,7 @@ const Utils = require('../utils/Utils');
|
||||
const Constants = require('../utils/Constants');
|
||||
const UserAgent = require('user-agents');
|
||||
|
||||
/** @namespace */
|
||||
class SessionBuilder {
|
||||
#config;
|
||||
|
||||
@@ -18,6 +19,10 @@ class SessionBuilder {
|
||||
#context;
|
||||
#player;
|
||||
|
||||
/**
|
||||
* @param {string} config
|
||||
* @constructor
|
||||
*/
|
||||
constructor(config) {
|
||||
this.#config = config;
|
||||
}
|
||||
@@ -42,6 +47,10 @@ class SessionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a valid context object.
|
||||
* @returns
|
||||
*/
|
||||
#buildContext() {
|
||||
const user_agent = new UserAgent({ deviceCategory: 'desktop' });
|
||||
|
||||
@@ -70,6 +79,11 @@ class SessionBuilder {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves initial configuration such as keys,
|
||||
* client data, etc.
|
||||
* @returns Promise.<object>
|
||||
*/
|
||||
async #getYtConfig() {
|
||||
const response = await Axios.get(`${Constants.URLS.YT_BASE}/sw.js_data`).catch((err) => err);
|
||||
|
||||
@@ -82,6 +96,10 @@ class SessionBuilder {
|
||||
return JSON.parse(response.data.replace(')]}\'', ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrives the YouTube player id.
|
||||
* @returns {Promise.<string>
|
||||
*/
|
||||
async #getPlayerId() {
|
||||
const response = await Axios.get(`${Constants.URLS.YT_BASE}/iframe_api`).catch((err) => err);
|
||||
|
||||
@@ -94,26 +112,32 @@ class SessionBuilder {
|
||||
return Utils.getStringBetweenStrings(response.data, 'player\\/', '\\/');
|
||||
}
|
||||
|
||||
/** @readonly */
|
||||
get key() {
|
||||
return this.#key;
|
||||
}
|
||||
|
||||
/** @readonly */
|
||||
get context() {
|
||||
return this.#context;
|
||||
}
|
||||
|
||||
/** @readonly */
|
||||
get api_version() {
|
||||
return this.#api_version;
|
||||
}
|
||||
|
||||
/** @readonly */
|
||||
get client_version() {
|
||||
return this.#client_version;
|
||||
}
|
||||
|
||||
/** @readonly */
|
||||
get client_name() {
|
||||
return this.#client_name;
|
||||
}
|
||||
|
||||
/** @readonly */
|
||||
get player() {
|
||||
return this.#player;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user