why. why is programming the way it is. it is october 2023 not january 1970. fuck this. fuck everything
This commit is contained in:
parent
09a70b39df
commit
3d5ec6f844
|
@ -686,6 +686,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_json",
|
||||
"spotify-rs",
|
||||
"tokio",
|
||||
"which",
|
||||
]
|
||||
|
||||
|
@ -1332,9 +1333,21 @@ dependencies = [
|
|||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"socket2 0.5.4",
|
||||
"tokio-macros",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.1"
|
||||
|
|
|
@ -11,4 +11,5 @@ regex = "1.10.2"
|
|||
serde = { version = "1.0.189", features = ["derive"] }
|
||||
serde_json = "1.0.107"
|
||||
spotify-rs = "0.3.9"
|
||||
tokio = { version = "1.33.0", features = ["rt-multi-thread", "macros"] }
|
||||
which = "4.4.2"
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -1,7 +1,7 @@
|
|||
use std::process;
|
||||
|
||||
use clap::Parser;
|
||||
use music_downloader::structs::Spotify;
|
||||
use music_downloader::{read_config, structs::Spotify};
|
||||
use spotify_rs::{ClientCredsClient, ClientCredsFlow};
|
||||
use std::process;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
|
@ -16,8 +16,9 @@ struct Cli {
|
|||
config_file: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// check for deps
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// check for deps
|
||||
let ytdlp_exists = which::which("yt-dlp").is_ok();
|
||||
let ffmpeg_exists = which::which("ffmpeg").is_ok();
|
||||
if !ytdlp_exists {
|
||||
|
@ -30,8 +31,8 @@ fn main() {
|
|||
}
|
||||
|
||||
// handle args
|
||||
let args = Cli::parse();
|
||||
println!("url: {}", args.url);
|
||||
let args = Cli::parse();
|
||||
// println!("url: {}", args.url);
|
||||
println!("download from: {}", args.download_from);
|
||||
|
||||
// init config
|
||||
|
@ -39,6 +40,22 @@ fn main() {
|
|||
|
||||
// run???
|
||||
let spot = Spotify::from_link(&args.url);
|
||||
println!("{spot:?}");
|
||||
// TODO: get song info
|
||||
// TODO: add a way to put data in config from cli
|
||||
|
||||
let config = read_config(&args.config_file[..]);
|
||||
|
||||
let auth_flow = ClientCredsFlow::new(config.client_id, config.client_secret);
|
||||
|
||||
println!("\n{auth_flow:?}\n");
|
||||
|
||||
// Create an authenticate the client
|
||||
let mut spotify = ClientCredsClient::authenticate(auth_flow).await.unwrap();
|
||||
println!("\n{:?}\n", spotify.refresh_token());
|
||||
spotify.request_refresh_token().await.unwrap();
|
||||
|
||||
let album = spotify.album(&spot.id[..]).get().await.unwrap();
|
||||
|
||||
println!("{album:?}");
|
||||
}
|
||||
|
|
|
@ -8,12 +8,13 @@ pub struct Config {
|
|||
pub client_id: String,
|
||||
pub client_secret: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Spotify {
|
||||
pub mtype: SpotifyType,
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SpotifyType {
|
||||
Album, // album: https://open.spotify.com/album/5MfAxS5zz8MlfROjGQVXhy?si=2BBYm0iVR3m4UlQ3xE8RRg
|
||||
Playlist, // playlist: https://open.spotify.com/playlist/1XsYplOyHG528tYcSaZOhT?si=ef60c1c83a744e29
|
||||
|
@ -25,7 +26,6 @@ pub enum SpotifyType {
|
|||
|
||||
impl Spotify {
|
||||
pub fn from_link(url: &String) -> Spotify {
|
||||
println!("{url}");
|
||||
let re = match Regex::new(r#"(open.spotify.com)\/(?<type>album|playlist|track|artist|episode|show)\/(?<id>[^?]*)"#) {
|
||||
Ok(val) => val,
|
||||
Err(why) => {
|
||||
|
|
Loading…
Reference in New Issue