mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 20:41:17 +02:00
65 lines
2.0 KiB
Rust
65 lines
2.0 KiB
Rust
use clap::{Arg, Command};
|
|
use tootube::*;
|
|
|
|
const DEFAULT_CONFIG_PATH: &str = "/usr/local/etc/tootube.toml";
|
|
|
|
fn main() {
|
|
let matches = Command::new(env!("CARGO_PKG_NAME"))
|
|
.version(env!("CARGO_PKG_VERSION"))
|
|
.about("A simple PeerTube to YouTube converter")
|
|
.arg(
|
|
Arg::new("config")
|
|
.short('c')
|
|
.long("config")
|
|
.value_name("CONFIG_FILE")
|
|
.help("TOML config file for tootube")
|
|
.num_args(1)
|
|
.default_value(DEFAULT_CONFIG_PATH)
|
|
.display_order(1),
|
|
)
|
|
.arg(
|
|
Arg::new("playlists")
|
|
.short('p')
|
|
.long("playlist")
|
|
.value_name("PLAYLIST")
|
|
.help("List of playlists to add the video to")
|
|
.num_args(0..)
|
|
.display_order(2),
|
|
)
|
|
.subcommand(
|
|
Command::new("register")
|
|
.version(env!("CARGO_PKG_VERSION"))
|
|
.about("Command to register to YouTube OAuth2.0")
|
|
.arg(
|
|
Arg::new("config")
|
|
.short('c')
|
|
.long("config")
|
|
.value_name("CONFIG_FILE")
|
|
.help("TOML config file for tootube")
|
|
.num_args(1)
|
|
.default_value(DEFAULT_CONFIG_PATH)
|
|
.display_order(1),
|
|
),
|
|
)
|
|
.get_matches();
|
|
|
|
if let Some(("register", sub_m)) = matches.subcommand() {
|
|
let config = parse_toml(sub_m.get_one::<String>("config").unwrap());
|
|
register(&config.youtube)
|
|
.unwrap_or_else(|e| panic!("Cannot register to YouTube API: {}", e));
|
|
return;
|
|
}
|
|
|
|
let config = parse_toml(matches.get_one::<String>("config").unwrap());
|
|
|
|
let playlists: Vec<String> = matches
|
|
.get_many::<String>("playlists")
|
|
.unwrap_or_default()
|
|
.map(|v| v.to_string())
|
|
.collect();
|
|
|
|
env_logger::init();
|
|
|
|
run(config, playlists);
|
|
}
|