Added ability to pull cover art from album artist
This commit is contained in:
parent
e95168ccf4
commit
9c854f0c5b
4 changed files with 31 additions and 8 deletions
|
@ -157,7 +157,7 @@ impl DiscordClient {
|
|||
return ("logo".to_string(), "mpv".to_string())
|
||||
}
|
||||
|
||||
let cover_art_url = music_brainz::get_cover_art_url(&metadata.title, &metadata.album, &metadata.artist);
|
||||
let cover_art_url = music_brainz::get_cover_art_url(&metadata.title, &metadata.album, &metadata.artist, &metadata.album_artist);
|
||||
let large_image = match cover_art_url {
|
||||
Some(url) => url,
|
||||
None => "logo".to_string()
|
||||
|
|
|
@ -2,16 +2,18 @@ use musicbrainz_rs::entity::release_group::{ReleaseGroup, ReleaseGroupSearchQuer
|
|||
use musicbrainz_rs::entity::CoverartResponse;
|
||||
use musicbrainz_rs::{Search, FetchCoverart};
|
||||
|
||||
pub fn get_cover_art_url(title: &Option<String>, album: &Option<String>, artist: &Option<String>) -> Option<String>{
|
||||
pub fn get_cover_art_url(title: &Option<String>, album: &Option<String>, artist: &Option<String>, album_artist: &Option<String>) -> Option<String>{
|
||||
get_track_cover_art(artist, title).or(
|
||||
get_album_cover_art(album_artist, album)
|
||||
)
|
||||
}
|
||||
|
||||
fn get_track_cover_art(artist: &Option<String>, title: &Option<String>) -> Option<String> {
|
||||
let mut builder = ReleaseGroupSearchQuery::query_builder();
|
||||
if let Some(ref title) = title {
|
||||
builder.release_group(title);
|
||||
}
|
||||
|
||||
if let Some(ref album) = album {
|
||||
builder.or().release_group(album);
|
||||
}
|
||||
|
||||
if let Some(ref artist) = artist {
|
||||
// Some artist fields might contain + characters
|
||||
// Pointing at multiple artists
|
||||
|
@ -19,9 +21,27 @@ pub fn get_cover_art_url(title: &Option<String>, album: &Option<String>, artist:
|
|||
builder.and().artist(part);
|
||||
}
|
||||
}
|
||||
get_cover_art_from_query(builder.build())
|
||||
}
|
||||
|
||||
let query = builder.build();
|
||||
|
||||
fn get_album_cover_art(album_artist: &Option<String>, album: &Option<String>) -> Option<String> {
|
||||
let mut builder = ReleaseGroupSearchQuery::query_builder();
|
||||
if let Some(ref album) = album {
|
||||
builder.release_group(album);
|
||||
}
|
||||
|
||||
if let Some(ref album_artist) = album_artist {
|
||||
// Some artist fields might contain + characters
|
||||
// Pointing at multiple artists
|
||||
for part in album_artist.split("+") {
|
||||
builder.and().artist(part);
|
||||
}
|
||||
}
|
||||
|
||||
get_cover_art_from_query(builder.build())
|
||||
}
|
||||
|
||||
fn get_cover_art_from_query(query: String) -> Option<String> {
|
||||
let result = match ReleaseGroup::search(query).execute() {
|
||||
Ok(res) => res,
|
||||
Err(_) => return None
|
||||
|
|
|
@ -78,12 +78,14 @@ impl MpvEventQueue {
|
|||
fn get_file_info_event(&self) -> Option<MpvEvent> {
|
||||
let filename = self.mpv.get_property("filename").unwrap();
|
||||
let artist = self.mpv.get_property("metadata/by-key/artist").ok();
|
||||
let album_artist = self.mpv.get_property("metadata/by-key/album_artist").ok();
|
||||
let album = self.mpv.get_property("metadata/by-key/album").ok();
|
||||
let title = self.mpv.get_property("metadata/by-key/title").ok();
|
||||
let track = self.mpv.get_property("metadata/by-key/track").ok();
|
||||
|
||||
let metadata = FileMetadata {
|
||||
artist,
|
||||
album_artist,
|
||||
album,
|
||||
title,
|
||||
track
|
||||
|
|
|
@ -5,6 +5,7 @@ pub struct FileInfo {
|
|||
|
||||
pub struct FileMetadata {
|
||||
pub artist: Option<String>,
|
||||
pub album_artist: Option<String>,
|
||||
pub album: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub track: Option<String>
|
||||
|
|
Loading…
Reference in a new issue