ytmusic_api_unofficial
Advanced tools
Comparing version 1.0.12 to 1.1.0-beta
@@ -18,4 +18,4 @@ "use strict"; | ||
getPlayer(id).then((res) => { | ||
if (res.playabilityStatus.status === 'UNPLAYABLE') | ||
reject(res.playabilityStatus); | ||
if (!res.streamingData) | ||
return reject(res.playabilityStatus); | ||
let webm = res.streamingData.adaptiveFormats.filter((item) => item.mimeType.includes('audio/webm')).sort((a, b) => b.bitrate - a.bitrate)[0]; | ||
@@ -22,0 +22,0 @@ webm.url = (0, decodeCipher_1.decode)(webm); |
import { Music } from "../models/Music"; | ||
import { Home } from "../models/Home"; | ||
import { Playlist } from "../models/Playlist"; | ||
declare const _default: { | ||
search: (query: string, type: TypeSearch) => Promise<Array<Music>>; | ||
getHomePage: () => Promise<Home>; | ||
relative: (ID: string) => Promise<Array<Music>>; | ||
get: (id: string) => Promise<Music>; | ||
GetData: (id: string) => Promise<any>; | ||
getPlaylist: (id: string) => Promise<Playlist>; | ||
}; | ||
@@ -7,0 +12,0 @@ export default _default; |
@@ -15,2 +15,6 @@ "use strict"; | ||
const Music_1 = require("../models/Music"); | ||
const Home_1 = require("../models/Home"); | ||
const index_1 = require("../index"); | ||
const extract_1 = require("../utils/extract"); | ||
const Playlist_1 = require("../models/Playlist"); | ||
exports.default = { | ||
@@ -38,3 +42,3 @@ search: (query, type) => __awaiter(void 0, void 0, void 0, function* () { | ||
for (const item of data) { | ||
resp_data.push(new Music_1.Music(yield GetData(((_e = (_d = item.musicResponsiveListItemRenderer) === null || _d === void 0 ? void 0 : _d.playlistItemData) === null || _e === void 0 ? void 0 : _e.videoId) || ((_f = item.musicResponsiveListItemRenderer) === null || _f === void 0 ? void 0 : _f.onTap.watchEndpoint.videoId)))); | ||
resp_data.push(new Music_1.Music((0, extract_1.extract_dataFromGetData)(yield GetData(((_e = (_d = item.musicResponsiveListItemRenderer) === null || _d === void 0 ? void 0 : _d.playlistItemData) === null || _e === void 0 ? void 0 : _e.videoId) || ((_f = item.musicResponsiveListItemRenderer) === null || _f === void 0 ? void 0 : _f.onTap.watchEndpoint.videoId))))); | ||
} | ||
@@ -45,2 +49,52 @@ return resp_data; | ||
}), | ||
getHomePage: () => __awaiter(void 0, void 0, void 0, function* () { | ||
return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () { | ||
(0, requestManager_1.requestToYtApi)('browse', { | ||
"browseId": "FEmusic_home" | ||
}).then((res) => __awaiter(void 0, void 0, void 0, function* () { | ||
const resp_data = { | ||
music_list: [], | ||
playlist: [] | ||
}; | ||
new Promise((resolve2) => __awaiter(void 0, void 0, void 0, function* () { | ||
for (let i = 0; res.data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents.length > i; i++) { | ||
let item = res.data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents; | ||
yield new Promise((resolve3) => __awaiter(void 0, void 0, void 0, function* () { | ||
for (let x = 0; item.length > x; x++) { | ||
let music = item[x].musicCarouselShelfRenderer; | ||
new Promise((resolve4) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u; | ||
for (let x = 0; music.contents.length > x; x++) { | ||
let musicdt = music.contents[x]; | ||
if (musicdt) { | ||
if (!((_h = (_g = musicdt === null || musicdt === void 0 ? void 0 : musicdt.musicResponsiveListItemRenderer) === null || _g === void 0 ? void 0 : _g.playlistItemData) === null || _h === void 0 ? void 0 : _h.videoId)) { | ||
if ((_l = (_k = (_j = musicdt.musicTwoRowItemRenderer) === null || _j === void 0 ? void 0 : _j.navigationEndpoint) === null || _k === void 0 ? void 0 : _k.browseEndpoint) === null || _l === void 0 ? void 0 : _l.browseId) | ||
resp_data.playlist.push(yield getPlaylist((_p = (_o = (_m = musicdt.musicTwoRowItemRenderer) === null || _m === void 0 ? void 0 : _m.navigationEndpoint) === null || _o === void 0 ? void 0 : _o.browseEndpoint) === null || _p === void 0 ? void 0 : _p.browseId)); | ||
} | ||
else { | ||
let title_music_list = (_u = (_t = (_s = (_r = (_q = music === null || music === void 0 ? void 0 : music.header) === null || _q === void 0 ? void 0 : _q.musicCarouselShelfBasicHeaderRenderer) === null || _r === void 0 ? void 0 : _r.title) === null || _s === void 0 ? void 0 : _s.runs) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.text; | ||
if (!resp_data.music_list.find((e) => e.title === title_music_list)) | ||
resp_data.music_list.push({ title: title_music_list, musics: [] }); | ||
resp_data.music_list.find((e) => e.title === title_music_list).musics.push((0, extract_1.extract_dataFromGetData)(yield index_1.searchManager.GetData(musicdt.musicResponsiveListItemRenderer.playlistItemData.videoId))); | ||
} | ||
} | ||
if (x + 1 === music.contents.length) | ||
resolve4(null); | ||
} | ||
})).then(() => { | ||
if (x + 1 === item.length) | ||
resolve3(null); | ||
}); | ||
} | ||
})).then(() => { | ||
if (i + 1 === res.data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents.length) | ||
resolve2(null); | ||
}); | ||
} | ||
})).then(() => { | ||
return resolve(new Home_1.Home(resp_data)); | ||
}); | ||
})); | ||
})); | ||
}), | ||
relative: (ID) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -71,4 +125,55 @@ return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () { | ||
})); | ||
}), | ||
GetData: (id) => __awaiter(void 0, void 0, void 0, function* () { | ||
return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () { | ||
return resolve(yield GetData(id)); | ||
})); | ||
}), | ||
getPlaylist: (id) => __awaiter(void 0, void 0, void 0, function* () { | ||
return yield getPlaylist(id); | ||
}) | ||
}; | ||
function getPlaylist(id) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () { | ||
(0, requestManager_1.requestToYtApi)('browse', { | ||
"browseId": id | ||
}).then((res) => __awaiter(this, void 0, void 0, function* () { | ||
let musics = []; | ||
yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () { | ||
const music_list = res.data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].musicPlaylistShelfRenderer.contents; | ||
for (let i = 0; music_list.length > i; i++) { | ||
//musics.push(extract_dataFromGetData(await GetData(music_list[i].musicResponsiveListItemRenderer.playlistItemData.videoId))) | ||
if (music_list.length === i + 1) | ||
resolve(null); | ||
} | ||
})); | ||
return resolve(new Playlist_1.Playlist({ | ||
title: res.data.header.musicDetailHeaderRenderer.title.runs[0].text, | ||
description: res.data.header.musicDetailHeaderRenderer.description.runs[0].text, | ||
id: id, | ||
artworks: res.data.header.musicDetailHeaderRenderer.thumbnail.croppedSquareThumbnailRenderer.thumbnail.thumbnails, | ||
musics: musics | ||
})); | ||
})); | ||
})); | ||
}); | ||
} | ||
function recursiveGetRelative(data, i = 0) { | ||
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c; | ||
if (!((_c = (_b = (_a = data.musicCarouselShelfRenderer.contents[i]) === null || _a === void 0 ? void 0 : _a.musicResponsiveListItemRenderer) === null || _b === void 0 ? void 0 : _b.playlistItemData) === null || _c === void 0 ? void 0 : _c.videoId)) | ||
return resolve(yield recursiveGetRelative(data, i - 1)); | ||
console.log(i); | ||
if (i < 0) | ||
return resolve(data); | ||
const data2 = yield index_1.searchManager.GetData(data.musicCarouselShelfRenderer.contents[i].musicResponsiveListItemRenderer.playlistItemData.videoId); | ||
if (data2.videoId) { | ||
data.musicCarouselShelfRenderer.contents[i] = data2; | ||
return resolve(yield recursiveGetRelative(data, i - 1)); | ||
} | ||
else | ||
return resolve(data); | ||
})); | ||
} | ||
function GetData(id) { | ||
@@ -75,0 +180,0 @@ return new Promise((resolve, reject) => { |
@@ -0,26 +1,17 @@ | ||
import { Artwork } from "./Artwork"; | ||
import { Artist } from "./Artist"; | ||
import { Duration } from "./Duration"; | ||
export declare class Music { | ||
artworks: Array<Artwork>; | ||
id: string; | ||
name: string; | ||
artist: { | ||
name: string; | ||
id: string; | ||
}; | ||
title: string; | ||
artists: Array<Artist>; | ||
typeVideo: string; | ||
length: { | ||
inSec: number; | ||
inText: string; | ||
label: string; | ||
}; | ||
duration: Duration; | ||
browseId: string; | ||
autoMix: boolean; | ||
constructor(search_result: any, autoMix?: boolean); | ||
constructor(data: any, autoMix?: boolean); | ||
getLyrics(): Promise<Lyrics | NoLyrics>; | ||
getRelative(): Promise<Array<Music>>; | ||
} | ||
declare class Artwork { | ||
url: string; | ||
width: number; | ||
height: number; | ||
} | ||
declare class Lyrics { | ||
@@ -27,0 +18,0 @@ lyrics: string; |
@@ -6,19 +6,12 @@ "use strict"; | ||
class Music { | ||
constructor(search_result, autoMix) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
this.artworks = search_result.thumbnail.thumbnails; | ||
this.id = search_result.videoId; | ||
this.name = search_result.title.runs[0].text; | ||
this.artist = { | ||
name: (_a = extractArtistData(search_result)) === null || _a === void 0 ? void 0 : _a.text, | ||
id: (_d = (_c = (_b = extractArtistData(search_result)) === null || _b === void 0 ? void 0 : _b.navigationEndpoint) === null || _c === void 0 ? void 0 : _c.browseEndpoint) === null || _d === void 0 ? void 0 : _d.browseId | ||
}; | ||
this.length = { | ||
inSec: timeToSec(((_g = (_f = (_e = search_result === null || search_result === void 0 ? void 0 : search_result.lengthText) === null || _e === void 0 ? void 0 : _e.runs) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.text) || '0:00'), | ||
inText: (_k = (_j = (_h = search_result === null || search_result === void 0 ? void 0 : search_result.lengthText) === null || _h === void 0 ? void 0 : _h.runs) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.text, | ||
label: (_o = (_m = (_l = search_result === null || search_result === void 0 ? void 0 : search_result.lengthText) === null || _l === void 0 ? void 0 : _l.accessibility) === null || _m === void 0 ? void 0 : _m.accessibilityData) === null || _o === void 0 ? void 0 : _o.label | ||
}; | ||
this.typeVideo = search_result.navigationEndpoint.watchEndpoint.watchEndpointMusicSupportedConfigs.watchEndpointMusicConfig.musicVideoType; | ||
this.browseId = search_result.browseId; | ||
this.autoMix = autoMix; | ||
constructor(data, autoMix) { | ||
this.artworks = data.artworks; | ||
this.id = data.id; | ||
this.title = data.title; | ||
this.artists = data.artists; | ||
this.duration = data.duration; | ||
this.typeVideo = data.type; | ||
this.browseId = data.browseId; | ||
if (autoMix) | ||
this.autoMix = autoMix; | ||
} | ||
@@ -49,4 +42,4 @@ getLyrics() { | ||
exports.Music = Music; | ||
function extractArtistData(search_result) { | ||
return search_result.longBylineText.runs.find((item) => { var _a, _b, _c, _d; return ((_d = (_c = (_b = (_a = item.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint) === null || _b === void 0 ? void 0 : _b.browseEndpointContextSupportedConfigs) === null || _c === void 0 ? void 0 : _c.browseEndpointContextMusicConfig) === null || _d === void 0 ? void 0 : _d.pageType) === 'MUSIC_PAGE_TYPE_ARTIST'; }); | ||
function extractArtistData(data) { | ||
return data.longBylineText.runs.find((item) => { var _a, _b, _c, _d; return ((_d = (_c = (_b = (_a = item.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint) === null || _b === void 0 ? void 0 : _b.browseEndpointContextSupportedConfigs) === null || _c === void 0 ? void 0 : _c.browseEndpointContextMusicConfig) === null || _d === void 0 ? void 0 : _d.pageType) === 'MUSIC_PAGE_TYPE_ARTIST'; }); | ||
} | ||
@@ -61,4 +54,2 @@ function timeToSec(time) { | ||
} | ||
class Artwork { | ||
} | ||
class Lyrics { | ||
@@ -65,0 +56,0 @@ } |
{ | ||
"name": "ytmusic_api_unofficial", | ||
"version": "1.0.12", | ||
"version": "1.1.0-beta", | ||
"description": "A simple API to get music from YouTube Music", | ||
@@ -5,0 +5,0 @@ "scripts": { |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
59777
51
1346
2