yandex-music
Version:
Creative and progressive Node.js framework for applications that interact with yandex music
96 lines (95 loc) • 3.89 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Track = void 0;
const crypto_1 = require("crypto");
const log_decorator_1 = require("../decorators/log.decorator");
const utils_1 = require("../utils");
class Track {
constructor(client) {
this.client = client;
}
/**
* Getting more information about the track.
* @param {Union} id The unique ID of the track.
* @returns Additional information about the track.
*/
async supplement(id) {
return await this.client.request.get(`/tracks/${id}/supplement`);
}
/**
* Getting similar tracks.
* @param {Union} id The unique ID of the track.
* @returns Similar tracks to the track..
*/
async similar(id) {
return await this.client.request.get(`/tracks/${id}/similar`);
}
/**
* Getting the track/tracks.
* @param {List} ids The unique identifier of the track or tracks.
* @returns Track or Tracks.
*/
async get(ids) {
const [url, params] = (0, utils_1.list)("track", ids);
return await this.client.request.get(url, params);
}
/**
* Getting the track download info.
* @param {Union} id The unique identifier of the track or tracks.
* @returns Track download info.
*/
async downloadInfo(id) {
return await this.client.request.get(`/tracks/${id}/download-info`);
}
/**
* Getting the track download url.
* @param {string} url Track download info.
* @returns Track download url.
*/
async downloadUrl(url) {
const info = await this.client.request.directLink(url, { format: "json" });
const trackUrl = `XGRlBW9FXlekgbPrRHuSiA${info.path.substring(1)}${info.s}`;
const hashedUrl = (0, crypto_1.createHash)("md5").update(trackUrl).digest("hex");
return `https://${info.host}/get-mp3/${hashedUrl}/${info.ts}${info.path}`;
}
}
__decorate([
(0, log_decorator_1.log)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Track.prototype, "supplement", null);
__decorate([
(0, log_decorator_1.log)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Track.prototype, "similar", null);
__decorate([
(0, log_decorator_1.log)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", Promise)
], Track.prototype, "get", null);
__decorate([
(0, log_decorator_1.log)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Track.prototype, "downloadInfo", null);
__decorate([
(0, log_decorator_1.log)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], Track.prototype, "downloadUrl", null);
exports.Track = Track;