Add search function and code quality improvements
This commit is contained in:
parent
a96279b190
commit
c523a3a18c
8 changed files with 1026 additions and 941 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -662,7 +662,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "down_on_spot"
|
||||
version = "0.0.1"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"aspotify",
|
||||
"async-std",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ panic = "abort"
|
|||
|
||||
[package]
|
||||
name = "down_on_spot"
|
||||
version = "0.0.1"
|
||||
version = "0.1.1"
|
||||
edition = "2018"
|
||||
authors = ["exttex", "oSumAtrIX"]
|
||||
build = "build.rs"
|
||||
|
|
@ -44,4 +44,4 @@ tokio = { version = "1.12", features = ["fs"] }
|
|||
OriginalFilename = "DownOnSpot.exe"
|
||||
FileDescription = "Download songs from Spotify with Rust"
|
||||
ProductName = "DownOnSpot"
|
||||
ProductVersion = "0.0.1"
|
||||
ProductVersion = "0.1.1"
|
||||
|
|
@ -31,6 +31,7 @@ I am not responsible in any way for the usage of the source code.
|
|||
- Works with free Spotify accounts (if using free-librespot fork)
|
||||
- Download 96, 160kbit/s audio with a free, 256 and 320 kbit/s audio with a premium account from Spotify, directly
|
||||
- Multi-threaded
|
||||
- Search for tracks
|
||||
- Download tracks, playlists, albums and artists
|
||||
- Convert to mp3
|
||||
- Metadata tagging
|
||||
|
|
@ -76,7 +77,7 @@ Settings could not be loaded, because of the following error: IO: NotFound No su
|
|||
|
||||
$ down_on_spot.exe
|
||||
Usage:
|
||||
down_on_spot.exe (track_url | album_url | playlist_url | artist_url)
|
||||
down_on_spot.exe (search_term | track_url | album_url | playlist_url | artist_url)
|
||||
```
|
||||
|
||||
### Template variables
|
||||
|
|
|
|||
1444
src/downloader.rs
1444
src/downloader.rs
File diff suppressed because it is too large
Load diff
156
src/main.rs
156
src/main.rs
|
|
@ -8,8 +8,6 @@ use settings::Settings;
|
|||
use spotify::Spotify;
|
||||
use std::{
|
||||
env,
|
||||
ffi::OsStr,
|
||||
path::Path,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
|
|
@ -29,14 +27,14 @@ async fn main() {
|
|||
#[cfg(windows)]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
use colored::control;
|
||||
use colored::control;
|
||||
|
||||
//backwards compatibility.
|
||||
match control::set_virtual_terminal(true) {
|
||||
Ok(_) => {},
|
||||
Ok(_) => {}
|
||||
Err(_) => {}
|
||||
};
|
||||
|
||||
|
||||
start().await;
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +43,7 @@ async fn start() {
|
|||
Ok(settings) => {
|
||||
println!(
|
||||
"{} {}.",
|
||||
"Settings successfully loaded. Continuing with spotify account:".green(),
|
||||
"Settings successfully loaded.\nContinuing with spotify account:".green(),
|
||||
settings.username
|
||||
);
|
||||
settings
|
||||
|
|
@ -56,8 +54,7 @@ async fn start() {
|
|||
"Settings could not be loaded, because of the following error:".red(),
|
||||
e
|
||||
);
|
||||
let default_settings =
|
||||
Settings::new("username", "password", "client_id", "secret").unwrap();
|
||||
let default_settings = Settings::new("username", "password", "client_id", "secret");
|
||||
match default_settings.save().await {
|
||||
Ok(_) => {
|
||||
println!(
|
||||
|
|
@ -103,75 +100,108 @@ async fn start() {
|
|||
|
||||
let downloader = Downloader::new(settings.downloader, spotify);
|
||||
|
||||
match downloader.add_uri(&args[1]).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
error!("{} {}", "Adding url failed:".red(), e)
|
||||
}
|
||||
}
|
||||
match downloader.handle_input(&args[1]).await {
|
||||
Ok(search_results) => {
|
||||
if let Some(search_results) = search_results {
|
||||
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
|
||||
|
||||
let refresh = Duration::from_secs(settings.refresh_ui_seconds);
|
||||
let now = Instant::now();
|
||||
let mut timeelapsed: u64;
|
||||
for (i, track) in search_results.iter().enumerate() {
|
||||
println!("{}: {} - {}", i + 1, track.author, track.title);
|
||||
}
|
||||
println!("{}", "Select the track (default: 1): ".green());
|
||||
|
||||
'outer: loop {
|
||||
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
|
||||
let mut exit_flag: i8 = 1;
|
||||
let mut selection;
|
||||
loop {
|
||||
let mut input = String::new();
|
||||
std::io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Failed to read line");
|
||||
|
||||
for download in downloader.get_downloads().await {
|
||||
let state = download.state;
|
||||
selection = input.trim().parse::<usize>().unwrap_or(1) - 1;
|
||||
|
||||
let progress: String;
|
||||
if selection < search_results.len() {
|
||||
break;
|
||||
}
|
||||
println!("{}", "Invalid selection. Try again or quit (CTRL+C):".red());
|
||||
}
|
||||
|
||||
if state != DownloadState::Done {
|
||||
exit_flag &= 0;
|
||||
progress = match state {
|
||||
DownloadState::Downloading(r, t) => {
|
||||
let p = r as f32 / t as f32 * 100.0;
|
||||
if p > 100.0 {
|
||||
"100%".to_string()
|
||||
} else {
|
||||
format!("{}%", p as i8)
|
||||
let track = &search_results[selection];
|
||||
|
||||
if let Err(e) = downloader
|
||||
.add_uri(&format!("spotify:track:{}", track.track_id))
|
||||
.await
|
||||
{
|
||||
error!(
|
||||
"{}",
|
||||
format!(
|
||||
"{}: {}",
|
||||
"Track could not be added to download queue.".red(),
|
||||
e
|
||||
)
|
||||
);
|
||||
} else {
|
||||
let refresh = Duration::from_secs(settings.refresh_ui_seconds);
|
||||
let now = Instant::now();
|
||||
let mut time_elapsed: u64;
|
||||
|
||||
'outer: loop {
|
||||
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
|
||||
let mut exit_flag: i8 = 1;
|
||||
|
||||
for download in downloader.get_downloads().await {
|
||||
let state = download.state;
|
||||
|
||||
let progress: String;
|
||||
|
||||
if state != DownloadState::Done {
|
||||
exit_flag &= 0;
|
||||
progress = match state {
|
||||
DownloadState::Downloading(r, t) => {
|
||||
let p = r as f32 / t as f32 * 100.0;
|
||||
if p > 100.0 {
|
||||
"100%".to_string()
|
||||
} else {
|
||||
format!("{}%", p as i8)
|
||||
}
|
||||
}
|
||||
DownloadState::Post => "Postprocessing... ".to_string(),
|
||||
DownloadState::None => "Preparing... ".to_string(),
|
||||
DownloadState::Lock => "Preparing... ".to_string(),
|
||||
DownloadState::Error(e) => {
|
||||
exit_flag |= 1;
|
||||
format!("{} ", e)
|
||||
}
|
||||
DownloadState::Done => {
|
||||
exit_flag |= 1;
|
||||
"Impossible state".to_string()
|
||||
}
|
||||
};
|
||||
} else {
|
||||
progress = "Done.".to_string();
|
||||
}
|
||||
|
||||
println!("{:<19}| {}", progress, download.title);
|
||||
}
|
||||
time_elapsed = now.elapsed().as_secs();
|
||||
if exit_flag == 1 {
|
||||
break 'outer;
|
||||
}
|
||||
|
||||
println!("\nElapsed second(s): {}", time_elapsed);
|
||||
task::sleep(refresh).await
|
||||
}
|
||||
DownloadState::Post => "Postprocessing... ".to_string(),
|
||||
DownloadState::None => "Preparing... ".to_string(),
|
||||
DownloadState::Lock => "Holding... ".to_string(),
|
||||
DownloadState::Error(e) => {
|
||||
exit_flag |= 1;
|
||||
format!("{} ", e)
|
||||
},
|
||||
DownloadState::Done => {
|
||||
exit_flag |= 1;
|
||||
"Impossible state".to_string()
|
||||
}
|
||||
};
|
||||
} else {
|
||||
progress = "Done.".to_string();
|
||||
println!("Finished download(s) in {} second(s).", time_elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
println!("{:<19}| {}", progress, download.title);
|
||||
}
|
||||
timeelapsed = now.elapsed().as_secs();
|
||||
if exit_flag == 1 {
|
||||
break 'outer;
|
||||
Err(e) => {
|
||||
error!("{} {}", "Handling input failed:".red(), e)
|
||||
}
|
||||
|
||||
println!("\nElapsed second(s): {}", timeelapsed);
|
||||
task::sleep(refresh).await
|
||||
}
|
||||
println!("Finished download(s) in {} second(s).", timeelapsed);
|
||||
} else {
|
||||
println!(
|
||||
"Usage:\n{} (track_url | album_url | playlist_url | artist_url )",
|
||||
env::args()
|
||||
.next()
|
||||
.as_ref()
|
||||
.map(Path::new)
|
||||
.and_then(Path::file_name)
|
||||
.and_then(OsStr::to_str)
|
||||
.map(String::from)
|
||||
.unwrap()
|
||||
args[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::downloader::DownloaderConfig;
|
||||
use crate::downloader::Quality;
|
||||
use crate::error::SpotifyError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -18,30 +17,18 @@ pub struct Settings {
|
|||
pub refresh_ui_seconds: u64,
|
||||
pub downloader: DownloaderConfig,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
// Create new instance
|
||||
pub fn new(
|
||||
username: &str,
|
||||
password: &str,
|
||||
client_id: &str,
|
||||
client_secret: &str,
|
||||
) -> Option<Settings> {
|
||||
Some(Settings {
|
||||
pub fn new(username: &str, password: &str, client_id: &str, client_secret: &str) -> Settings {
|
||||
Settings {
|
||||
username: username.to_string(),
|
||||
password: password.to_string(),
|
||||
client_id: client_id.to_string(),
|
||||
client_secret: client_secret.to_string(),
|
||||
refresh_ui_seconds: 1,
|
||||
downloader: DownloaderConfig {
|
||||
concurrent_downloads: 4,
|
||||
quality: Quality::Q320,
|
||||
path: "downloads".to_string(),
|
||||
filename_template: "%artist% - %title%".to_string(),
|
||||
id3v24: true,
|
||||
convert_to_mp3: false,
|
||||
separator: ", ".to_string(),
|
||||
},
|
||||
})
|
||||
downloader: DownloaderConfig::new()
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize the settings to a json file
|
||||
|
|
|
|||
325
src/spotify.rs
325
src/spotify.rs
|
|
@ -1,6 +1,4 @@
|
|||
use aspotify::{
|
||||
Album, Artist, Client, ClientCredentials, Playlist, PlaylistItemType, Track, TrackSimplified,
|
||||
};
|
||||
use aspotify::{Album, Artist, Client, ClientCredentials, ItemType, Playlist, PlaylistItemType, Track, TrackSimplified};
|
||||
use librespot::core::authentication::Credentials;
|
||||
use librespot::core::config::SessionConfig;
|
||||
use librespot::core::session::Session;
|
||||
|
|
@ -10,183 +8,196 @@ use url::Url;
|
|||
use crate::error::SpotifyError;
|
||||
|
||||
pub struct Spotify {
|
||||
// librespotify sessopm
|
||||
pub session: Session,
|
||||
pub spotify: Client,
|
||||
// librespotify sessopm
|
||||
pub session: Session,
|
||||
pub spotify: Client,
|
||||
}
|
||||
|
||||
impl Spotify {
|
||||
/// Create new instance
|
||||
pub async fn new(
|
||||
username: &str,
|
||||
password: &str,
|
||||
client_id: &str,
|
||||
client_secret: &str,
|
||||
) -> Result<Spotify, SpotifyError> {
|
||||
// librespot
|
||||
let credentials = Credentials::with_password(username, password);
|
||||
let session = Session::connect(SessionConfig::default(), credentials, None).await?;
|
||||
//aspotify
|
||||
let credentials = ClientCredentials {
|
||||
id: client_id.to_string(),
|
||||
secret: client_secret.to_string(),
|
||||
};
|
||||
let spotify = Client::new(credentials);
|
||||
/// Create new instance
|
||||
pub async fn new(
|
||||
username: &str,
|
||||
password: &str,
|
||||
client_id: &str,
|
||||
client_secret: &str,
|
||||
) -> Result<Spotify, SpotifyError> {
|
||||
// librespot
|
||||
let credentials = Credentials::with_password(username, password);
|
||||
let session = Session::connect(SessionConfig::default(), credentials, None).await?;
|
||||
//aspotify
|
||||
let credentials = ClientCredentials {
|
||||
id: client_id.to_string(),
|
||||
secret: client_secret.to_string(),
|
||||
};
|
||||
let spotify = Client::new(credentials);
|
||||
|
||||
Ok(Spotify { session, spotify })
|
||||
}
|
||||
Ok(Spotify { session, spotify })
|
||||
}
|
||||
|
||||
/// Parse URI or URL into URI
|
||||
pub fn parse_uri(uri: &str) -> Result<String, SpotifyError> {
|
||||
// Already URI
|
||||
if uri.starts_with("spotify:") {
|
||||
if uri.split(':').count() < 3 {
|
||||
return Err(SpotifyError::InvalidUri);
|
||||
}
|
||||
return Ok(uri.to_string());
|
||||
}
|
||||
/// Parse URI or URL into URI
|
||||
pub fn parse_uri(uri: &str) -> Result<String, SpotifyError> {
|
||||
// Already URI
|
||||
if uri.starts_with("spotify:") {
|
||||
if uri.split(':').count() < 3 {
|
||||
return Err(SpotifyError::InvalidUri);
|
||||
}
|
||||
return Ok(uri.to_string());
|
||||
}
|
||||
|
||||
// Parse URL
|
||||
let url = Url::parse(uri)?;
|
||||
// Spotify Web Player URL
|
||||
if url.host_str() == Some("open.spotify.com") {
|
||||
let path = url
|
||||
.path_segments()
|
||||
.ok_or_else(|| SpotifyError::Error("Missing URL path".into()))?
|
||||
.collect::<Vec<&str>>();
|
||||
if path.len() < 2 {
|
||||
return Err(SpotifyError::InvalidUri);
|
||||
}
|
||||
return Ok(format!("spotify:{}:{}", path[0], path[1]));
|
||||
}
|
||||
Err(SpotifyError::InvalidUri)
|
||||
}
|
||||
// Parse URL
|
||||
let url = Url::parse(uri)?;
|
||||
// Spotify Web Player URL
|
||||
if url.host_str() == Some("open.spotify.com") {
|
||||
let path = url
|
||||
.path_segments()
|
||||
.ok_or_else(|| SpotifyError::Error("Missing URL path".into()))?
|
||||
.collect::<Vec<&str>>();
|
||||
if path.len() < 2 {
|
||||
return Err(SpotifyError::InvalidUri);
|
||||
}
|
||||
return Ok(format!("spotify:{}:{}", path[0], path[1]));
|
||||
}
|
||||
Err(SpotifyError::InvalidUri)
|
||||
}
|
||||
|
||||
/// Fetch data for URI
|
||||
pub async fn resolve_uri(&self, uri: &str) -> Result<SpotifyItem, SpotifyError> {
|
||||
let parts = uri.split(':').skip(1).collect::<Vec<&str>>();
|
||||
let id = parts[1];
|
||||
match parts[0] {
|
||||
"track" => {
|
||||
let track = self.spotify.tracks().get_track(id, None).await?;
|
||||
Ok(SpotifyItem::Track(track.data))
|
||||
}
|
||||
"playlist" => {
|
||||
let playlist = self.spotify.playlists().get_playlist(id, None).await?;
|
||||
Ok(SpotifyItem::Playlist(playlist.data))
|
||||
}
|
||||
"album" => {
|
||||
let album = self.spotify.albums().get_album(id, None).await?;
|
||||
Ok(SpotifyItem::Album(album.data))
|
||||
}
|
||||
"artist" => {
|
||||
let artist = self.spotify.artists().get_artist(id).await?;
|
||||
Ok(SpotifyItem::Artist(artist.data))
|
||||
}
|
||||
// Unsupported / Unimplemented
|
||||
_ => Ok(SpotifyItem::Other(uri.to_string())),
|
||||
}
|
||||
}
|
||||
/// Fetch data for URI
|
||||
pub async fn resolve_uri(&self, uri: &str) -> Result<SpotifyItem, SpotifyError> {
|
||||
let parts = uri.split(':').skip(1).collect::<Vec<&str>>();
|
||||
let id = parts[1];
|
||||
match parts[0] {
|
||||
"track" => {
|
||||
let track = self.spotify.tracks().get_track(id, None).await?;
|
||||
Ok(SpotifyItem::Track(track.data))
|
||||
}
|
||||
"playlist" => {
|
||||
let playlist = self.spotify.playlists().get_playlist(id, None).await?;
|
||||
Ok(SpotifyItem::Playlist(playlist.data))
|
||||
}
|
||||
"album" => {
|
||||
let album = self.spotify.albums().get_album(id, None).await?;
|
||||
Ok(SpotifyItem::Album(album.data))
|
||||
}
|
||||
"artist" => {
|
||||
let artist = self.spotify.artists().get_artist(id).await?;
|
||||
Ok(SpotifyItem::Artist(artist.data))
|
||||
}
|
||||
// Unsupported / Unimplemented
|
||||
_ => Ok(SpotifyItem::Other(uri.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all tracks from playlist
|
||||
pub async fn full_playlist(&self, id: &str) -> Result<Vec<Track>, SpotifyError> {
|
||||
let mut items = vec![];
|
||||
let mut offset = 0;
|
||||
loop {
|
||||
let page = self
|
||||
.spotify
|
||||
.playlists()
|
||||
.get_playlists_items(id, 100, offset, None)
|
||||
.await?;
|
||||
items.append(
|
||||
&mut page
|
||||
.data
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|i| -> Option<Track> {
|
||||
if let Some(PlaylistItemType::Track(t)) = &i.item {
|
||||
Some(t.to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
/// Get search results for query
|
||||
pub async fn search(&self, query: &str) -> Result<Vec<Track>, SpotifyError> {
|
||||
Ok(self
|
||||
.spotify
|
||||
.search()
|
||||
.search(query, [ItemType::Track], true, 50, 0, None)
|
||||
.await?
|
||||
.data
|
||||
.tracks
|
||||
.unwrap()
|
||||
.items)
|
||||
}
|
||||
|
||||
// End
|
||||
offset += page.data.items.len();
|
||||
if page.data.total == offset {
|
||||
return Ok(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Get all tracks from playlist
|
||||
pub async fn full_playlist(&self, id: &str) -> Result<Vec<Track>, SpotifyError> {
|
||||
let mut items = vec![];
|
||||
let mut offset = 0;
|
||||
loop {
|
||||
let page = self
|
||||
.spotify
|
||||
.playlists()
|
||||
.get_playlists_items(id, 100, offset, None)
|
||||
.await?;
|
||||
items.append(
|
||||
&mut page
|
||||
.data
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|i| -> Option<Track> {
|
||||
if let Some(PlaylistItemType::Track(t)) = &i.item {
|
||||
Some(t.to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
|
||||
/// Get all tracks from album
|
||||
pub async fn full_album(&self, id: &str) -> Result<Vec<TrackSimplified>, SpotifyError> {
|
||||
let mut items = vec![];
|
||||
let mut offset = 0;
|
||||
loop {
|
||||
let page = self
|
||||
.spotify
|
||||
.albums()
|
||||
.get_album_tracks(id, 50, offset, None)
|
||||
.await?;
|
||||
items.append(&mut page.data.items.to_vec());
|
||||
// End
|
||||
offset += page.data.items.len();
|
||||
if page.data.total == offset {
|
||||
return Ok(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End
|
||||
offset += page.data.items.len();
|
||||
if page.data.total == offset {
|
||||
return Ok(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Get all tracks from album
|
||||
pub async fn full_album(&self, id: &str) -> Result<Vec<TrackSimplified>, SpotifyError> {
|
||||
let mut items = vec![];
|
||||
let mut offset = 0;
|
||||
loop {
|
||||
let page = self
|
||||
.spotify
|
||||
.albums()
|
||||
.get_album_tracks(id, 50, offset, None)
|
||||
.await?;
|
||||
items.append(&mut page.data.items.to_vec());
|
||||
|
||||
/// Get all tracks from artist
|
||||
pub async fn full_artist(&self, id: &str) -> Result<Vec<TrackSimplified>, SpotifyError> {
|
||||
let mut items = vec![];
|
||||
let mut offset = 0;
|
||||
loop {
|
||||
let page = self
|
||||
.spotify
|
||||
.artists()
|
||||
.get_artist_albums(id, None, 50, offset, None)
|
||||
.await?;
|
||||
// End
|
||||
offset += page.data.items.len();
|
||||
if page.data.total == offset {
|
||||
return Ok(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for album in &mut page.data.items.iter() {
|
||||
items.append(&mut self.full_album(&album.id).await?)
|
||||
}
|
||||
/// Get all tracks from artist
|
||||
pub async fn full_artist(&self, id: &str) -> Result<Vec<TrackSimplified>, SpotifyError> {
|
||||
let mut items = vec![];
|
||||
let mut offset = 0;
|
||||
loop {
|
||||
let page = self
|
||||
.spotify
|
||||
.artists()
|
||||
.get_artist_albums(id, None, 50, offset, None)
|
||||
.await?;
|
||||
|
||||
// End
|
||||
offset += page.data.items.len();
|
||||
if page.data.total == offset {
|
||||
return Ok(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
for album in &mut page.data.items.iter() {
|
||||
items.append(&mut self.full_album(&album.id).await?)
|
||||
}
|
||||
|
||||
// End
|
||||
offset += page.data.items.len();
|
||||
if page.data.total == offset {
|
||||
return Ok(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Spotify {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
session: self.session.clone(),
|
||||
spotify: Client::new(self.spotify.credentials.clone()),
|
||||
}
|
||||
}
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
session: self.session.clone(),
|
||||
spotify: Client::new(self.spotify.credentials.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Basic debug implementation so can be used in other structs
|
||||
impl fmt::Debug for Spotify {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "<Spotify Instance>")
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "<Spotify Instance>")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SpotifyItem {
|
||||
Track(Track),
|
||||
Album(Album),
|
||||
Playlist(Playlist),
|
||||
Artist(Artist),
|
||||
/// Unimplemented
|
||||
Other(String),
|
||||
Track(Track),
|
||||
Album(Album),
|
||||
Playlist(Playlist),
|
||||
Artist(Artist),
|
||||
/// Unimplemented
|
||||
Other(String),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use chrono::NaiveDate;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::downloader::AudioFormat;
|
||||
|
|
@ -16,6 +17,7 @@ pub enum TagWrap {
|
|||
}
|
||||
|
||||
impl TagWrap {
|
||||
|
||||
/// Load from file
|
||||
pub fn new(path: impl AsRef<Path>, format: AudioFormat) -> Result<TagWrap, SpotifyError> {
|
||||
match format {
|
||||
|
|
@ -27,10 +29,10 @@ impl TagWrap {
|
|||
|
||||
/// Get Tag trait
|
||||
pub fn get_tag(&mut self) -> Box<&mut dyn Tag> {
|
||||
match self {
|
||||
TagWrap::Ogg(tag) => Box::new(tag),
|
||||
TagWrap::Id3(tag) => Box::new(tag),
|
||||
}
|
||||
Box::new(match self {
|
||||
TagWrap::Ogg(tag) => tag,
|
||||
TagWrap::Id3(tag) => tag,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue