aboutsummaryrefslogtreecommitdiff
path: root/node_modules/genius-lyrics/dist/Songs
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/genius-lyrics/dist/Songs')
-rw-r--r--node_modules/genius-lyrics/dist/Songs/Client.d.ts23
-rw-r--r--node_modules/genius-lyrics/dist/Songs/Client.js89
-rw-r--r--node_modules/genius-lyrics/dist/Songs/Song.d.ts31
-rw-r--r--node_modules/genius-lyrics/dist/Songs/Song.js103
4 files changed, 246 insertions, 0 deletions
diff --git a/node_modules/genius-lyrics/dist/Songs/Client.d.ts b/node_modules/genius-lyrics/dist/Songs/Client.d.ts
new file mode 100644
index 0000000..00b54ae
--- /dev/null
+++ b/node_modules/genius-lyrics/dist/Songs/Client.d.ts
@@ -0,0 +1,23 @@
+import { Client } from "../";
+import { Song } from "./Song";
+export interface SongSearchOptions {
+ sanitizeQuery: boolean;
+}
+export declare class SongsClient {
+ readonly client: Client;
+ /**
+ * @example const SongsClient = new Genius.Songs.Client(key);
+ */
+ constructor(client: Client);
+ /**
+ * Searches for songs for the provided query (Key is optional)
+ * @example const SearchResults = await SongsClient.search("faded");
+ */
+ search(query: string, options?: Partial<SongSearchOptions>): Promise<Song[]>;
+ /**
+ * Fetches the Song using the provided ID (Requires Key)
+ * @example const Song = await SongsClient.get(3276244);
+ */
+ get(id: number): Promise<Song>;
+ sanitizeQuery(query: string): string;
+}
diff --git a/node_modules/genius-lyrics/dist/Songs/Client.js b/node_modules/genius-lyrics/dist/Songs/Client.js
new file mode 100644
index 0000000..be25629
--- /dev/null
+++ b/node_modules/genius-lyrics/dist/Songs/Client.js
@@ -0,0 +1,89 @@
+"use strict";
+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.SongsClient = void 0;
+const got_1 = __importDefault(require("got"));
+const Song_1 = require("./Song");
+const Constants_1 = require("../Constants");
+class SongsClient {
+ /**
+ * @example const SongsClient = new Genius.Songs.Client(key);
+ */
+ constructor(client) {
+ this.client = client;
+ }
+ /**
+ * Searches for songs for the provided query (Key is optional)
+ * @example const SearchResults = await SongsClient.search("faded");
+ */
+ search(query, options) {
+ var _a, _b, _c, _d;
+ return __awaiter(this, void 0, void 0, function* () {
+ const { sanitizeQuery } = Object.assign({ sanitizeQuery: true }, options);
+ if (typeof query !== "string") {
+ throw new Error("'query' must be a type of 'string'");
+ }
+ const term = encodeURIComponent(sanitizeQuery ? this.sanitizeQuery(query) : query);
+ let result = [];
+ if (this.client.key) {
+ const data = yield this.client.api.get(`/search?q=${term}`);
+ const parsed = JSON.parse(data);
+ result = parsed.response.hits;
+ }
+ else {
+ const res = yield got_1.default.get(`${((_a = this.client.config.origin) === null || _a === void 0 ? void 0 : _a.url) || Constants_1.Constants.UN_BASE_URL}/search/multi?per_page=5&q=${term}`, Object.assign(Object.assign({}, this.client.config.requestOptions), { headers: Object.assign({ "User-Agent": Constants_1.Constants.DEF_USER_AGENT }, (_b = this.client.config.requestOptions) === null || _b === void 0 ? void 0 : _b.headers) }));
+ const parsed = JSON.parse(res.body);
+ if (!((_c = parsed === null || parsed === void 0 ? void 0 : parsed.response) === null || _c === void 0 ? void 0 : _c.sections)) {
+ throw new Error(Constants_1.Constants.NO_RESULT);
+ }
+ const __hits = parsed.response.sections.find((s) => s.type === "song");
+ if (!((_d = __hits === null || __hits === void 0 ? void 0 : __hits.hits) === null || _d === void 0 ? void 0 : _d.length)) {
+ throw new Error(Constants_1.Constants.NO_RESULT);
+ }
+ result = __hits.hits;
+ }
+ return result
+ .filter((s) => s.type === "song")
+ .map((s) => new Song_1.Song(this.client, s.result, true));
+ });
+ }
+ /**
+ * Fetches the Song using the provided ID (Requires Key)
+ * @example const Song = await SongsClient.get(3276244);
+ */
+ get(id) {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (typeof id !== "number") {
+ throw new Error("'id' must be a type of 'number'");
+ }
+ if (!this.client.key) {
+ throw new Error(Constants_1.Constants.REQUIRES_KEY);
+ }
+ const data = yield this.client.api.get(`/songs/${id}`);
+ const parsed = JSON.parse(data);
+ return new Song_1.Song(this.client, parsed.response.song, false);
+ });
+ }
+ // Source: https://github.com/farshed/genius-lyrics-api/blob/110397a9f05fe20c4ded92418430f665f074c4e4/lib/utils/index.js#L15
+ sanitizeQuery(query) {
+ return query
+ .toLowerCase()
+ .replace(/ *\([^)]*\) */g, "")
+ .replace(/ *\[[^\]]*]/, "")
+ .replace(/feat.|ft./g, "")
+ .replace(/\s+/g, " ")
+ .trim();
+ }
+}
+exports.SongsClient = SongsClient;
diff --git a/node_modules/genius-lyrics/dist/Songs/Song.d.ts b/node_modules/genius-lyrics/dist/Songs/Song.d.ts
new file mode 100644
index 0000000..8e51887
--- /dev/null
+++ b/node_modules/genius-lyrics/dist/Songs/Song.d.ts
@@ -0,0 +1,31 @@
+import { Client } from "../Client";
+import { Album } from "../Albums/Album";
+import { Artist } from "../Artists/Artist";
+export declare class Song {
+ readonly client: Client;
+ partial: boolean;
+ title: string;
+ fullTitle: string;
+ featuredTitle: string;
+ id: number;
+ thumbnail: string;
+ image: string;
+ url: string;
+ endpoint: string;
+ artist: Artist;
+ album?: Album;
+ releasedAt?: Date;
+ raw: any;
+ constructor(client: Client, res: any, partial?: boolean);
+ /**
+ * Fetches Lyrics of the Track
+ * @example const Lyrics = await Song.lyrics(true);
+ */
+ lyrics(removeChorus?: boolean): Promise<string>;
+ /**
+ * Fetches All Information about the Track and updates all the existing Properties (Requires Key)
+ * @example const NewSong = await Song.fetch();
+ */
+ fetch(): Promise<this>;
+ removeChorus(lyrics: string): string;
+}
diff --git a/node_modules/genius-lyrics/dist/Songs/Song.js b/node_modules/genius-lyrics/dist/Songs/Song.js
new file mode 100644
index 0000000..6b577c8
--- /dev/null
+++ b/node_modules/genius-lyrics/dist/Songs/Song.js
@@ -0,0 +1,103 @@
+"use strict";
+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Song = void 0;
+const got_1 = __importDefault(require("got"));
+const cheerio_1 = __importDefault(require("cheerio"));
+const Album_1 = require("../Albums/Album");
+const Artist_1 = require("../Artists/Artist");
+const Constants_1 = require("../Constants");
+class Song {
+ constructor(client, res, partial = false) {
+ this.client = client;
+ this.partial = partial;
+ this.title = res.title;
+ this.fullTitle = res.full_title;
+ this.featuredTitle = res.title_with_featured;
+ this.id = +res.id;
+ this.thumbnail = res.header_image_thumbnail_url;
+ this.image = res.header_image_url;
+ this.url = res.url;
+ this.endpoint = res.api_path;
+ this.artist = new Artist_1.Artist(this.client, res.primary_artist, true);
+ this.partial = partial;
+ this.album =
+ !this.partial && res.album
+ ? new Album_1.Album(res.album, this.artist)
+ : undefined;
+ this.releasedAt =
+ !this.partial && res.release_date
+ ? new Date(res.release_date)
+ : undefined;
+ this.raw = res;
+ }
+ /**
+ * Fetches Lyrics of the Track
+ * @example const Lyrics = await Song.lyrics(true);
+ */
+ lyrics(removeChorus = false) {
+ var _a;
+ return __awaiter(this, void 0, void 0, function* () {
+ if (typeof removeChorus !== "boolean") {
+ throw new Error("'removeChorus' must be a type of 'boolean'");
+ }
+ const { body } = yield got_1.default.get(this.url, Object.assign(Object.assign({}, this.client.config.requestOptions), { headers: Object.assign({ "User-Agent": Constants_1.Constants.DEF_USER_AGENT }, (_a = this.client.config.requestOptions) === null || _a === void 0 ? void 0 : _a.headers) }));
+ const $ = cheerio_1.default.load(body);
+ const selectors = [
+ () => $(".lyrics").text().trim(),
+ () => $("div[class*='Lyrics__Container']")
+ .toArray()
+ .map((x) => {
+ const ele = $(x);
+ ele.find("br").replaceWith("\n");
+ return ele.text().trim();
+ })
+ .join("\n\n")
+ .trim(),
+ ];
+ for (const x of selectors) {
+ const lyrics = x();
+ if (lyrics === null || lyrics === void 0 ? void 0 : lyrics.length) {
+ return removeChorus ? this.removeChorus(lyrics) : lyrics;
+ }
+ }
+ throw new Error(Constants_1.Constants.NO_RESULT);
+ });
+ }
+ /**
+ * Fetches All Information about the Track and updates all the existing Properties (Requires Key)
+ * @example const NewSong = await Song.fetch();
+ */
+ fetch() {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (!this.client.key) {
+ throw new Error(Constants_1.Constants.REQUIRES_KEY);
+ }
+ const data = yield this.client.api.get(`/songs/${this.id}`);
+ const parsed = JSON.parse(data);
+ this.album = parsed.response.song.album
+ ? new Album_1.Album(parsed.response.song.album, this.artist)
+ : undefined;
+ this.releasedAt = parsed.response.song.release_date
+ ? new Date(parsed.response.song.release_date)
+ : undefined;
+ this.partial = false;
+ return this;
+ });
+ }
+ removeChorus(lyrics) {
+ return lyrics.replace(/^\[[^\]]+\]$/g, "");
+ }
+}
+exports.Song = Song;