ytmusic_api_unofficial
Advanced tools
Comparing version 2.0.0-beta.1.6.5 to 2.0.0-beta.1.6.7
@@ -11,2 +11,3 @@ import { AvailableCountries, AvailableFormat, AvailableQuality, AvailableTypes } from "./utils/default"; | ||
* @param filter ex: "SONG" (Check available types) | ||
* @param fetch ex: false (If you want to get complete results, but it will take more time) | ||
* @example | ||
@@ -16,3 +17,3 @@ * const search = await client.search("Hello Adele", "SONG") | ||
*/ | ||
export declare function search(query: string, filter: AvailableTypes): Promise<{ | ||
export declare function search(query: string, filter?: AvailableTypes, fetch?: false): Promise<{ | ||
query: string; | ||
@@ -19,0 +20,0 @@ filter: AvailableTypes; |
@@ -26,2 +26,3 @@ "use strict"; | ||
* @param filter ex: "SONG" (Check available types) | ||
* @param fetch ex: false (If you want to get complete results, but it will take more time) | ||
* @example | ||
@@ -31,13 +32,15 @@ * const search = await client.search("Hello Adele", "SONG") | ||
*/ | ||
function search(query, filter) { | ||
function search(query, filter, fetch) { | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
filter = filter === null || filter === void 0 ? void 0 : filter.toLowerCase(); | ||
if (filter && !default_1.all_TYPES.includes(filter)) | ||
var _a; | ||
const hasFilter = !!filter; | ||
filter = (_a = filter === null || filter === void 0 ? void 0 : filter.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase(); | ||
if (hasFilter && !default_1.all_TYPES.includes(filter)) | ||
return reject((0, error_1.error)(1001, `Available types: ${default_1.all_TYPES.join(", ")}`)); | ||
const result = { query, filter, content: [] }; | ||
if ((0, utils_1.getYTIdFromText)(query).type) { | ||
const result = { query, filter: hasFilter ? filter : false, content: [] }; | ||
if ((0, utils_1.getYTIdFromText)(query).isValidId) { | ||
result.content = [yield this.get(query).catch(reject)]; | ||
return resolve(result); | ||
} | ||
(0, request_1.default)('search', { query, params: default_1.TYPE_SEARCH_CODE[filter] }).then((response) => { | ||
(0, request_1.default)('search', { query, params: hasFilter ? default_1.TYPE_SEARCH_CODE[filter] : '' }).then((response) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
@@ -72,3 +75,3 @@ if (response.content) | ||
(0, utils_1.parseSearchResults)(shelf_contents, category).forEach((content, i) => { | ||
if (!content || (filter && (content === null || content === void 0 ? void 0 : content.resultType) !== filter)) | ||
if (!content || (hasFilter && (content === null || content === void 0 ? void 0 : content.resultType) !== filter)) | ||
return; | ||
@@ -78,2 +81,17 @@ result.content.push(content); | ||
} | ||
if (fetch) { | ||
result.content = result.content.filter((content) => !!(content === null || content === void 0 ? void 0 : content.id)); | ||
const promises = result.content.map((content) => __awaiter(this, void 0, void 0, function* () { | ||
if (content.id) | ||
return yield this.get(content.id).catch((e) => { | ||
process.emitWarning(`Please report this issue on the GitHub repository, this is a bug.: ${e}`, 'uncaughtException'); | ||
console.log(e); | ||
return null; | ||
}); | ||
else | ||
return null; | ||
})); | ||
result.content = yield Promise.all(promises); | ||
result.content = result.content.filter((content) => !!(content === null || content === void 0 ? void 0 : content.id)); | ||
} | ||
return resolve(result); | ||
@@ -86,3 +104,3 @@ } | ||
} | ||
}).catch((e) => { | ||
})).catch((e) => { | ||
reject(e); | ||
@@ -89,0 +107,0 @@ }); |
@@ -9,3 +9,3 @@ "use strict"; | ||
exports.UN_TYPES = ["song", "video", "playlist", "artist", "podcast", "profile", "station", "episode"]; | ||
exports.all_TYPES = ["album", ...exports.UN_TYPES]; | ||
exports.all_TYPES = ['false', "album", ...exports.UN_TYPES]; | ||
exports.TYPE_SEARCH_CODE = { | ||
@@ -12,0 +12,0 @@ song: 'EgWKAQIIAWoOEAMQBBAJEA4QChAFEBU%3D', |
@@ -17,3 +17,4 @@ import Music from "../classes/Music"; | ||
export declare function getYTIdFromText(text: string, precise?: boolean): { | ||
id: string; | ||
id: any; | ||
isValidId: boolean; | ||
type: null | string; | ||
@@ -20,0 +21,0 @@ }; |
@@ -103,3 +103,3 @@ "use strict"; | ||
let searchResult = {}; | ||
searchResult.resultType = detectType((0, responseBuilder_1.nav)(response, responseBuilder_1.SUBTITLE)); | ||
searchResult.resultType = detectType((0, responseBuilder_1.nav)(response, responseBuilder_1.SUBTITLE), true); | ||
searchResult.category = (0, responseBuilder_1.nav)(response, responseBuilder_1.CARD_SHELF_TITLE); | ||
@@ -374,3 +374,5 @@ searchResult.thumbnails = (0, responseBuilder_1.nav)(response, responseBuilder_1.THUMBNAILS, true); | ||
const reg = /https?:\/\/(?:music\.|www\.)?youtube\.com\/(?:watch\?v=|v\/|channel\/|playlist\?list=)([A-Za-z0-9_-]+)/m; | ||
const id = text.match(reg); | ||
let id = null; | ||
if (!text.includes(' ')) | ||
id = text.match(reg); | ||
if (id) { | ||
@@ -380,6 +382,6 @@ const type = getTypeByID(id[1]); | ||
id[1] = 'VL' + id[1]; | ||
return { id: id[1], type: type }; | ||
return { id: id[1], type: type, isValidId: true }; | ||
} | ||
else | ||
return { id: text, type: getTypeByID(text) }; | ||
return { isValidId: false, id: text, type: getTypeByID(text) }; | ||
} | ||
@@ -386,0 +388,0 @@ exports.getYTIdFromText = getYTIdFromText; |
{ | ||
"name": "ytmusic_api_unofficial", | ||
"version": "2.0.0-beta.1.6.5", | ||
"version": "2.0.0-beta.1.6.7", | ||
"description": "A simple API to get music from YouTube Music", | ||
@@ -46,9 +46,9 @@ "scripts": { | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "^7.47.0", | ||
"@types/node": "^20.14.2", | ||
"comment-parser": "^1.4.1", | ||
"fs-extra": "^11.2.0", | ||
"nodemon": "^3.1.3", | ||
"typescript": "^5.4.5", | ||
"vitepress": "^1.2.3", | ||
"@microsoft/api-extractor": "^7.47.0", | ||
"comment-parser": "^1.4.1", | ||
"fs-extra": "^11.2.0" | ||
"vitepress": "^1.2.3" | ||
}, | ||
@@ -55,0 +55,0 @@ "release": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
168953
2310
7