@@ -9,7 +9,7 @@ use magic_crypt::{new_magic_crypt, MagicCryptTrait};
9
9
use serde_json:: Value ;
10
10
use soda_resource_tools_lib:: soda:: {
11
11
self ,
12
- entity:: { EmbyRenameStyle , RenameStyle , ResourceType , ScrapeConfig , SodaError , TransferType } ,
12
+ entity:: { RenameStyle , ResourceType , ScrapeConfig , SodaError , TransferType } ,
13
13
} ;
14
14
use tracing_appender:: non_blocking:: NonBlocking ;
15
15
use tracing_subscriber:: { filter, fmt:: time:: ChronoLocal , layer:: SubscriberExt , util:: SubscriberInitExt , Layer } ;
@@ -72,6 +72,12 @@ enum Commands {
72
72
/// 刮削图片
73
73
#[ arg( long) ]
74
74
scrape_image : Option < bool > ,
75
+
76
+ /// 重命名格式
77
+ #[ arg( long, value_parser = clap:: builder:: PossibleValuesParser :: new( [ "emby" ] )
78
+ . map( |s| s. parse:: <RenameStyle >( ) . unwrap( ) ) ,
79
+ ) ]
80
+ rename_style : Option < RenameStyle > ,
75
81
} ,
76
82
}
77
83
@@ -118,34 +124,43 @@ fn main() {
118
124
tracing:: info!( target: "soda::info" , "缓存文件目录: {}" , cache_dir. to_str( ) . unwrap( ) ) ;
119
125
tracing:: info!( target: "soda::info" , "日志文件目录: {}" , log_dir. to_str( ) . unwrap( ) ) ;
120
126
121
- // 开发者配置
122
- if dev {
123
- let lib_dir = current_dir ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . join ( "soda_resource_tools_lib" ) ;
124
- init_lib_config_dev ( & lib_dir) ;
125
- }
126
- // Release配置
127
- else {
128
- if let Ok ( ( ) ) = init_config ( & config_dir) {
129
- tracing:: info!( target: "soda::info" , "初始化配置文件成功" ) ;
130
- } else {
131
- tracing:: error!( target: "soda::info" , "初始化配置文件失败" ) ;
132
- return ;
133
- }
127
+ match args. command {
128
+ Commands :: Scrape {
129
+ resource_type,
130
+ transfer_type,
131
+ src_dir,
132
+ target_dir,
133
+ scrape_image,
134
+ rename_style : rename_format,
135
+ } => {
136
+ let rename_style = rename_format. unwrap_or ( RenameStyle :: Emby ) ;
137
+
138
+ // 开发者配置
139
+ if dev {
140
+ let lib_dir = current_dir ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . join ( "soda_resource_tools_lib" ) ;
141
+ init_lib_config_dev ( & lib_dir, & rename_style) ;
142
+ }
143
+ // Release配置
144
+ else {
145
+ if let Ok ( ( ) ) = init_config ( & config_dir) {
146
+ tracing:: info!( target: "soda::info" , "初始化配置文件成功" ) ;
147
+ } else {
148
+ tracing:: error!( target: "soda::info" , "初始化配置文件失败" ) ;
149
+ return ;
150
+ }
134
151
135
- let local_soda_config_path = config_dir. join ( "soda_config.json" ) ;
136
- let local_soda_config: Value = serde_json:: from_str ( & fs:: read_to_string ( & local_soda_config_path) . unwrap ( ) ) . unwrap ( ) ;
137
- tracing:: info!( target: "soda::info" , "配置文件: {}" , local_soda_config) ;
152
+ let local_soda_config_path = config_dir. join ( "soda_config.json" ) ;
153
+ let local_soda_config: Value = serde_json:: from_str ( & fs:: read_to_string ( & local_soda_config_path) . unwrap ( ) ) . unwrap ( ) ;
154
+ tracing:: info!( target: "soda::info" , "配置文件: {}" , local_soda_config) ;
138
155
139
- if !local_soda_config. get ( "enable_cli" ) . unwrap ( ) . as_bool ( ) . unwrap ( ) {
140
- tracing:: error!( target: "soda::info" , "配置文件中enable_cli为false,不允许使用soda_cli" ) ;
141
- return ;
142
- }
156
+ if !local_soda_config. get ( "enable_cli" ) . unwrap ( ) . as_bool ( ) . unwrap ( ) {
157
+ tracing:: error!( target: "soda::info" , "配置文件中enable_cli为false,不允许使用soda_cli" ) ;
158
+ return ;
159
+ }
143
160
144
- init_lib_config ( & local_soda_config, & config_dir, & cache_dir) ;
145
- }
161
+ init_lib_config ( & local_soda_config, & config_dir, & cache_dir, & rename_style ) ;
162
+ }
146
163
147
- match args. command {
148
- Commands :: Scrape { resource_type, transfer_type, src_dir, target_dir, scrape_image } => {
149
164
if src_dir. is_some ( ) {
150
165
let src_dir = src_dir. clone ( ) . unwrap ( ) ;
151
166
let target_dir = if target_dir. is_some ( ) { target_dir. unwrap ( ) } else { src_dir. clone ( ) } ;
@@ -165,7 +180,7 @@ fn main() {
165
180
}
166
181
}
167
182
168
- fn init_lib_config ( local_soda_config : & Value , config_dir : & Path , cache_dir : & Path ) {
183
+ fn init_lib_config ( local_soda_config : & Value , config_dir : & Path , cache_dir : & Path , rename_style : & RenameStyle ) {
169
184
let mc = new_magic_crypt ! ( "biezhihua_soda" , 256 ) ;
170
185
171
186
let bin_path_name = local_soda_config. get ( "bin" ) . unwrap ( ) . as_str ( ) . unwrap ( ) ;
@@ -190,21 +205,21 @@ fn init_lib_config(local_soda_config: &Value, config_dir: &Path, cache_dir: &Pat
190
205
config. strong_match_regex_rules_path = "" . to_string ( ) ;
191
206
config. strong_match_name_map_path = "" . to_string ( ) ;
192
207
config. metadata_skip_special = true ;
193
- config. movie_rename_format = Some ( RenameStyle :: Emby ( EmbyRenameStyle :: EmbyMovie ) ) ;
194
- config. tv_rename_format = Some ( RenameStyle :: Emby ( EmbyRenameStyle :: EmbyTV ) ) ;
208
+ config. movie_rename_format = Some ( rename_style . clone ( ) ) ;
209
+ config. tv_rename_format = Some ( rename_style . clone ( ) ) ;
195
210
soda:: update_lib_config ( config) ;
196
211
tracing:: info!( target: "soda::info" , "配置更新成功" ) ;
197
212
}
198
213
199
- fn init_lib_config_dev ( lib_dir : & Path ) {
214
+ fn init_lib_config_dev ( lib_dir : & Path , rename_style : & RenameStyle ) {
200
215
let mut config = soda:: get_lib_config ( ) ;
201
216
config. cache_path = lib_dir. join ( "cache" ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
202
217
config. strong_match_rules_tv_path = lib_dir. join ( "config" ) . join ( "mt_strong_match_rules_tv.json" ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
203
218
config. strong_match_rules_movie_path = lib_dir. join ( "config" ) . join ( "mt_strong_match_rules_movie.json" ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
204
219
config. strong_match_regex_rules_path = lib_dir. join ( "config" ) . join ( "mt_strong_match_regex_rules.json" ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
205
220
config. strong_match_name_map_path = lib_dir. join ( "config" ) . join ( "mt_strong_match_name_map.json" ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
206
- config. movie_rename_format = Some ( RenameStyle :: Emby ( EmbyRenameStyle :: EmbyMovie ) ) ;
207
- config. tv_rename_format = Some ( RenameStyle :: Emby ( EmbyRenameStyle :: EmbyTV ) ) ;
221
+ config. movie_rename_format = Some ( rename_style . clone ( ) ) ;
222
+ config. tv_rename_format = Some ( rename_style . clone ( ) ) ;
208
223
config. metadata_skip_special = true ;
209
224
soda:: update_lib_config ( config) ;
210
225
tracing:: info!( target: "soda::info" , "配置更新成功" ) ;
0 commit comments