UNPKG

yandex-music

Version:

Creative and progressive Node.js framework for applications that interact with yandex music

140 lines (139 loc) 5.92 kB
"use strict"; 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.Rotor = void 0; const log_decorator_1 = require("../decorators/log.decorator"); const radio_1 = require("./radio"); const track_1 = require("./track"); class Rotor { constructor(client) { this.client = client; this.radio = new radio_1.Radio(this); this.track = new track_1.Track(this); } /** * Getting the user status with additional fields. * @returns User status with additional fields from the radio. */ async status() { return await this.client.request.get("/rotor/account/status"); } /** * Getting the recommended stations of the current user. * @returns Recommended stations. */ async dashboard() { return await this.client.request.get("/rotor/stations/dashboard"); } /** * Getting all radio stations with user settings. * @returns Stations. */ async list() { return await this.client.request.get("/rotor/stations/list"); } /** * Getting a chain of tracks of a certain station. * @param {string} station Station. * @returns Tracks. */ async tracks(station) { return await this.client.request.get(`/rotor/station/${station}/tracks`); } /** * Getting information about the station and user settings for it. * @param {string} station Station. * @returns Tracks. */ async info(station) { return await this.client.request.get(`/rotor/station/${station}/info`); } /** * Changing the settings of a specific station. * @param {string} station Station. * @param {energy} moodEnergy Mood. * @param {diver} diversity The type of tracks. * @param {lang} language Language. * @param {settings} type Type. * @returns OK if the request is successful. */ async settings(station, moodEnergy, diversity, language = "any", type = "rotor") { const data = { moodEnergy, diversity, type, language }; return await this.client.request.post(`/rotor/station/${station}/settings3`, data); } /** * Sending a response to what is happening when listening to the radio. * @param {string} station Station * @param {FeedbackType} type Type of feedback being sent: "radioStarted", "trackStarted", "trackFinished", "skip". * @param {string} from Where the radio playback started from. * @param {string} batch_id Unique identifier of the batch of tracks. Returned when receiving tracks. * @param {number} totalPlayedSeconds How many seconds of the track were played before the action. * @param {Union} trackId The unique ID of the track. * @returns OK if the request is successful. */ async feedback(station, type, from, batch_id, totalPlayedSeconds = 0, trackId = "0") { const timestamp = Date.now(); let params = {}; let data = { type, timestamp }; if (batch_id) params = { "batch-id": batch_id }; if (trackId) data = Object.assign(Object.assign({}, data), { trackId }); if (from) data = Object.assign(Object.assign({}, data), { from }); if (totalPlayedSeconds) data = Object.assign(Object.assign({}, data), { totalPlayedSeconds }); return await this.client.request.post(`/rotor/station/${station}/feedback`, data, params); } } __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], Rotor.prototype, "status", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], Rotor.prototype, "dashboard", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], Rotor.prototype, "list", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], Rotor.prototype, "tracks", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], Rotor.prototype, "info", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, String, String, String]), __metadata("design:returntype", Promise) ], Rotor.prototype, "settings", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, String, String, Number, Object]), __metadata("design:returntype", Promise) ], Rotor.prototype, "feedback", null); exports.Rotor = Rotor;