A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at feat/pgpull 102 lines 4.1 kB view raw
1use clap::Command; 2use dotenv::dotenv; 3use tracing_subscriber::fmt::format::Format; 4 5pub mod cmd; 6 7fn cli() -> Command { 8 Command::new("rockskyd") 9 .version(env!("CARGO_PKG_VERSION")) 10 .about("Rocksky Daemon Service") 11 .subcommand( 12 Command::new("analytics") 13 .about("Analytics related commands") 14 .subcommand(Command::new("sync").about("Sync data from Xata to DuckDB")) 15 .subcommand(Command::new("serve").about("Serve the Rocksky Analytics API")), 16 ) 17 .subcommand( 18 Command::new("dropbox") 19 .about("Dropbox related commands") 20 .subcommand(Command::new("scan").about("Scan Dropbox Music Folder")) 21 .subcommand(Command::new("serve").about("Serve Rocksky Dropbox API")), 22 ) 23 .subcommand( 24 Command::new("googledrive") 25 .about("Google Drive related commands") 26 .subcommand(Command::new("scan").about("Scan Google Drive Music Folder")) 27 .subcommand(Command::new("serve").about("Serve Rocksky Google Drive API")), 28 ) 29 .subcommand(Command::new("jetstream").about("Start JetStream Subscriber Service")) 30 .subcommand(Command::new("playlist").about("Playlist related commands")) 31 .subcommand(Command::new("scrobbler").about("Start Scrobbler API")) 32 .subcommand(Command::new("spotify").about("Start Spotify Listener Service")) 33 .subcommand(Command::new("tracklist").about("Start User Current Track Queue Service")) 34 .subcommand(Command::new("webscrobbler").about("Start Webscrobbler API")) 35 .subcommand( 36 Command::new("pull") 37 .about("Pull data from a remote PostgreSQL database to your local PostgresSQL instance") 38 .long_about("Pull data from a remote PostgreSQL database to your local PostgresSQL instance. Ensure that the SOURCE_POSTGRES_URL environment variable is set to your remote PostgreSQL connection string."), 39 ) 40} 41 42#[tokio::main] 43async fn main() -> Result<(), Box<dyn std::error::Error>> { 44 let format = Format::default() 45 .with_level(true) 46 .with_target(true) 47 .with_ansi(true) 48 .compact(); 49 50 tracing_subscriber::fmt() 51 .event_format(format) 52 .with_max_level(tracing::Level::INFO) 53 .init(); 54 55 dotenv().ok(); 56 57 let args = cli().get_matches(); 58 59 match args.subcommand() { 60 Some(("analytics", sub_m)) => match sub_m.subcommand() { 61 Some(("sync", _)) => cmd::analytics::sync().await?, 62 Some(("serve", _)) => cmd::analytics::serve().await?, 63 _ => println!("Unknown analytics command"), 64 }, 65 Some(("dropbox", sub_m)) => match sub_m.subcommand() { 66 Some(("scan", _)) => cmd::dropbox::scan().await?, 67 Some(("serve", _)) => cmd::dropbox::serve().await?, 68 _ => println!("Unknown dropbox command"), 69 }, 70 Some(("googledrive", sub_m)) => match sub_m.subcommand() { 71 Some(("scan", _)) => cmd::googledrive::scan().await?, 72 Some(("serve", _)) => cmd::googledrive::serve().await?, 73 _ => println!("Unknown googledrive command"), 74 }, 75 Some(("jetstream", _)) => { 76 cmd::jetstream::start_jetstream_service().await?; 77 } 78 Some(("playlist", _)) => { 79 cmd::playlist::start_playlist_service().await?; 80 } 81 Some(("scrobbler", _)) => { 82 cmd::scrobbler::start_scrobbler_service().await?; 83 } 84 Some(("spotify", _)) => { 85 cmd::spotify::start_spotify_service().await?; 86 } 87 Some(("tracklist", _)) => { 88 cmd::tracklist::start_tracklist_service().await?; 89 } 90 Some(("webscrobbler", _)) => { 91 cmd::webscrobbler::start_webscrobbler_service().await?; 92 } 93 Some(("pull", _)) => { 94 cmd::pull::pull_data().await?; 95 } 96 _ => { 97 println!("No valid subcommand was used. Use --help to see available commands."); 98 } 99 } 100 101 Ok(()) 102}