Things idk
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
|
||||
|
||||
@@ -11,16 +11,16 @@ pub struct Song {
|
||||
}
|
||||
|
||||
impl Song {
|
||||
pub fn new(url: &url::Url) -> crate::Result<Self> {
|
||||
pub fn new(url: &url::Url, source_type: SourceType) -> crate::Result<Self> {
|
||||
Ok(Self {
|
||||
name: String::default(),
|
||||
author: String::default(),
|
||||
source_type: SourceType::from_url(url)?,
|
||||
source_type,
|
||||
url: url.clone()
|
||||
})
|
||||
}
|
||||
pub fn new_from_str(url: &str) -> crate::Result<Self> {
|
||||
Self::new(&url::Url::from_str(url)?)
|
||||
pub fn new_from_str(url: &str, source_type: SourceType) -> crate::Result<Self> {
|
||||
Self::new(&url::Url::from_str(url)?, source_type)
|
||||
}
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
@@ -48,21 +48,26 @@ impl Song {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, PartialOrd)]
|
||||
pub enum SourceType {
|
||||
Youtube,
|
||||
Spotify,
|
||||
Soundcloud,
|
||||
HttpBare,
|
||||
HttpZip,
|
||||
Http7z
|
||||
}
|
||||
|
||||
impl SourceType {
|
||||
fn from_url(url: &url::Url) -> crate::Result<Self> {
|
||||
fn from_url(url: &url::Url) -> Option<Self> {
|
||||
match url.host_str() {
|
||||
Some("youtube.com") | Some("youtu.be") => Ok(Self::Youtube),
|
||||
Some("open.spotify.com") => Ok(Self::Spotify),
|
||||
Some("soundcloud.com") |Some("on.soundcloud.com") => Ok(Self::Soundcloud),
|
||||
Some(host) => anyhow::bail!("Unknown host {host:?}"),
|
||||
None => anyhow::bail!("Unknown host: (none)"),
|
||||
Some("youtube.com") | Some("youtu.be") =>
|
||||
Some(Self::Youtube),
|
||||
Some("open.spotify.com") =>
|
||||
Some(Self::Spotify),
|
||||
Some("soundcloud.com") | Some("on.soundcloud.com") =>
|
||||
Some(Self::Soundcloud),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user