why. why is programming the way it is. it is october 2023 not january 1970. fuck this. fuck everything

This commit is contained in:
SadlyNotSappho 2023-10-24 11:54:04 -07:00
parent 09a70b39df
commit 3d5ec6f844
4 changed files with 40 additions and 9 deletions

13
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -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,7 +16,8 @@ struct Cli {
config_file: String,
}
fn main() {
#[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();
@ -31,7 +32,7 @@ fn main() {
// handle args
let args = Cli::parse();
println!("url: {}", args.url);
// 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:?}");
}

View File

@ -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) => {