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,
|
radio_id: S,
|
||||||
) -> Result<Paginator<TrackItem>, Error> {
|
) -> Result<Paginator<TrackItem>, Error> {
|
||||||
let radio_id = radio_id.as_ref();
|
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 {
|
let request_body = QRadio {
|
||||||
context,
|
context,
|
||||||
playlist_id: radio_id,
|
playlist_id: radio_id,
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,55 @@ impl RustyPipeQuery {
|
||||||
browse_id: album_id,
|
browse_id: album_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.execute_request::<response::MusicPlaylist, _, _>(
|
let mut album = self
|
||||||
ClientType::DesktopMusic,
|
.execute_request::<response::MusicPlaylist, MusicAlbum, _>(
|
||||||
"music_album",
|
ClientType::DesktopMusic,
|
||||||
album_id,
|
"music_album",
|
||||||
"browse",
|
album_id,
|
||||||
&request_body,
|
"browse",
|
||||||
)
|
&request_body,
|
||||||
.await
|
)
|
||||||
|
.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),
|
track_nr: Some(1),
|
||||||
),
|
),
|
||||||
TrackItem(
|
TrackItem(
|
||||||
id: "lhPOMUjV4rE",
|
id: "Jz-26iiDuYs",
|
||||||
title: "Waldbrand",
|
title: "Waldbrand",
|
||||||
duration: Some(208),
|
duration: Some(208),
|
||||||
cover: [],
|
cover: [],
|
||||||
|
|
@ -55,7 +55,7 @@ MusicAlbum(
|
||||||
name: "Waldbrand",
|
name: "Waldbrand",
|
||||||
)),
|
)),
|
||||||
view_count: None,
|
view_count: None,
|
||||||
is_video: true,
|
is_video: false,
|
||||||
track_nr: Some(2),
|
track_nr: Some(2),
|
||||||
),
|
),
|
||||||
TrackItem(
|
TrackItem(
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ MusicAlbum(
|
||||||
by_va: false,
|
by_va: false,
|
||||||
tracks: [
|
tracks: [
|
||||||
TrackItem(
|
TrackItem(
|
||||||
id: "XX0epju-YvY",
|
id: "VU6lEv0PKAo",
|
||||||
title: "Der Himmel reißt auf",
|
title: "Der Himmel reißt auf",
|
||||||
duration: Some(183),
|
duration: Some(183),
|
||||||
cover: [],
|
cover: [],
|
||||||
|
|
@ -43,7 +43,7 @@ MusicAlbum(
|
||||||
name: "Der Himmel reißt auf",
|
name: "Der Himmel reißt auf",
|
||||||
)),
|
)),
|
||||||
view_count: None,
|
view_count: None,
|
||||||
is_video: true,
|
is_video: false,
|
||||||
track_nr: Some(1),
|
track_nr: Some(1),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ MusicAlbum(
|
||||||
by_va: true,
|
by_va: true,
|
||||||
tracks: [
|
tracks: [
|
||||||
TrackItem(
|
TrackItem(
|
||||||
id: "8IqLxg0GqXc",
|
id: "Tzai7JXo45w",
|
||||||
title: "Waka Boom (My Way) (feat. Lee Young Ji)",
|
title: "Waka Boom (My Way) (feat. Lee Young Ji)",
|
||||||
duration: Some(274),
|
duration: Some(274),
|
||||||
cover: [],
|
cover: [],
|
||||||
|
|
@ -30,7 +30,7 @@ MusicAlbum(
|
||||||
name: "<Queendom2> FINAL",
|
name: "<Queendom2> FINAL",
|
||||||
)),
|
)),
|
||||||
view_count: None,
|
view_count: None,
|
||||||
is_video: true,
|
is_video: false,
|
||||||
track_nr: Some(1),
|
track_nr: Some(1),
|
||||||
),
|
),
|
||||||
TrackItem(
|
TrackItem(
|
||||||
|
|
|
||||||
Reference in a new issue