-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
274 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::{ | ||
lyrics_fetcher::LyricsFetcher, | ||
model::{playable::Playable, track::Track}, | ||
queue::Queue, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct LyricsManager { | ||
queue: Arc<Queue>, | ||
fetcher: LyricsFetcher, | ||
// TODO: add a cache | ||
} | ||
|
||
impl LyricsManager { | ||
pub fn new(queue: Arc<Queue>, fetcher: LyricsFetcher) -> Self { | ||
LyricsManager { queue, fetcher } | ||
} | ||
|
||
/// Saves the given lyrics to the user's filesystem. | ||
/// | ||
/// Returns an optional message indicating the outcome of this operation. | ||
pub fn save_lyrics(&self, lyrics: String) -> Option<String> { | ||
Some("".to_string()) | ||
} | ||
|
||
/// Fetches and returns the lyrics of the given track | ||
pub fn get_lyrics(&self, track: Track) -> String { | ||
// TODO: implement caching | ||
|
||
self.fetcher.fetch(&track) | ||
} | ||
|
||
/// Fetches and returns the lyrics of the currently playing track | ||
pub fn get_lyrics_for_current(&self) -> String { | ||
match self.get_current_track() { | ||
None => String::from("No track currently playing: could not get lyrics"), | ||
Some(track) => self.get_lyrics(track), | ||
} | ||
} | ||
|
||
/// Returns the track being played currently, or nothing if the user is listening to a podcast episodes | ||
fn get_current_track(&self) -> Option<Track> { | ||
let playable = self.queue.get_current().unwrap(); | ||
|
||
match playable { | ||
Playable::Track(track) => Some(track), | ||
Playable::Episode(_) => None, | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::model::track::Track; | ||
|
||
#[derive(Clone)] | ||
pub struct LyricsFetcher {} | ||
|
||
impl LyricsFetcher { | ||
pub fn new() -> LyricsFetcher { | ||
Self {} | ||
} | ||
|
||
/// Fetches the lyrics of the given song using the specified lyrics source | ||
pub fn fetch(&self, track: &Track) -> String { | ||
// std::thread::sleep(std::time::Duration::from_secs(2)); | ||
|
||
format!("Sample Lyrics for {}\n", track.title) | ||
} | ||
} | ||
|
||
impl Default for LyricsFetcher { | ||
fn default() -> Self { | ||
LyricsFetcher::new() // TODO: check the prefered fetcher | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.