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

ytmusic_api_unofficial

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ytmusic_api_unofficial - npm Package Compare versions

Comparing version 1.1.0-beta.1 to 1.1.0-beta.1.2

dist/errors/YTjsError.d.ts

14

dist/errors/errorCodes.d.ts

@@ -1,11 +0,3 @@

/**
* @typedef {Object} YTErrorCodes
*
* @property {'UnrecognizedError'} UnrecognizedError
*/
declare const _default: {
UnrecognizedError: string;
BadRequest: string;
FAILED_PRECONDITION: string;
};
export default _default;
declare const ErrorCode: any;
export default ErrorCode;
export type ErrorCodeType = typeof ErrorCode[keyof typeof ErrorCode];
"use strict";
/**
* @typedef {Object} YTErrorCodes
*
* @property {'UnrecognizedError'} UnrecognizedError
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
const ErrorCode = {
UnrecognizedError: 'UnrecognizedError',
BadRequest: 'BadRequest',
FAILED_PRECONDITION: 'FAILED_PRECONDITION',
VIDEO_NOT_FOUND: 'VIDEO_NOT_FOUND',
INVALID_ARGUMENT: 'INVALID_ARGUMENT',
};
exports.default = ErrorCode;

@@ -1,1 +0,2 @@

export declare function makeAxiosError(message: string, error: any, ...args: any[]): Error;
export declare function makeAxiosError(message: any, error: any, ...args: any[]): Error;
export declare const YTjsErrorError: any;

@@ -6,5 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.makeAxiosError = void 0;
exports.YTjsErrorError = exports.makeAxiosError = void 0;
const Messages_1 = __importDefault(require("./Messages"));
const errorCodes_1 = __importDefault(require("./errorCodes"));
const errorCodes_2 = __importDefault(require("./errorCodes"));
function makeAxiosError(message, error, ...args) {

@@ -24,1 +25,42 @@ const msg = (message in errorCodes_1.default) ? Messages_1.default[message] : null;

exports.makeAxiosError = makeAxiosError;
/**
* Extend an error of some sort into a YTjsError.
* @param {Error} Base Base error to extend
* @returns {YTjsError}
* @ignore
*/
function makeYTjsErrorError(Base) {
return class YTjsError extends Base {
constructor(code, ...args) {
var _a;
super(message(code, args));
this.code = code;
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, YTjsError);
}
get name() {
return `${super.name} [${this.code}]`;
}
};
}
/**
* Format the message for an error.
* @param {string} code The error code
* @param {Array<*>} args Arguments to pass for util format or as function args
* @returns {string} Formatted string
* @ignore
*/
function message(code, args) {
if (!(code in errorCodes_2.default))
throw new Error('Error code must be a valid YTjsErrorCodes');
const msg = Messages_1.default[code];
if (!msg)
throw new Error(`No message associated with error code: ${code}.`);
if (typeof msg === 'function') { // @ts-ignore
return msg(...args);
}
if (!(args === null || args === void 0 ? void 0 : args.length))
return msg;
args.unshift(msg);
return String(...args);
}
exports.YTjsErrorError = makeYTjsErrorError(Error);
declare const Messages: {
[x: string]: (error: any) => string;
[x: number]: (error: any) => string;
};
export default Messages;

@@ -10,4 +10,6 @@ "use strict";

[errorCodes_1.default.FAILED_PRECONDITION]: (error) => `${error.code}. The request failed because a precondition was not met. Message: ${error.message}\nPlease contact the developer of the library (https://instagram.com/leko_system).`,
[errorCodes_1.default.UnrecognizedError]: (error) => `An unrecognized error has occurred. Please contact the developer of the library (https://instagram.com/leko_system).\nError code: ${error.code}`
[errorCodes_1.default.UnrecognizedError]: (error) => `An unrecognized error has occurred. Please contact the developer of the library (https://instagram.com/leko_system).\nError code: ${error.code}`,
[errorCodes_1.default.VIDEO_NOT_FOUND]: (error) => `The video was not found. ID: ${error.id}`,
[errorCodes_1.default.INVALID_ARGUMENT]: (message) => `The argument was invalid. Message: ${message}`,
};
exports.default = Messages;

@@ -11,2 +11,5 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -20,2 +23,4 @@ exports.TypeSearch = void 0;

const Playlist_1 = require("../models/Playlist");
const errors_1 = require("../errors");
const errorCodes_1 = __importDefault(require("../errors/errorCodes"));
exports.default = {

@@ -121,4 +126,8 @@ search: (query, type) => __awaiter(void 0, void 0, void 0, function* () {

get: (id) => __awaiter(void 0, void 0, void 0, function* () {
return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
return resolve(new Music_1.Music((0, extract_1.extract_dataFromGetData)(yield GetData(id))));
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
GetData(id).then((e) => {
return resolve(new Music_1.Music((0, extract_1.extract_dataFromGetData)(e)));
}).catch((e) => __awaiter(void 0, void 0, void 0, function* () {
reject(e);
}));
}));

@@ -183,3 +192,7 @@ }),

}).then((res) => {
resolve(Object.assign({ browseId: res.data.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[1].tabRenderer.endpoint.browseEndpoint.browseId }, res.data.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content.musicQueueRenderer.content.playlistPanelRenderer.contents[0].playlistPanelVideoRenderer));
if (res.data.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[1].tabRenderer.endpoint) {
resolve(Object.assign({ browseId: res.data.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[1].tabRenderer.endpoint.browseEndpoint.browseId }, res.data.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content.musicQueueRenderer.content.playlistPanelRenderer.contents[0].playlistPanelVideoRenderer));
}
else
reject(new errors_1.YTjsErrorError(errorCodes_1.default.VIDEO_NOT_FOUND, id));
}).catch(reject);

@@ -186,0 +199,0 @@ });

@@ -12,2 +12,3 @@ import { Artwork } from "./Artwork";

browseId: string;
isAudioOnly: boolean;
autoMix: boolean;

@@ -14,0 +15,0 @@ constructor(data: any, autoMix?: boolean);

@@ -11,5 +11,11 @@ "use strict";

this.artists = data.artists;
this.artists.toString = () => {
const artists = data.artists = [...data.artists];
// Return the artists in string format with a comma between each artist and if it's the last artist add '&'
return artists.map((artist, index) => `${artist.name}${index === artists.length - 1 ? '' : index === artists.length - 2 ? ' &' : ','} `).join('');
};
this.duration = data.duration;
this.typeVideo = data.type;
this.browseId = data.browseId;
this.isAudioOnly = data.type.includes('ATV');
if (autoMix)

@@ -16,0 +22,0 @@ this.autoMix = autoMix;

@@ -10,17 +10,17 @@ "use strict";

function extract_dataFromGetData(data) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
let artists = [], album, date;
for (let item of ((_a = data === null || data === void 0 ? void 0 : data.longBylineText) === null || _a === void 0 ? void 0 : _a.runs) || []) {
// Get Author(s)
if ((_f = (_e = (_d = (_c = (_b = item.navigationEndpoint) === null || _b === void 0 ? void 0 : _b.browseEndpoint) === null || _c === void 0 ? void 0 : _c.browseEndpointContextSupportedConfigs) === null || _d === void 0 ? void 0 : _d.browseEndpointContextMusicConfig) === null || _e === void 0 ? void 0 : _e.pageType) === null || _f === void 0 ? void 0 : _f.includes('ARTIST')) {
if (((_f = (_e = (_d = (_c = (_b = item.navigationEndpoint) === null || _b === void 0 ? void 0 : _b.browseEndpoint) === null || _c === void 0 ? void 0 : _c.browseEndpointContextSupportedConfigs) === null || _d === void 0 ? void 0 : _d.browseEndpointContextMusicConfig) === null || _e === void 0 ? void 0 : _e.pageType) === null || _f === void 0 ? void 0 : _f.includes('ARTIST')) || ((_l = (_k = (_j = (_h = (_g = item.navigationEndpoint) === null || _g === void 0 ? void 0 : _g.browseEndpoint) === null || _h === void 0 ? void 0 : _h.browseEndpointContextSupportedConfigs) === null || _j === void 0 ? void 0 : _j.browseEndpointContextMusicConfig) === null || _k === void 0 ? void 0 : _k.pageType) === null || _l === void 0 ? void 0 : _l.includes('USER'))) {
artists.push(new Artist_1.Artist({
name: item.text,
id: (_h = (_g = item.navigationEndpoint) === null || _g === void 0 ? void 0 : _g.browseEndpoint) === null || _h === void 0 ? void 0 : _h.browseId
id: (_o = (_m = item.navigationEndpoint) === null || _m === void 0 ? void 0 : _m.browseEndpoint) === null || _o === void 0 ? void 0 : _o.browseId
}));
// Get Album if exists
}
else if ((_m = (_l = (_k = (_j = item.navigationEndpoint) === null || _j === void 0 ? void 0 : _j.browseEndpoint) === null || _k === void 0 ? void 0 : _k.browseEndpointContextSupportedConfigs) === null || _l === void 0 ? void 0 : _l.browseEndpointContextMusicConfig) === null || _m === void 0 ? void 0 : _m.pageType.includes('ALBUM')) {
else if ((_s = (_r = (_q = (_p = item.navigationEndpoint) === null || _p === void 0 ? void 0 : _p.browseEndpoint) === null || _q === void 0 ? void 0 : _q.browseEndpointContextSupportedConfigs) === null || _r === void 0 ? void 0 : _r.browseEndpointContextMusicConfig) === null || _s === void 0 ? void 0 : _s.pageType.includes('ALBUM')) {
album = new Album_1.Album({
name: item.text,
id: (_p = (_o = item.navigationEndpoint) === null || _o === void 0 ? void 0 : _o.browseEndpoint) === null || _p === void 0 ? void 0 : _p.browseId
id: (_u = (_t = item.navigationEndpoint) === null || _t === void 0 ? void 0 : _t.browseEndpoint) === null || _u === void 0 ? void 0 : _u.browseId
});

@@ -44,4 +44,4 @@ // Get Date if exists

duration: new Duration_1.Duration({
seconds: timeToSec(((_s = (_r = (_q = data.lengthText) === null || _q === void 0 ? void 0 : _q.runs) === null || _r === void 0 ? void 0 : _r[0]) === null || _s === void 0 ? void 0 : _s.text) || '0:00'),
text: (_v = (_u = (_t = data.lengthText) === null || _t === void 0 ? void 0 : _t.runs) === null || _u === void 0 ? void 0 : _u[0]) === null || _v === void 0 ? void 0 : _v.text,
seconds: timeToSec(((_x = (_w = (_v = data.lengthText) === null || _v === void 0 ? void 0 : _v.runs) === null || _w === void 0 ? void 0 : _w[0]) === null || _x === void 0 ? void 0 : _x.text) || '0:00'),
text: (_0 = (_z = (_y = data.lengthText) === null || _y === void 0 ? void 0 : _y.runs) === null || _z === void 0 ? void 0 : _z[0]) === null || _0 === void 0 ? void 0 : _0.text,
label: data.lengthText.accessibility.accessibilityData.label

@@ -48,0 +48,0 @@ })

@@ -18,2 +18,3 @@ "use strict";

const errors_1 = require("../errors");
const errorCodes_1 = __importDefault(require("../errors/errorCodes"));
let Defaultheaders = {

@@ -42,4 +43,9 @@ 'Content-Type': 'application/json',

.catch((err) => {
var _a, _b, _c, _d, _e;
reject((0, errors_1.makeAxiosError)(((_c = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.status) || err.message, err, (_e = (_d = err.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error));
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
if ((_c = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.status) {
if (errorCodes_1.default[(_f = (_e = (_d = err.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.status]) {
return reject(new errors_1.YTjsErrorError((_j = (_h = (_g = err.response) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.error) === null || _j === void 0 ? void 0 : _j.status, (_p = (_o = (_m = (_l = (_k = err.response) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.error) === null || _m === void 0 ? void 0 : _m.errors) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.message));
}
}
reject((0, errors_1.makeAxiosError)(((_s = (_r = (_q = err.response) === null || _q === void 0 ? void 0 : _q.data) === null || _r === void 0 ? void 0 : _r.error) === null || _s === void 0 ? void 0 : _s.status) || err.message, err, (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.data) === null || _u === void 0 ? void 0 : _u.error));
});

@@ -46,0 +52,0 @@ });

{
"name": "ytmusic_api_unofficial",
"version": "1.1.0-beta.1",
"version": "1.1.0-beta.1.2",
"description": "A simple API to get music from YouTube Music",

@@ -5,0 +5,0 @@ "scripts": {

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