audiobook_forge/cli/
commands.rs

1//! CLI commands and arguments
2
3use clap::{Parser, Subcommand, Args};
4use std::path::PathBuf;
5
6use crate::VERSION;
7
8/// Audiobook Forge - Convert audiobook directories to M4B format
9#[derive(Parser)]
10#[command(name = "audiobook-forge")]
11#[command(version = VERSION)]
12#[command(about = "Convert audiobook directories to M4B format with chapters and metadata")]
13#[command(long_about = "
14Audiobook Forge is a CLI tool that converts audiobook directories containing
15MP3 files into high-quality M4B audiobook files with proper chapters and metadata.
16
17Features:
18• Automatic quality detection and preservation
19• Smart chapter generation from multiple sources
20• Parallel batch processing
21• Metadata extraction and enhancement
22• Cover art embedding
23")]
24pub struct Cli {
25    #[command(subcommand)]
26    pub command: Commands,
27
28    /// Enable verbose output
29    #[arg(global = true, short, long)]
30    pub verbose: bool,
31}
32
33#[derive(Subcommand)]
34pub enum Commands {
35    /// Process audiobooks and convert to M4B
36    Build(BuildArgs),
37
38    /// Organize audiobooks into M4B and To_Convert folders
39    Organize(OrganizeArgs),
40
41    /// Manage configuration
42    #[command(subcommand)]
43    Config(ConfigCommands),
44
45    /// Fetch and manage Audible metadata
46    #[command(subcommand)]
47    Metadata(MetadataCommands),
48
49    /// Interactive metadata matching for M4B files
50    Match(MatchArgs),
51
52    /// Check system dependencies
53    Check,
54
55    /// Show version information
56    Version,
57}
58
59#[derive(Args)]
60pub struct BuildArgs {
61    /// Root directory containing audiobook folders
62    #[arg(short, long)]
63    pub root: Option<PathBuf>,
64
65    /// Output directory (defaults to same as root)
66    #[arg(short, long)]
67    pub out: Option<PathBuf>,
68
69    /// Number of parallel workers (1-8)
70    #[arg(short = 'j', long, value_parser = clap::value_parser!(u8).range(1..=8))]
71    pub parallel: Option<u8>,
72
73    /// Skip folders with existing M4B files
74    #[arg(long)]
75    pub skip_existing: Option<bool>,
76
77    /// Force reprocessing (overwrite existing)
78    #[arg(long)]
79    pub force: bool,
80
81    /// Normalize existing M4B files (fix metadata)
82    #[arg(long)]
83    pub normalize: bool,
84
85    /// Dry run (analyze without creating files)
86    #[arg(long)]
87    pub dry_run: bool,
88
89    /// Prefer stereo over mono
90    #[arg(long)]
91    pub prefer_stereo: Option<bool>,
92
93    /// Chapter source priority
94    #[arg(long, value_parser = ["auto", "files", "cue", "id3", "none"])]
95    pub chapter_source: Option<String>,
96
97    /// Cover art filenames (comma-separated)
98    #[arg(long)]
99    pub cover_names: Option<String>,
100
101    /// Default language for metadata
102    #[arg(long)]
103    pub language: Option<String>,
104
105    /// Keep temporary files for debugging
106    #[arg(long)]
107    pub keep_temp: bool,
108
109    /// Delete original files after conversion
110    #[arg(long)]
111    pub delete_originals: bool,
112
113    /// AAC encoder to use (auto, aac_at, libfdk_aac, aac)
114    #[arg(long)]
115    pub aac_encoder: Option<String>,
116
117    /// DEPRECATED: Use --aac-encoder instead
118    #[arg(long, hide = true)]
119    pub use_apple_silicon_encoder: Option<bool>,
120
121    /// Fetch metadata from Audible during build
122    #[arg(long)]
123    pub fetch_audible: bool,
124
125    /// Audible region (us, uk, ca, au, fr, de, jp, it, in, es)
126    #[arg(long)]
127    pub audible_region: Option<String>,
128
129    /// Auto-match books with Audible by folder name
130    #[arg(long)]
131    pub audible_auto_match: bool,
132
133    /// Configuration file path
134    #[arg(long)]
135    pub config: Option<PathBuf>,
136}
137
138#[derive(Args)]
139pub struct OrganizeArgs {
140    /// Root directory to organize
141    #[arg(short, long)]
142    pub root: Option<PathBuf>,
143
144    /// Dry run (show what would be done)
145    #[arg(long)]
146    pub dry_run: bool,
147
148    /// Configuration file path
149    #[arg(long)]
150    pub config: Option<PathBuf>,
151}
152
153#[derive(Subcommand)]
154pub enum ConfigCommands {
155    /// Initialize config file with defaults
156    Init {
157        /// Overwrite existing config file
158        #[arg(long)]
159        force: bool,
160    },
161
162    /// Show current configuration
163    Show {
164        /// Configuration file path
165        #[arg(long)]
166        config: Option<PathBuf>,
167    },
168
169    /// Validate configuration file
170    Validate {
171        /// Configuration file path
172        #[arg(long)]
173        config: Option<PathBuf>,
174    },
175
176    /// Show config file path
177    Path,
178
179    /// Edit config file in default editor
180    Edit,
181}
182
183#[derive(Subcommand)]
184pub enum MetadataCommands {
185    /// Fetch metadata from Audible
186    Fetch {
187        /// Audible ASIN (B002V5D7RU format)
188        #[arg(long)]
189        asin: Option<String>,
190
191        /// Search by title
192        #[arg(long)]
193        title: Option<String>,
194
195        /// Search by author
196        #[arg(long)]
197        author: Option<String>,
198
199        /// Audible region (us, uk, ca, au, fr, de, jp, it, in, es)
200        #[arg(long, default_value = "us")]
201        region: String,
202
203        /// Save metadata to JSON file
204        #[arg(long)]
205        output: Option<PathBuf>,
206    },
207
208    /// Enrich M4B file with Audible metadata
209    Enrich {
210        /// M4B file to enrich
211        #[arg(long)]
212        file: PathBuf,
213
214        /// Audible ASIN
215        #[arg(long)]
216        asin: Option<String>,
217
218        /// Auto-detect ASIN from filename
219        #[arg(long)]
220        auto_detect: bool,
221
222        /// Audible region
223        #[arg(long, default_value = "us")]
224        region: String,
225    },
226}
227
228/// Arguments for the match command
229#[derive(Args)]
230pub struct MatchArgs {
231    /// M4B file to match
232    #[arg(long, short = 'f', conflicts_with = "dir")]
233    pub file: Option<PathBuf>,
234
235    /// Directory of M4B files
236    #[arg(long, short = 'd', conflicts_with = "file")]
237    pub dir: Option<PathBuf>,
238
239    /// Manual title override
240    #[arg(long)]
241    pub title: Option<String>,
242
243    /// Manual author override
244    #[arg(long)]
245    pub author: Option<String>,
246
247    /// Auto mode (non-interactive, select best match)
248    #[arg(long)]
249    pub auto: bool,
250
251    /// Audible region
252    #[arg(long, default_value = "us")]
253    pub region: String,
254
255    /// Keep existing cover art instead of downloading
256    #[arg(long)]
257    pub keep_cover: bool,
258
259    /// Dry run (show matches but don't apply)
260    #[arg(long)]
261    pub dry_run: bool,
262}