use async_trait::async_trait;
use serde_json::Value;
use super::{BaseFetcher, LyricsFetcher, LyricsItem};
use crate::{error::LyricsError, song::SongInfo};
#[allow(dead_code)]
#[derive(Default)]
pub(super) struct OvhFetcher {
base: BaseFetcher,
}
#[async_trait]
impl LyricsFetcher for OvhFetcher {
async fn search_lyric(&self, _song: &SongInfo) -> Result<Vec<LyricsItem>, LyricsError> {
Err(LyricsError::NoLyricsFound)
}
async fn download_lyric(&self, _item: &LyricsItem) -> Result<String, LyricsError> {
Err(LyricsError::NoLyricsFound)
}
async fn fetch_lyric(&self, song: &SongInfo) -> Result<String, LyricsError> {
let ovh_api = "https://api.lyrics.ovh/v1";
let api_url = format!("{}/{}/{}", ovh_api, song.artist, song.title);
let request = self
.base
.client
.get(api_url)
.header("Accept", "application/json")
.header(
"User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
);
let json: Value = self.base.fetch_with_retry(request).await?;
let lyrics = json["lyrics"].as_str().ok_or(LyricsError::NoLyricsFound)?;
if lyrics.is_empty() {
return Err(LyricsError::NoLyricsFound);
}
Ok(lyrics.to_string())
}
fn source_name(&self) -> &'static str {
"Spotify"
}
}