Fix track search for ytmusic
Track search recently changed (see linked commit), this makes the same
changes here so that the track search works again.
e1af1c2653
This commit is contained in:
parent
2ff1c61510
commit
c11c581e1f
2 changed files with 43 additions and 14 deletions
|
@ -114,25 +114,35 @@ function parse_result_content(contents, type) {
|
|||
}
|
||||
|
||||
async function lookupTrack(id) {
|
||||
let endpoint = "https://www.youtube.com/get_video_info"
|
||||
const { body } = await request.get(endpoint).query({ video_id: id, hl: "en", el: "detailpage" })
|
||||
let request_body = {'video_id': id, ...standard_body }
|
||||
|
||||
if (body.player_response === undefined) {
|
||||
throw new Error();
|
||||
const { body } = await request.post("https://music.youtube.com/youtubei/v1/player")
|
||||
.set(standard_headers)
|
||||
.query(standard_params)
|
||||
.send(request_body)
|
||||
let song_meta = body.videoDetails
|
||||
|
||||
let description = body.microformat.microformatDataRenderer.description.split(' · ')
|
||||
let possible_album_name = description[description.length - 1].split("℗")[0]
|
||||
if (!description[description.length - 1].includes("℗")) {
|
||||
possible_album_name = "";
|
||||
}
|
||||
let player_response = JSON.parse(body.player_response)
|
||||
let song_meta = player_response.videoDetails
|
||||
|
||||
let description = song_meta.shortDescription.split("\n\n")
|
||||
let album_name = description[2]
|
||||
let artists = description[1].split(' · ').slice(1)
|
||||
let tags = body.microformat.microformatDataRenderer.tags
|
||||
let album_name = ""
|
||||
for (const tag of tags) {
|
||||
if(possible_album_name.includes(tag)){
|
||||
album_name = tag;
|
||||
}
|
||||
}
|
||||
let artists = song_meta.author
|
||||
artists = artists.replace(" - Topic", "")
|
||||
|
||||
const artwork = {
|
||||
small: song_meta.thumbnail.thumbnails[0].url,
|
||||
large: song_meta.thumbnail.thumbnails[song_meta.thumbnail.thumbnails.length-1].url,
|
||||
};
|
||||
|
||||
return Promise.resolve({
|
||||
let track_info = {
|
||||
service: 'ytmusic',
|
||||
type: 'track',
|
||||
id: song_meta.videoId,
|
||||
|
@ -141,12 +151,14 @@ async function lookupTrack(id) {
|
|||
purchaseUrl: null,
|
||||
artwork,
|
||||
artist: {
|
||||
name: artists.join(", "),
|
||||
name: artists,
|
||||
},
|
||||
album: {
|
||||
name: album_name,
|
||||
},
|
||||
});
|
||||
}
|
||||
debug(track_info)
|
||||
return Promise.resolve(track_info);
|
||||
}
|
||||
|
||||
async function lookupAlbum(id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue