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    /// Use Apple Silicon encoder (aac_at)
114    #[arg(long)]
115    pub use_apple_silicon_encoder: Option<bool>,
116
117    /// Fetch metadata from Audible during build
118    #[arg(long)]
119    pub fetch_audible: bool,
120
121    /// Audible region (us, uk, ca, au, fr, de, jp, it, in, es)
122    #[arg(long)]
123    pub audible_region: Option<String>,
124
125    /// Auto-match books with Audible by folder name
126    #[arg(long)]
127    pub audible_auto_match: bool,
128
129    /// Configuration file path
130    #[arg(long)]
131    pub config: Option<PathBuf>,
132}
133
134#[derive(Args)]
135pub struct OrganizeArgs {
136    /// Root directory to organize
137    #[arg(short, long)]
138    pub root: Option<PathBuf>,
139
140    /// Dry run (show what would be done)
141    #[arg(long)]
142    pub dry_run: bool,
143
144    /// Configuration file path
145    #[arg(long)]
146    pub config: Option<PathBuf>,
147}
148
149#[derive(Subcommand)]
150pub enum ConfigCommands {
151    /// Initialize config file with defaults
152    Init {
153        /// Overwrite existing config file
154        #[arg(long)]
155        force: bool,
156    },
157
158    /// Show current configuration
159    Show {
160        /// Configuration file path
161        #[arg(long)]
162        config: Option<PathBuf>,
163    },
164
165    /// Validate configuration file
166    Validate {
167        /// Configuration file path
168        #[arg(long)]
169        config: Option<PathBuf>,
170    },
171
172    /// Show config file path
173    Path,
174
175    /// Edit config file in default editor
176    Edit,
177}
178
179#[derive(Subcommand)]
180pub enum MetadataCommands {
181    /// Fetch metadata from Audible
182    Fetch {
183        /// Audible ASIN (B002V5D7RU format)
184        #[arg(long)]
185        asin: Option<String>,
186
187        /// Search by title
188        #[arg(long)]
189        title: Option<String>,
190
191        /// Search by author
192        #[arg(long)]
193        author: Option<String>,
194
195        /// Audible region (us, uk, ca, au, fr, de, jp, it, in, es)
196        #[arg(long, default_value = "us")]
197        region: String,
198
199        /// Save metadata to JSON file
200        #[arg(long)]
201        output: Option<PathBuf>,
202    },
203
204    /// Enrich M4B file with Audible metadata
205    Enrich {
206        /// M4B file to enrich
207        #[arg(long)]
208        file: PathBuf,
209
210        /// Audible ASIN
211        #[arg(long)]
212        asin: Option<String>,
213
214        /// Auto-detect ASIN from filename
215        #[arg(long)]
216        auto_detect: bool,
217
218        /// Audible region
219        #[arg(long, default_value = "us")]
220        region: String,
221    },
222}
223
224/// Arguments for the match command
225#[derive(Args)]
226pub struct MatchArgs {
227    /// M4B file to match
228    #[arg(long, short = 'f', conflicts_with = "dir")]
229    pub file: Option<PathBuf>,
230
231    /// Directory of M4B files
232    #[arg(long, short = 'd', conflicts_with = "file")]
233    pub dir: Option<PathBuf>,
234
235    /// Manual title override
236    #[arg(long)]
237    pub title: Option<String>,
238
239    /// Manual author override
240    #[arg(long)]
241    pub author: Option<String>,
242
243    /// Auto mode (non-interactive, select best match)
244    #[arg(long)]
245    pub auto: bool,
246
247    /// Audible region
248    #[arg(long, default_value = "us")]
249    pub region: String,
250
251    /// Keep existing cover art instead of downloading
252    #[arg(long)]
253    pub keep_cover: bool,
254
255    /// Dry run (show matches but don't apply)
256    #[arg(long)]
257    pub dry_run: bool,
258}