1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
use sync_dis_boi::ConfigArgs;
use tracing::Level;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct RootArgs {
/// The source music platform
#[command(subcommand)]
pub src: MusicPlatformSrc,
#[command(flatten)]
pub config: ConfigArgs,
/// Logging level
#[arg(short, long, value_enum, default_value_t = LoggingLevel::Info)]
pub logging: LoggingLevel,
}
#[derive(Subcommand, Clone, Debug)]
#[command(subcommand_value_name = "SRC_PLATFORM")]
pub enum MusicPlatformSrc {
YtMusic {
/// The path to the headers JSON file
#[arg(long)]
headers: Option<PathBuf>,
/// The client ID for the Youtube API application
#[arg(
long,
env = "YTMUSIC_CLIENT_ID",
conflicts_with = "headers",
requires = "client_secret"
)]
client_id: Option<String>,
/// The client secret for the Youtube API application
#[arg(long, env = "YTMUSIC_CLIENT_SECRET", conflicts_with = "headers")]
client_secret: Option<String>,
/// Clear the cached ytmusic_oauth.json file
#[arg(long, requires = "client_id", requires = "client_secret")]
clear_cache: bool,
/// The destination music platform
#[command(subcommand)]
dst: MusicPlatformDst,
},
Spotify {
/// The client ID for the Spotify API application
#[arg(long, env = "SPOTIFY_CLIENT_ID")]
client_id: String,
/// The client secret for the Spotify API application
#[arg(long, env = "SPOTIFY_CLIENT_SECRET")]
client_secret: String,
/// Clear the cached spotify_oauth.json file
#[arg(long)]
clear_cache: bool,
/// The destination music platform
#[command(subcommand)]
dst: MusicPlatformDst,
},
Tidal {
/// The client ID for the Tidal API application
#[arg(long, env = "TIDAL_CLIENT_ID", default_value = "zU4XHVVkc2tDPo4t")]
client_id: String,
/// The client secret for the Tidal API application
#[arg(
long,
env = "TIDAL_CLIENT_SECRET",
default_value = "VJKhDFqJPqvsPVNBV6ukXTJmwlvbttP7wlMlrc72se4="
)]
client_secret: String,
/// Clear the cached tidal_oauth.json file
#[arg(long)]
clear_cache: bool,
/// The destination music platform
#[command(subcommand)]
dst: MusicPlatformDst,
},
}
// INFO: Hack to support command chaining with clap
// related issue: https://github.com/clap-rs/clap/issues/2222
#[derive(Subcommand, Clone, Debug)]
#[command(subcommand_value_name = "DST_PLATFORM")]
pub enum MusicPlatformDst {
YtMusic {
/// The path to the headers JSON file
#[arg(long)]
headers: Option<PathBuf>,
/// The client ID for the Youtube API application
#[arg(
long,
env = "YTMUSIC_CLIENT_ID",
conflicts_with = "headers",
requires = "client_secret"
)]
client_id: Option<String>,
/// The client secret for the Youtube API application
#[arg(long, env = "YTMUSIC_CLIENT_SECRET", conflicts_with = "headers")]
client_secret: Option<String>,
/// Clear the cached ytmusic_oauth.json file
#[arg(long, requires = "client_id", requires = "client_secret")]
clear_cache: bool,
},
Spotify {
/// The client ID for the Spotify API application
#[arg(long, env = "SPOTIFY_CLIENT_ID")]
client_id: String,
/// The client secret for the Spotify API application
#[arg(long, env = "SPOTIFY_CLIENT_SECRET")]
client_secret: String,
/// Clear the cached spotify_oauth.json file
#[arg(long)]
clear_cache: bool,
},
Tidal {
/// The client ID for the Tidal API application
#[arg(long, env = "TIDAL_CLIENT_ID", default_value = "zU4XHVVkc2tDPo4t")]
client_id: String,
#[arg(
long,
env = "TIDAL_CLIENT_SECRET",
default_value = "VJKhDFqJPqvsPVNBV6ukXTJmwlvbttP7wlMlrc72se4="
)]
/// The client secret for the Tidal API application
client_secret: String,
/// Clear the cached tidal_oauth.json file
#[arg(long)]
clear_cache: bool,
},
Export {
/// The path to the file to export the playlists to
#[arg(short, long)]
output: PathBuf,
/// Minify the exported JSON file
#[arg(long, default_value = "false")]
minify: bool,
},
Import {
/// The path to the file to import the playlists from
#[arg(short, long)]
input: PathBuf,
},
}
#[derive(ValueEnum, Clone, Debug)]
pub enum LoggingLevel {
/// Only log errors
Error,
/// Log errors and warnings
Warn,
/// Log errors, warnings and info
Info,
/// Log errors, warnings, info and debug (very verbose)
Debug,
}
impl From<LoggingLevel> for Level {
fn from(level: LoggingLevel) -> Self {
match level {
LoggingLevel::Warn => Level::WARN,
LoggingLevel::Error => Level::ERROR,
LoggingLevel::Info => Level::INFO,
LoggingLevel::Debug => Level::DEBUG,
}
}
}