fix: replace MVs in albums with tracks from album playlist
This commit is contained in:
parent
3eadf82b8b
commit
2b91c76b85
5 changed files with 59 additions and 15 deletions
|
|
@ -99,7 +99,10 @@ impl RustyPipeQuery {
|
|||
radio_id: S,
|
||||
) -> Result<Paginator<TrackItem>, Error> {
|
||||
let radio_id = radio_id.as_ref();
|
||||
let context = self.get_context(ClientType::DesktopMusic, true, None).await;
|
||||
let visitor_data = self.get_ytm_visitor_data().await?;
|
||||
let context = self
|
||||
.get_context(ClientType::DesktopMusic, true, Some(&visitor_data))
|
||||
.await;
|
||||
let request_body = QRadio {
|
||||
context,
|
||||
playlist_id: radio_id,
|
||||
|
|
|
|||
|
|
@ -45,14 +45,55 @@ impl RustyPipeQuery {
|
|||
browse_id: album_id,
|
||||
};
|
||||
|
||||
self.execute_request::<response::MusicPlaylist, _, _>(
|
||||
ClientType::DesktopMusic,
|
||||
"music_album",
|
||||
album_id,
|
||||
"browse",
|
||||
&request_body,
|
||||
)
|
||||
.await
|
||||
let mut album = self
|
||||
.execute_request::<response::MusicPlaylist, MusicAlbum, _>(
|
||||
ClientType::DesktopMusic,
|
||||
"music_album",
|
||||
album_id,
|
||||
"browse",
|
||||
&request_body,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// YouTube Music is replacing album tracks with their respective music videos. To get the original
|
||||
// tracks, we have to fetch the album as a playlist and replace the offending track ids.
|
||||
if let Some(playlist_id) = &album.playlist_id {
|
||||
// Get a list of music videos in the album
|
||||
let to_replace = album
|
||||
.tracks
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, track)| {
|
||||
if track.is_video {
|
||||
Some((i, track.title.to_owned()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !to_replace.is_empty() {
|
||||
let playlist = self.music_playlist(playlist_id).await?;
|
||||
|
||||
for (i, title) in to_replace {
|
||||
let found_track = playlist.tracks.items.iter().find_map(|track| {
|
||||
if track.title == title && !track.is_video {
|
||||
Some((track.id.to_owned(), track.duration))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
if let Some((track_id, duration)) = found_track {
|
||||
album.tracks[i].id = track_id;
|
||||
if let Some(duration) = duration {
|
||||
album.tracks[i].duration = Some(duration);
|
||||
}
|
||||
album.tracks[i].is_video = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(album)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ MusicAlbum(
|
|||
track_nr: Some(1),
|
||||
),
|
||||
TrackItem(
|
||||
id: "lhPOMUjV4rE",
|
||||
id: "Jz-26iiDuYs",
|
||||
title: "Waldbrand",
|
||||
duration: Some(208),
|
||||
cover: [],
|
||||
|
|
@ -55,7 +55,7 @@ MusicAlbum(
|
|||
name: "Waldbrand",
|
||||
)),
|
||||
view_count: None,
|
||||
is_video: true,
|
||||
is_video: false,
|
||||
track_nr: Some(2),
|
||||
),
|
||||
TrackItem(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ MusicAlbum(
|
|||
by_va: false,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "XX0epju-YvY",
|
||||
id: "VU6lEv0PKAo",
|
||||
title: "Der Himmel reißt auf",
|
||||
duration: Some(183),
|
||||
cover: [],
|
||||
|
|
@ -43,7 +43,7 @@ MusicAlbum(
|
|||
name: "Der Himmel reißt auf",
|
||||
)),
|
||||
view_count: None,
|
||||
is_video: true,
|
||||
is_video: false,
|
||||
track_nr: Some(1),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ MusicAlbum(
|
|||
by_va: true,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "8IqLxg0GqXc",
|
||||
id: "Tzai7JXo45w",
|
||||
title: "Waka Boom (My Way) (feat. Lee Young Ji)",
|
||||
duration: Some(274),
|
||||
cover: [],
|
||||
|
|
@ -30,7 +30,7 @@ MusicAlbum(
|
|||
name: "<Queendom2> FINAL",
|
||||
)),
|
||||
view_count: None,
|
||||
is_video: true,
|
||||
is_video: false,
|
||||
track_nr: Some(1),
|
||||
),
|
||||
TrackItem(
|
||||
|
|
|
|||
Reference in a new issue