forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1use clap::{arg, 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#[tokio::main]
42async fn main() -> Result<(), Box<dyn std::error::Error>> {
43 let format = Format::default()
44 .with_level(true)
45 .with_target(true)
46 .with_ansi(true)
47 .compact();
48
49 tracing_subscriber::fmt()
50 .event_format(format)
51 .with_max_level(tracing::Level::INFO)
52 .init();
53
54 dotenv().ok();
55
56 let args = cli().get_matches();
57
58 match args.subcommand() {
59 Some(("analytics", sub_m)) => match sub_m.subcommand() {
60 Some(("sync", _)) => cmd::analytics::sync().await?,
61 Some(("serve", _)) => cmd::analytics::serve().await?,
62 _ => println!("Unknown analytics command"),
63 },
64 Some(("dropbox", sub_m)) => match sub_m.subcommand() {
65 Some(("scan", _)) => cmd::dropbox::scan().await?,
66 Some(("serve", _)) => cmd::dropbox::serve().await?,
67 _ => println!("Unknown dropbox command"),
68 },
69 Some(("googledrive", sub_m)) => match sub_m.subcommand() {
70 Some(("scan", _)) => cmd::googledrive::scan().await?,
71 Some(("serve", _)) => cmd::googledrive::serve().await?,
72 _ => println!("Unknown googledrive command"),
73 },
74 Some(("jetstream", _)) => {
75 cmd::jetstream::start_jetstream_service().await?;
76 }
77 Some(("playlist", _)) => {
78 cmd::playlist::start_playlist_service().await?;
79 }
80 Some(("scrobbler", _)) => {
81 cmd::scrobbler::start_scrobbler_service().await?;
82 }
83 Some(("spotify", _)) => {
84 cmd::spotify::start_spotify_service().await?;
85 }
86 Some(("tracklist", _)) => {
87 cmd::tracklist::start_tracklist_service().await?;
88 }
89 Some(("webscrobbler", _)) => {
90 cmd::webscrobbler::start_webscrobbler_service().await?;
91 }
92 Some(("pull", _)) => {
93 cmd::pull::pull_data().await?;
94 }
95 _ => {
96 println!("No valid subcommand was used. Use --help to see available commands.");
97 }
98 }
99
100 Ok(())
101}