Skip to content

Commit

Permalink
Upgrade lofty, add support for album_artist
Browse files Browse the repository at this point in the history
  • Loading branch information
tranxuanthang committed May 29, 2024
1 parent 155d532 commit dcec6f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
31 changes: 15 additions & 16 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.4", features = [ "shell-open", "devtools", "dialog-all", "global-shortcut-all", "os-all", "path-all", "protocol-all", "window-all"] }
globwalk = "0.8.1"
reqwest = { version = "0.11.12", features = ["json"] }
lofty = "0.13.0"
lofty = "0.19.2"
anyhow = "1.0.71"
thiserror = "1.0"
rusqlite = { version = "0.29.0", features = ["bundled"] }
Expand Down
31 changes: 21 additions & 10 deletions src-tauri/src/fs_track.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use globwalk::{glob, DirEntry};
use lofty::{read_from_path, AudioFile, LoftyError};
use lofty::TaggedFileExt;
use lofty::Accessor;
use lofty::error::LoftyError;
use lofty::file::AudioFile;
use lofty::file::TaggedFileExt;
use lofty::read_from_path;
use lofty::tag::Accessor;
use anyhow::Result;
use rusqlite::Connection;
use tauri::AppHandle;
Expand All @@ -21,6 +23,7 @@ pub struct FsTrack {
title: String,
album: String,
artist: String,
album_artist: String,
duration: f64,
txt_lyrics: Option<String>,
lrc_lyrics: Option<String>
Expand Down Expand Up @@ -49,13 +52,14 @@ struct ScanProgress {
}

impl FsTrack {
fn new(file_path: String, file_name: String, title: String, album: String, artist: String, duration: f64, txt_lyrics: Option<String>, lrc_lyrics: Option<String>) -> FsTrack {
fn new(file_path: String, file_name: String, title: String, album: String, artist: String, album_artist: String, duration: f64, txt_lyrics: Option<String>, lrc_lyrics: Option<String>) -> FsTrack {
FsTrack {
file_path,
file_name,
title,
album,
artist,
album_artist,
duration,
txt_lyrics,
lrc_lyrics
Expand All @@ -66,15 +70,18 @@ impl FsTrack {
let file_path = path.display().to_string();
let file_name = path.file_name().unwrap().to_str().unwrap().to_owned();
let tagged_file = read_from_path(&file_path).or_else(|err| Err(FsTrackError::ParseFailed(file_path.to_owned(), err)))?;
let tag = tagged_file.primary_tag().ok_or(FsTrackError::PrimaryTagNotFound(file_path.to_owned()))?;
let owned_tag = tag.to_owned();
let tag = tagged_file.primary_tag().ok_or(FsTrackError::PrimaryTagNotFound(file_path.to_owned()))?.to_owned();
let properties = tagged_file.properties();
let title = owned_tag.title().ok_or(FsTrackError::TitleNotFound(file_path.to_owned()))?.to_string();
let album = owned_tag.album().ok_or(FsTrackError::AlbumNotFound(file_path.to_owned()))?.to_string();
let artist = owned_tag.artist().ok_or(FsTrackError::ArtistNotFound(file_path.to_owned()))?.to_string();
let title = tag.title().ok_or(FsTrackError::TitleNotFound(file_path.to_owned()))?.to_string();
let album = tag.album().ok_or(FsTrackError::AlbumNotFound(file_path.to_owned()))?.to_string();
let artist = tag.artist().ok_or(FsTrackError::ArtistNotFound(file_path.to_owned()))?.to_string();
let album_artist = tag
.get_string(&lofty::tag::ItemKey::AlbumArtist)
.map(|s| s.to_string())
.unwrap_or_else(|| artist.clone());
let duration = properties.duration().as_secs_f64();

let mut track = FsTrack::new(file_path, file_name, title, album, artist, duration, None, None);
let mut track = FsTrack::new(file_path, file_name, title, album, artist, album_artist, duration, None, None);
track.txt_lyrics = track.get_txt_lyrics();
track.lrc_lyrics = track.get_lrc_lyrics();

Expand All @@ -101,6 +108,10 @@ impl FsTrack {
self.artist.to_owned()
}

pub fn album_artist(&self) -> String {
self.album_artist.to_owned()
}

pub fn duration(&self) -> f64 {
self.duration
}
Expand Down

0 comments on commit dcec6f5

Please sign in to comment.