node-youtube-music
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -8,26 +8,5 @@ declare const _default: { | ||
clientVersion: string; | ||
experimentIds: never[]; | ||
experimentsToken: string; | ||
hl: string; | ||
gl: string; | ||
locationInfo: { | ||
locationPermissionAuthorizationStatus: string; | ||
}; | ||
musicAppInfo: { | ||
musicActivityMasterSwitch: string; | ||
musicLocationMasterSwitch: string; | ||
pwaInstallabilityStatus: string; | ||
}; | ||
utcOffsetMinutes: number; | ||
}; | ||
request: { | ||
internalExperimentFlags: { | ||
key: string; | ||
value: string; | ||
}[]; | ||
sessionIndex: {}; | ||
}; | ||
user: { | ||
enableSafetyMode: boolean; | ||
}; | ||
}; | ||
@@ -34,0 +13,0 @@ }; |
@@ -11,38 +11,7 @@ "use strict"; | ||
clientVersion: '0.1', | ||
experimentIds: [], | ||
experimentsToken: '', | ||
hl: lang !== null && lang !== void 0 ? lang : 'en', | ||
gl: country !== null && country !== void 0 ? country : 'GB', | ||
locationInfo: { | ||
locationPermissionAuthorizationStatus: 'LOCATION_PERMISSION_AUTHORIZATION_STATUS_UNSUPPORTED', | ||
}, | ||
musicAppInfo: { | ||
musicActivityMasterSwitch: 'MUSIC_ACTIVITY_MASTER_SWITCH_INDETERMINATE', | ||
musicLocationMasterSwitch: 'MUSIC_LOCATION_MASTER_SWITCH_INDETERMINATE', | ||
pwaInstallabilityStatus: 'PWA_INSTALLABILITY_STATUS_UNKNOWN', | ||
}, | ||
utcOffsetMinutes: 60, | ||
}, | ||
request: { | ||
internalExperimentFlags: [ | ||
{ | ||
key: 'force_music_enable_outertube_tastebuilder_browse', | ||
value: 'true', | ||
}, | ||
{ | ||
key: 'force_music_enable_outertube_playlist_detail_browse', | ||
value: 'true', | ||
}, | ||
{ | ||
key: 'force_music_enable_outertube_search_suggestions', | ||
value: 'true', | ||
}, | ||
], | ||
sessionIndex: {}, | ||
}, | ||
user: { | ||
enableSafetyMode: false, | ||
}, | ||
}, | ||
}), | ||
}; |
import search from './search'; | ||
import getSuggestions from './suggestions'; | ||
declare const _default: { | ||
parseYoutubeMusicSearchBody: (body: { | ||
contents: { | ||
sectionListRenderer: { | ||
contents: { | ||
musicShelfRenderer: { | ||
contents: []; | ||
}; | ||
}[]; | ||
}; | ||
}; | ||
}) => import("./models").MusicVideo[]; | ||
search: typeof search; | ||
@@ -5,0 +16,0 @@ getSuggestions: typeof getSuggestions; |
@@ -6,4 +6,5 @@ "use strict"; | ||
exports.default = { | ||
parseYoutubeMusicSearchBody: search_1.parseYoutubeMusicSearchBody, | ||
search: search_1.default, | ||
getSuggestions: suggestions_1.default, | ||
}; |
import { MusicVideo } from './models'; | ||
export declare const parseYoutubeMusicSearchBody: (body: { | ||
contents: { | ||
sectionListRenderer: { | ||
contents: { | ||
musicShelfRenderer: { | ||
contents: []; | ||
}; | ||
}[]; | ||
}; | ||
}; | ||
}) => MusicVideo[]; | ||
export default function search(query: string, options?: { | ||
@@ -3,0 +14,0 @@ lang?: string; |
@@ -12,14 +12,29 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseYoutubeMusicSearchBody = void 0; | ||
const got_1 = require("got"); | ||
const parsers_1 = require("./parsers"); | ||
const context_1 = require("./context"); | ||
const parseYoutubeMusicSearchBody = (body) => { | ||
const { contents, } = body.contents.sectionListRenderer.contents[0].musicShelfRenderer; | ||
const results = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content) => { | ||
try { | ||
const video = parsers_1.parseVideo(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
}; | ||
exports.parseYoutubeMusicSearchBody = parseYoutubeMusicSearchBody; | ||
function search(query, options) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield got_1.default.post('https://music.youtube.com/youtubei/v1/search', { | ||
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 }), | ||
searchParams: { | ||
alt: 'json', | ||
key: 'AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', | ||
}, | ||
headers: { | ||
@@ -32,17 +47,3 @@ 'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', | ||
try { | ||
const { contents } = JSON.parse(response.body).contents.sectionListRenderer.contents[0].musicShelfRenderer; | ||
const results = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content) => { | ||
try { | ||
const video = parsers_1.parseVideo(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
return exports.parseYoutubeMusicSearchBody(JSON.parse(response.body)); | ||
} | ||
@@ -49,0 +50,0 @@ catch (_b) { |
import { MusicVideo } from './models'; | ||
export declare const parseYoutubeMusicSuggestionsBody: (body: { | ||
contents: { | ||
singleColumnMusicWatchNextResultsRenderer: { | ||
tabbedRenderer: { | ||
watchNextTabbedResultsRenderer: { | ||
tabs: { | ||
tabRenderer: { | ||
content: { | ||
musicQueueRenderer: { | ||
content: { | ||
playlistPanelRenderer: { | ||
contents: []; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}[]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}) => MusicVideo[]; | ||
export default function getSuggestions(videoId: string, options?: { | ||
@@ -3,0 +26,0 @@ lang?: string; |
@@ -12,5 +12,24 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseYoutubeMusicSuggestionsBody = void 0; | ||
const got_1 = require("got"); | ||
const parsers_1 = require("./parsers"); | ||
const context_1 = require("./context"); | ||
const parseYoutubeMusicSuggestionsBody = (body) => { | ||
const { contents, } = body.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content.musicQueueRenderer.content.playlistPanelRenderer; | ||
const results = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content) => { | ||
try { | ||
const video = parsers_1.parseSuggestion(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
}; | ||
exports.parseYoutubeMusicSuggestionsBody = parseYoutubeMusicSuggestionsBody; | ||
function getSuggestions(videoId, options) { | ||
@@ -32,17 +51,3 @@ var _a; | ||
try { | ||
const { contents } = JSON.parse(response.body).contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content.musicQueueRenderer.content.playlistPanelRenderer; | ||
const results = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content) => { | ||
try { | ||
const video = parsers_1.parseSuggestion(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
return exports.parseYoutubeMusicSuggestionsBody(JSON.parse(response.body)); | ||
} | ||
@@ -49,0 +54,0 @@ catch (_b) { |
{ | ||
"name": "node-youtube-music", | ||
"description": "Unofficial YouTube Music API for Node.js", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"main": "dist/src/index.js", | ||
@@ -6,0 +6,0 @@ "types": "dist/src/index.d.ts", |
@@ -9,41 +9,7 @@ export default { | ||
clientVersion: '0.1', | ||
experimentIds: [], | ||
experimentsToken: '', | ||
hl: lang ?? 'en', | ||
gl: country ?? 'GB', | ||
locationInfo: { | ||
locationPermissionAuthorizationStatus: | ||
'LOCATION_PERMISSION_AUTHORIZATION_STATUS_UNSUPPORTED', | ||
}, | ||
musicAppInfo: { | ||
musicActivityMasterSwitch: | ||
'MUSIC_ACTIVITY_MASTER_SWITCH_INDETERMINATE', | ||
musicLocationMasterSwitch: | ||
'MUSIC_LOCATION_MASTER_SWITCH_INDETERMINATE', | ||
pwaInstallabilityStatus: 'PWA_INSTALLABILITY_STATUS_UNKNOWN', | ||
}, | ||
utcOffsetMinutes: 60, | ||
}, | ||
request: { | ||
internalExperimentFlags: [ | ||
{ | ||
key: 'force_music_enable_outertube_tastebuilder_browse', | ||
value: 'true', | ||
}, | ||
{ | ||
key: 'force_music_enable_outertube_playlist_detail_browse', | ||
value: 'true', | ||
}, | ||
{ | ||
key: 'force_music_enable_outertube_search_suggestions', | ||
value: 'true', | ||
}, | ||
], | ||
sessionIndex: {}, | ||
}, | ||
user: { | ||
enableSafetyMode: false, | ||
}, | ||
}, | ||
}), | ||
}; |
@@ -1,7 +0,11 @@ | ||
import search from './search'; | ||
import getSuggestions from './suggestions'; | ||
import search, { parseYoutubeMusicSearchBody } from './search'; | ||
import getSuggestions, { | ||
parseYoutubeMusicSuggestionsBody, | ||
} from './suggestions'; | ||
export default { | ||
parseYoutubeMusicSearchBody, | ||
parseYoutubeMusicSuggestionsBody, | ||
search, | ||
getSuggestions, | ||
}; |
@@ -6,2 +6,28 @@ import got from 'got'; | ||
export const parseYoutubeMusicSearchBody = (body: { | ||
contents: { | ||
sectionListRenderer: { | ||
contents: { musicShelfRenderer: { contents: [] } }[]; | ||
}; | ||
}; | ||
}): MusicVideo[] => { | ||
const { | ||
contents, | ||
} = body.contents.sectionListRenderer.contents[0].musicShelfRenderer; | ||
const results: MusicVideo[] = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content: any) => { | ||
try { | ||
const video = parseVideo(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
}; | ||
export default async function search( | ||
@@ -15,3 +41,3 @@ query: string, | ||
const response = await got.post( | ||
'https://music.youtube.com/youtubei/v1/search', | ||
'https://music.youtube.com/youtubei/v1/search?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', | ||
{ | ||
@@ -23,6 +49,2 @@ json: { | ||
}, | ||
searchParams: { | ||
alt: 'json', | ||
key: 'AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30', | ||
}, | ||
headers: { | ||
@@ -37,19 +59,3 @@ 'User-Agent': | ||
try { | ||
const { contents } = JSON.parse( | ||
response.body | ||
).contents.sectionListRenderer.contents[0].musicShelfRenderer; | ||
const results: MusicVideo[] = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content: any) => { | ||
try { | ||
const video = parseVideo(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
return parseYoutubeMusicSearchBody(JSON.parse(response.body)); | ||
} catch { | ||
@@ -56,0 +62,0 @@ return []; |
@@ -6,2 +6,40 @@ import got from 'got'; | ||
export const parseYoutubeMusicSuggestionsBody = (body: { | ||
contents: { | ||
singleColumnMusicWatchNextResultsRenderer: { | ||
tabbedRenderer: { | ||
watchNextTabbedResultsRenderer: { | ||
tabs: { | ||
tabRenderer: { | ||
content: { | ||
musicQueueRenderer: { | ||
content: { playlistPanelRenderer: { contents: [] } }; | ||
}; | ||
}; | ||
}; | ||
}[]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}): MusicVideo[] => { | ||
const { | ||
contents, | ||
} = body.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content.musicQueueRenderer.content.playlistPanelRenderer; | ||
const results: MusicVideo[] = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content: any) => { | ||
try { | ||
const video = parseSuggestion(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
}; | ||
export default async function getSuggestions( | ||
@@ -39,19 +77,3 @@ videoId: string, | ||
try { | ||
const { contents } = JSON.parse( | ||
response.body | ||
).contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content.musicQueueRenderer.content.playlistPanelRenderer; | ||
const results: MusicVideo[] = []; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contents.forEach((content: any) => { | ||
try { | ||
const video = parseSuggestion(content); | ||
if (video) { | ||
results.push(video); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
return results; | ||
return parseYoutubeMusicSuggestionsBody(JSON.parse(response.body)); | ||
} catch { | ||
@@ -58,0 +80,0 @@ return []; |
33938
846