UNPKG

yandex-music

Version:

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

187 lines (186 loc) 8.03 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.Playlists = void 0; const log_decorator_1 = require("../../decorators/log.decorator"); const diff_playlist_1 = require("./diff.playlist"); class Playlists { constructor(client) { this.client = client; } /** * Getting a playlist or playlist list by unique identifiers. * @param {Union} id The unique ID of the user who owns the playlist. * @param {List} kind The unique ID of the playlist or a list of them. * @returns Playlist List. */ async get(id, kind) { const params = { kinds: kind.toString() }; const playlists = await this.client.request.get(`/users/${id}/playlists`, params); return playlists.filter((playlist) => (playlist === null || playlist === void 0 ? void 0 : playlist.owner) !== undefined); } /** * Getting a playlist or playlist list by unique identifiers. * @param {Union} id The unique ID of the user who owns the playlist. * @param {Union} kind The unique ID of the playlist. * @returns Playlist List. */ async recommendations(id, kind) { return await this.client.request.get(`/users/${id}/playlists/${kind}/recommendations`); } /** * Creating a playlist. * @param {Union} id The unique ID of the owner. * @param {string} title The title of playlist. * @param {string} visibility Access modifier. * @returns New Playlist. */ async create(id, title, visibility = "public") { const params = { title, visibility }; return await this.client.request.post(`/users/${id}/playlists/create`, null, params); } /** * Deleting a playlist * @param {Union} id The unique ID of the owner. * @param {Union} kind The unique ID of the playlist. * @returns OK in success */ async delete(id, kind) { return await this.client.request.post(`/users/${id}/playlists/${kind}/delete`); } /** * Renaming a playlist * @param {Union} id The unique ID of the owner. * @param {Union} kind The unique ID of the playlist. * @param {string} value New name. * @returns OK in success */ async name(id, kind, value) { return await this.client.request.post(`/users/${id}/playlists/${kind}/name`, null, { value }); } /** * Changing the visibility of the playlist. * @param {Union} id The unique ID of the owner. * @param {Union} kind The unique ID of the playlist. * @param {string} value New visibility. * @returns OK in success */ async visibility(id, kind, value = "public") { return await this.client.request.post(`/users/${id}/playlists/${kind}/visibility`, null, { value }); } /** * Getting a playlists. * @param {Union} id The unique ID of the user who owns the playlist. * @returns Playlist List. */ async list(id) { return await this.client.request.get(`/users/${id}/playlists/list`); } /** * Changing the playlist. * @param {Union} id The unique ID of the user who owns the playlist. * @param {Union} kind The unique ID of the playlist. * @param {string} diff JSON representations of the differences between the old and new playlist. * @param {number} revision Album Revision. * @returns Modified playlist. */ async change(id, kind, diff, revision = 1) { const params = { kind: kind, revision: revision, diff: '"' + diff + '"' }; return await this.client.request.post(`/users/${id}/playlists/${kind}/change`, null, params); } /** * Adding a track to a playlist. * @param {Union} id The unique ID of the user who owns the playlist. * @param {Union} kind The unique ID of the playlist. * @param {tracks} tracks Array of tracks * @param {number} at Index to insert. * @param {number} revision Album Revision. * @returns Modified playlist. */ async insert(id, kind, tracks, at = 0, revision = 1) { const operation = diff_playlist_1.Difference.insert(at, tracks); return await this.change(id, kind, operation, revision); } /** * * @param {Union} id The unique ID of the user who owns the playlist. * @param {Union} kind The unique ID of the playlist. * @param {number} from From which index. * @param {number} to By what index. * @param {number} revision Album Revision. * @returns Modified playlist. */ async remove(id, kind, from, to, revision = 1) { const operation = diff_playlist_1.Difference.delete(from, to); return await this.change(id, kind, operation, revision); } } __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Array]), __metadata("design:returntype", Promise) ], Playlists.prototype, "get", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], Playlists.prototype, "recommendations", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, String, String]), __metadata("design:returntype", Promise) ], Playlists.prototype, "create", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], Playlists.prototype, "delete", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], Playlists.prototype, "name", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], Playlists.prototype, "visibility", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], Playlists.prototype, "list", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, Number]), __metadata("design:returntype", Promise) ], Playlists.prototype, "change", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, Array, Number, Number]), __metadata("design:returntype", Promise) ], Playlists.prototype, "insert", null); __decorate([ (0, log_decorator_1.log)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, Number, Number, Number]), __metadata("design:returntype", Promise) ], Playlists.prototype, "remove", null); exports.Playlists = Playlists;