mirror of
https://github.com/arabianq/lyrics_fetcher.git
synced 2026-04-27 22:11:22 +00:00
30 lines
806 B
Rust
30 lines
806 B
Rust
pub mod genius;
|
|
pub mod lrclib;
|
|
|
|
pub use genius::GeniusSource;
|
|
pub use lrclib::LrcLibSource;
|
|
|
|
use anyhow::{Result, anyhow};
|
|
use async_trait::async_trait;
|
|
use lofty::{properties::FileProperties, tag::Tag};
|
|
use std::sync::Arc;
|
|
|
|
#[async_trait]
|
|
pub trait LyricsSource: Send + Sync {
|
|
fn name(&self) -> &'static str;
|
|
async fn fetch_lyrics(
|
|
&self,
|
|
tag: &Tag,
|
|
properties: &FileProperties,
|
|
allow_inaccurate: bool,
|
|
) -> Result<String>;
|
|
}
|
|
|
|
pub async fn create_source(name: &str) -> Result<Arc<dyn LyricsSource>> {
|
|
match name {
|
|
"lrclib" => Ok(Arc::new(LrcLibSource::new().await?) as Arc<dyn LyricsSource>),
|
|
"genius" => Ok(Arc::new(GeniusSource::new().await?) as Arc<dyn LyricsSource>),
|
|
_ => Err(anyhow!("Unknown source type: {}", name)),
|
|
}
|
|
}
|