node-youtube-music
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -5,6 +5,3 @@ "use strict"; | ||
// https://music.youtube.com/browse?id=MPREb_iWdtzQKst5b | ||
const main = () => src_1.listMusicsFromAlbum('MPREb_iWdtzQKst5b', { | ||
lang: 'fr', | ||
country: 'FR', | ||
}); | ||
const main = () => src_1.listMusicsFromAlbum('MPREb_iWdtzQKst5b'); | ||
main().then((results) => console.log(results)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const src_1 = require("../src"); | ||
const main = () => src_1.listMusicsFromPlaylist('VLRDCLAK5uy_n20FRYQXNt1p1wS55Nj2r14IouO5weaYU', { | ||
lang: 'fr', | ||
country: 'FR', | ||
}); | ||
const main = () => src_1.listMusicsFromPlaylist('VLRDCLAK5uy_n20FRYQXNt1p1wS55Nj2r14IouO5weaYU'); | ||
main().then((results) => console.log(results)); |
@@ -14,3 +14,3 @@ "use strict"; | ||
const main = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const music = (yield src_1.searchMusics('Liem if only', { lang: 'fr', country: 'FR' })).shift(); | ||
const music = (yield src_1.searchMusics('Liem if only')).shift(); | ||
if (!music) { | ||
@@ -21,7 +21,4 @@ throw Error(); | ||
return; | ||
src_1.getSuggestions(music.youtubeId, { | ||
lang: 'fr', | ||
country: 'FR', | ||
}); | ||
src_1.getSuggestions(music.youtubeId); | ||
}); | ||
main().then((results) => console.log(results)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const src_1 = require("../src"); | ||
const main = () => src_1.searchMusics('DJOKO', { lang: 'fr', country: 'FR' }); | ||
const main = () => src_1.searchMusics('DJOKO'); | ||
main().then((results) => console.log(results)); |
declare const _default: { | ||
body: (lang?: string | undefined, country?: string | undefined) => { | ||
body: { | ||
context: { | ||
@@ -8,4 +8,2 @@ capabilities: {}; | ||
clientVersion: string; | ||
hl: string; | ||
gl: string; | ||
}; | ||
@@ -12,0 +10,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
body: (lang, country) => ({ | ||
body: { | ||
context: { | ||
@@ -12,7 +12,5 @@ capabilities: {}, | ||
clientVersion: '0.1', | ||
hl: lang !== null && lang !== void 0 ? lang : 'en', | ||
gl: country !== null && country !== void 0 ? country : 'GB', | ||
}, | ||
}, | ||
}), | ||
}, | ||
}; |
import { MusicVideo } from './models'; | ||
export declare const parseListMusicsFromAlbumBody: (body: any) => MusicVideo[]; | ||
export declare function listMusicsFromAlbum(albumId: string, options?: { | ||
lang?: string; | ||
country?: string; | ||
}): Promise<MusicVideo[]>; | ||
export declare function listMusicsFromAlbum(albumId: string): Promise<MusicVideo[]>; |
@@ -39,10 +39,8 @@ "use strict"; | ||
exports.parseListMusicsFromAlbumBody = parseListMusicsFromAlbumBody; | ||
function listMusicsFromAlbum(albumId, options) { | ||
var _a; | ||
function listMusicsFromAlbum(albumId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield got_1.default.post('https://music.youtube.com/youtubei/v1/browse?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', { | ||
json: Object.assign(Object.assign({}, context_1.default.body(options === null || options === void 0 ? void 0 : options.lang, options === null || options === void 0 ? void 0 : options.country)), { browseId: albumId }), | ||
json: Object.assign(Object.assign({}, context_1.default.body), { browseId: albumId }), | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -49,0 +47,0 @@ }, |
@@ -21,5 +21,2 @@ import { MusicVideo } from './models'; | ||
}) => MusicVideo[]; | ||
export declare function listMusicsFromPlaylist(playlistId: string, options?: { | ||
lang?: string; | ||
country?: string; | ||
}): Promise<MusicVideo[]>; | ||
export declare function listMusicsFromPlaylist(playlistId: string): Promise<MusicVideo[]>; |
@@ -34,10 +34,8 @@ "use strict"; | ||
exports.parseListMusicsFromPlaylistBody = parseListMusicsFromPlaylistBody; | ||
function listMusicsFromPlaylist(playlistId, options) { | ||
var _a; | ||
function listMusicsFromPlaylist(playlistId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield got_1.default.post('https://music.youtube.com/youtubei/v1/browse?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', { | ||
json: Object.assign(Object.assign({}, context_1.default.body(options === null || options === void 0 ? void 0 : options.lang, options === null || options === void 0 ? void 0 : options.country)), { browseId: playlistId }), | ||
json: Object.assign(Object.assign({}, context_1.default.body), { browseId: playlistId }), | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -44,0 +42,0 @@ }, |
import { AlbumPreview } from './models'; | ||
export declare const parseSearchAlbumsBody: (body: any) => AlbumPreview[]; | ||
export declare function searchAlbums(query: string, options?: { | ||
lang?: string; | ||
country?: string; | ||
}): Promise<AlbumPreview[]>; | ||
export declare function searchAlbums(query: string): Promise<AlbumPreview[]>; |
@@ -35,10 +35,8 @@ "use strict"; | ||
exports.parseSearchAlbumsBody = parseSearchAlbumsBody; | ||
function searchAlbums(query, options) { | ||
var _a; | ||
function searchAlbums(query) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield got_1.default.post('https://music.youtube.com/youtubei/v1/search?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', { | ||
json: Object.assign(Object.assign({}, context_1.default.body(options === null || options === void 0 ? void 0 : options.lang, options === null || options === void 0 ? void 0 : options.country)), { params: 'EgWKAQIYAWoKEAkQAxAEEAUQCg%3D%3D', query }), | ||
json: Object.assign(Object.assign({}, context_1.default.body), { params: 'EgWKAQIYAWoKEAkQAxAEEAUQCg%3D%3D', query }), | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -45,0 +43,0 @@ }, |
@@ -5,5 +5,2 @@ import { MusicVideo } from './models'; | ||
}) => MusicVideo[]; | ||
export declare function searchMusics(query: string, options?: { | ||
lang?: string; | ||
country?: string; | ||
}): Promise<MusicVideo[]>; | ||
export declare function searchMusics(query: string): Promise<MusicVideo[]>; |
@@ -34,10 +34,8 @@ "use strict"; | ||
exports.parseSearchMusicsBody = parseSearchMusicsBody; | ||
function searchMusics(query, options) { | ||
var _a; | ||
function searchMusics(query) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield got_1.default.post('https://music.youtube.com/youtubei/v1/search?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', { | ||
json: Object.assign(Object.assign({}, context_1.default.body(options === null || options === void 0 ? void 0 : options.lang, options === null || options === void 0 ? void 0 : options.country)), { params: 'EgWKAQIIAWoKEAoQCRADEAQQBQ%3D%3D', query }), | ||
json: Object.assign(Object.assign({}, context_1.default.body), { params: 'EgWKAQIIAWoKEAoQCRADEAQQBQ%3D%3D', query }), | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -49,3 +47,3 @@ }, | ||
} | ||
catch (_b) { | ||
catch (_a) { | ||
return []; | ||
@@ -52,0 +50,0 @@ } |
import { PlaylistPreview } from './models'; | ||
export declare const parseSearchPlaylistsBody: (body: any, onlyOfficialPlaylists: boolean) => PlaylistPreview[]; | ||
export declare function searchPlaylists(query: string, options?: { | ||
lang?: string; | ||
country?: string; | ||
onlyOfficialPlaylists?: boolean; | ||
}): Promise<PlaylistPreview[]>; |
@@ -35,9 +35,8 @@ "use strict"; | ||
function searchPlaylists(query, options) { | ||
var _a, _b; | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield got_1.default.post('https://music.youtube.com/youtubei/v1/search?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', { | ||
json: Object.assign(Object.assign({}, context_1.default.body(options === null || options === void 0 ? void 0 : options.lang, options === null || options === void 0 ? void 0 : options.country)), { params: 'EgWKAQIoAWoKEAoQAxAEEAUQCQ%3D%3D', query }), | ||
json: Object.assign(Object.assign({}, context_1.default.body), { params: 'EgWKAQIoAWoKEAoQAxAEEAUQCQ%3D%3D', query }), | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -47,3 +46,3 @@ }, | ||
try { | ||
return exports.parseSearchPlaylistsBody(JSON.parse(response.body), (_b = options === null || options === void 0 ? void 0 : options.onlyOfficialPlaylists) !== null && _b !== void 0 ? _b : false); | ||
return exports.parseSearchPlaylistsBody(JSON.parse(response.body), (_a = options === null || options === void 0 ? void 0 : options.onlyOfficialPlaylists) !== null && _a !== void 0 ? _a : false); | ||
} | ||
@@ -50,0 +49,0 @@ catch (e) { |
@@ -25,5 +25,2 @@ import { MusicVideo } from './models'; | ||
}) => MusicVideo[]; | ||
export declare function getSuggestions(videoId: string, options?: { | ||
lang?: string; | ||
country?: string; | ||
}): Promise<MusicVideo[]>; | ||
export declare function getSuggestions(videoId: string): Promise<MusicVideo[]>; |
@@ -34,7 +34,6 @@ "use strict"; | ||
exports.parseGetSuggestionsBody = parseGetSuggestionsBody; | ||
function getSuggestions(videoId, options) { | ||
var _a; | ||
function getSuggestions(videoId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield got_1.default.post('https://music.youtube.com/youtubei/v1/next', { | ||
json: Object.assign(Object.assign({}, context_1.default.body(options === null || options === void 0 ? void 0 : options.lang)), { enablePersistentPlaylistPanel: true, isAudioOnly: true, params: 'mgMDCNgE', playerParams: 'igMDCNgE', tunerSettingValue: 'AUTOMIX_SETTING_NORMAL', videoId }), | ||
json: Object.assign(Object.assign({}, context_1.default.body), { enablePersistentPlaylistPanel: true, isAudioOnly: true, params: 'mgMDCNgE', playerParams: 'igMDCNgE', tunerSettingValue: 'AUTOMIX_SETTING_NORMAL', videoId }), | ||
searchParams: { | ||
@@ -46,3 +45,2 @@ alt: 'json', | ||
'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': (_a = options === null || options === void 0 ? void 0 : options.lang) !== null && _a !== void 0 ? _a : 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -54,3 +52,3 @@ }, | ||
} | ||
catch (_b) { | ||
catch (_a) { | ||
return []; | ||
@@ -57,0 +55,0 @@ } |
import { listMusicsFromAlbum } from '../src'; | ||
// https://music.youtube.com/browse?id=MPREb_iWdtzQKst5b | ||
const main = () => | ||
listMusicsFromAlbum('MPREb_iWdtzQKst5b', { | ||
lang: 'fr', | ||
country: 'FR', | ||
}); | ||
const main = () => listMusicsFromAlbum('MPREb_iWdtzQKst5b'); | ||
main().then((results) => console.log(results)); |
import { listMusicsFromPlaylist } from '../src'; | ||
const main = () => | ||
listMusicsFromPlaylist('VLRDCLAK5uy_n20FRYQXNt1p1wS55Nj2r14IouO5weaYU', { | ||
lang: 'fr', | ||
country: 'FR', | ||
}); | ||
listMusicsFromPlaylist('VLRDCLAK5uy_n20FRYQXNt1p1wS55Nj2r14IouO5weaYU'); | ||
main().then((results) => console.log(results)); |
import { getSuggestions, searchMusics } from '../src'; | ||
const main = async () => { | ||
const music = ( | ||
await searchMusics('Liem if only', { lang: 'fr', country: 'FR' }) | ||
).shift(); | ||
const music = (await searchMusics('Liem if only')).shift(); | ||
if (!music) { | ||
@@ -11,8 +9,5 @@ throw Error(); | ||
if (!music.youtubeId) return; | ||
getSuggestions(music.youtubeId, { | ||
lang: 'fr', | ||
country: 'FR', | ||
}); | ||
getSuggestions(music.youtubeId); | ||
}; | ||
main().then((results) => console.log(results)); |
import { searchMusics } from '../src'; | ||
const main = () => searchMusics('DJOKO', { lang: 'fr', country: 'FR' }); | ||
const main = () => searchMusics('DJOKO'); | ||
main().then((results) => console.log(results)); |
{ | ||
"name": "node-youtube-music", | ||
"description": "Unofficial YouTube Music API for Node.js", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"main": "dist/src/index.js", | ||
@@ -6,0 +6,0 @@ "types": "dist/src/index.d.ts", |
export default { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
body: (lang?: string, country?: string) => ({ | ||
body: { | ||
context: { | ||
@@ -9,7 +9,5 @@ capabilities: {}, | ||
clientVersion: '0.1', | ||
hl: lang ?? 'en', | ||
gl: country ?? 'GB', | ||
}, | ||
}, | ||
}), | ||
}, | ||
}; |
@@ -32,7 +32,3 @@ import got from 'got'; | ||
export async function listMusicsFromAlbum( | ||
albumId: string, | ||
options?: { | ||
lang?: string; | ||
country?: string; | ||
} | ||
albumId: string | ||
): Promise<MusicVideo[]> { | ||
@@ -43,3 +39,3 @@ const response = await got.post( | ||
json: { | ||
...context.body(options?.lang, options?.country), | ||
...context.body, | ||
browseId: albumId, | ||
@@ -50,3 +46,2 @@ }, | ||
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': options?.lang ?? 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -53,0 +48,0 @@ }, |
@@ -41,7 +41,3 @@ import got from 'got'; | ||
export async function listMusicsFromPlaylist( | ||
playlistId: string, | ||
options?: { | ||
lang?: string; | ||
country?: string; | ||
} | ||
playlistId: string | ||
): Promise<MusicVideo[]> { | ||
@@ -52,3 +48,3 @@ const response = await got.post( | ||
json: { | ||
...context.body(options?.lang, options?.country), | ||
...context.body, | ||
browseId: playlistId, | ||
@@ -59,3 +55,2 @@ }, | ||
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': options?.lang ?? 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -62,0 +57,0 @@ }, |
@@ -28,9 +28,3 @@ import got from 'got'; | ||
export async function searchAlbums( | ||
query: string, | ||
options?: { | ||
lang?: string; | ||
country?: string; | ||
} | ||
): Promise<AlbumPreview[]> { | ||
export async function searchAlbums(query: string): Promise<AlbumPreview[]> { | ||
const response = await got.post( | ||
@@ -40,3 +34,3 @@ 'https://music.youtube.com/youtubei/v1/search?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', | ||
json: { | ||
...context.body(options?.lang, options?.country), | ||
...context.body, | ||
params: 'EgWKAQIYAWoKEAkQAxAEEAUQCg%3D%3D', | ||
@@ -48,3 +42,2 @@ query, | ||
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': options?.lang ?? 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -51,0 +44,0 @@ }, |
@@ -28,9 +28,3 @@ import got from 'got'; | ||
export async function searchMusics( | ||
query: string, | ||
options?: { | ||
lang?: string; | ||
country?: string; | ||
} | ||
): Promise<MusicVideo[]> { | ||
export async function searchMusics(query: string): Promise<MusicVideo[]> { | ||
const response = await got.post( | ||
@@ -40,3 +34,3 @@ 'https://music.youtube.com/youtubei/v1/search?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', | ||
json: { | ||
...context.body(options?.lang, options?.country), | ||
...context.body, | ||
params: 'EgWKAQIIAWoKEAoQCRADEAQQBQ%3D%3D', | ||
@@ -48,3 +42,2 @@ query, | ||
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': options?.lang ?? 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -51,0 +44,0 @@ }, |
@@ -32,4 +32,2 @@ import got from 'got'; | ||
options?: { | ||
lang?: string; | ||
country?: string; | ||
onlyOfficialPlaylists?: boolean; | ||
@@ -42,3 +40,3 @@ } | ||
json: { | ||
...context.body(options?.lang, options?.country), | ||
...context.body, | ||
params: 'EgWKAQIoAWoKEAoQAxAEEAUQCQ%3D%3D', | ||
@@ -50,3 +48,2 @@ query, | ||
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': options?.lang ?? 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -53,0 +50,0 @@ }, |
@@ -44,9 +44,3 @@ import got from 'got'; | ||
export async function getSuggestions( | ||
videoId: string, | ||
options?: { | ||
lang?: string; | ||
country?: string; | ||
} | ||
): Promise<MusicVideo[]> { | ||
export async function getSuggestions(videoId: string): Promise<MusicVideo[]> { | ||
const response = await got.post( | ||
@@ -56,3 +50,3 @@ 'https://music.youtube.com/youtubei/v1/next', | ||
json: { | ||
...context.body(options?.lang), | ||
...context.body, | ||
enablePersistentPlaylistPanel: true, | ||
@@ -72,3 +66,2 @@ isAudioOnly: true, | ||
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
'Accept-Language': options?.lang ?? 'en', | ||
origin: 'https://music.youtube.com', | ||
@@ -75,0 +68,0 @@ }, |
116241
2362