2021-11-28 08:49:20 +13:00
use std ::path ::PathBuf ;
use img_hash ::{ FilterType , HashAlg } ;
use structopt ::StructOpt ;
2021-02-21 17:59:07 +13:00
use czkawka_core ::duplicate ::{ CheckingMethod , DeleteMethod , HashType } ;
2020-11-03 09:56:07 +13:00
use czkawka_core ::same_music ::MusicSimilarity ;
2021-11-18 23:23:17 +13:00
use czkawka_core ::similar_images ::SimilarityPreset ;
2020-11-03 09:56:07 +13:00
2020-10-05 10:36:49 +13:00
#[ derive(Debug, StructOpt) ]
#[ structopt(name = " czkawka " , help_message = HELP_MESSAGE, template = HELP_TEMPLATE) ]
pub enum Commands {
2021-12-02 00:37:17 +13:00
#[ structopt(name = " dup " , about = " Finds duplicate files " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka dup -d /home/rafal -e /home/rafal/Obrazy -m 25 -x 7z rar IMAGE -s hash -f results.txt -D aeo " ) ]
2020-10-05 10:36:49 +13:00
Duplicates {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_directories : ExcludedDirectories ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_items : ExcludedItems ,
2021-08-07 09:23:11 +12:00
#[ structopt(short, long, parse(try_from_str = parse_minimal_file_size), default_value = " 8192 " , help = " Minimum size in bytes " , long_help = " Minimum size of checked files in bytes, assigning bigger value may speed up searching " ) ]
2020-10-15 08:10:27 +13:00
minimal_file_size : u64 ,
2021-08-07 09:23:11 +12:00
#[ structopt(short = " i " , long, parse(try_from_str = parse_maximal_file_size), default_value = " 18446744073709551615 " , help = " Maximum size in bytes " , long_help = " Maximum size of checked files in bytes, assigning lower value may speed up searching " ) ]
maximal_file_size : u64 ,
2021-12-02 08:09:04 +13:00
#[ structopt(short = " c " , long, parse(try_from_str = parse_minimal_file_size), default_value = " 257144 " , help = " Minimum cached file size in bytes " , long_help = " Minimum size of cached files in bytes, assigning bigger value may speed up will cause that lower amount of files will be cached, but loading of cache will be faster " ) ]
2021-05-07 07:54:44 +12:00
minimal_cached_file_size : u64 ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
allowed_extensions : AllowedExtensions ,
2021-12-02 10:34:49 +13:00
#[ structopt(short, long, default_value = " HASH " , parse(try_from_str = parse_checking_method), help = " Search method (NAME, SIZE, HASH) " , long_help = " Methods to search files. \n NAME - Fast but but rarely usable, \n SIZE - Fast but not accurate, checking by the file's size, \n HASH - The slowest method, checking by the hash of the entire file " ) ]
2020-10-05 10:36:49 +13:00
search_method : CheckingMethod ,
2021-02-06 05:59:34 +13:00
#[ structopt(short = " D " , long, default_value = " NONE " , parse(try_from_str = parse_delete_method), help = " Delete method (AEN, AEO, ON, OO, HARD) " , long_help = " Methods to delete the files. \n AEN - All files except the newest, \n AEO - All files except the oldest, \n ON - Only 1 file, the newest, \n OO - Only 1 file, the oldest \n HARD - create hard link \n NONE - not delete files " ) ]
2020-10-05 10:36:49 +13:00
delete_method : DeleteMethod ,
2021-11-28 08:57:10 +13:00
#[ structopt(short = " ht " , long, default_value = " BLAKE3 " , parse(try_from_str = parse_hash_type), help = " Hash type (BLAKE3, CRC32, XXH3) " ) ]
2021-02-21 17:59:07 +13:00
hash_type : HashType ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
2021-02-23 08:14:33 +13:00
#[ structopt(flatten) ]
allow_hard_links : AllowHardLinks ,
2021-03-02 00:23:43 +13:00
#[ structopt(flatten) ]
dryrun : DryRun ,
2020-10-05 10:36:49 +13:00
} ,
2020-10-07 21:34:15 +13:00
#[ structopt(name = " empty-folders " , about = " Finds empty folders " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka empty-folders -d /home/rafal/rr /home/gateway -f results.txt " ) ]
2020-10-05 10:36:49 +13:00
EmptyFolders {
#[ structopt(flatten) ]
directories : Directories ,
2020-11-01 07:19:33 +13:00
#[ structopt(flatten) ]
excluded_directories : ExcludedDirectories ,
#[ structopt(flatten) ]
excluded_items : ExcludedItems ,
2020-10-05 10:36:49 +13:00
#[ structopt(short = " D " , long, help = " Delete found folders " ) ]
delete_folders : bool ,
#[ structopt(flatten) ]
file_to_save : FileToSave ,
} ,
#[ structopt(name = " big " , about = " Finds big files " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka big -d /home/rafal/ /home/piszczal -e /home/rafal/Roman -n 25 -x VIDEO -f results.txt " ) ]
BiggestFiles {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_directories : ExcludedDirectories ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_items : ExcludedItems ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
allowed_extensions : AllowedExtensions ,
#[ structopt(short, long, default_value = " 50 " , help = " Number of files to be shown " ) ]
number_of_files : usize ,
2020-11-01 07:19:33 +13:00
#[ structopt(short = " D " , long, help = " Delete found files " ) ]
delete_files : bool ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
} ,
2021-04-09 04:28:49 +12:00
#[ structopt(name = " empty-files " , about = " Finds empty files " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka empty-files -d /home/rafal /home/szczekacz -e /home/rafal/Pulpit -R -f results.txt " ) ]
2020-10-05 10:36:49 +13:00
EmptyFiles {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_directories : ExcludedDirectories ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_items : ExcludedItems ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
allowed_extensions : AllowedExtensions ,
#[ structopt(short = " D " , long, help = " Delete found files " ) ]
delete_files : bool ,
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
} ,
#[ structopt(name = " temp " , about = " Finds temporary files " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka temp -d /home/rafal/ -E */.git */tmp* *Pulpit -f results.txt -D " ) ]
Temporary {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_directories : ExcludedDirectories ,
2020-10-05 10:36:49 +13:00
#[ structopt(flatten) ]
2020-10-07 21:34:15 +13:00
excluded_items : ExcludedItems ,
2020-10-05 10:36:49 +13:00
#[ structopt(short = " D " , long, help = " Delete found files " ) ]
delete_files : bool ,
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
} ,
2020-10-25 07:44:21 +13:00
#[ structopt(name = " image " , about = " Finds similar images " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka image -d /home/rafal/ -E */.git */tmp* *Pulpit -f results.txt " ) ]
2020-10-15 08:10:27 +13:00
SimilarImages {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
excluded_directories : ExcludedDirectories ,
#[ structopt(short, long, parse(try_from_str = parse_minimal_file_size), default_value = " 16384 " , help = " Minimum size in bytes " , long_help = " Minimum size of checked files in bytes, assigning bigger value may speed up searching " ) ]
minimal_file_size : u64 ,
2021-08-07 09:23:11 +12:00
#[ structopt(short = " i " , long, parse(try_from_str = parse_maximal_file_size), default_value = " 18446744073709551615 " , help = " Maximum size in bytes " , long_help = " Maximum size of checked files in bytes, assigning lower value may speed up searching " ) ]
maximal_file_size : u64 ,
2021-06-26 01:59:36 +12:00
#[ structopt(short, long, default_value = " High " , parse(try_from_str = parse_similar_images_similarity), help = " Similairty level (Minimal, VerySmall, Small, Medium, High, VeryHigh) " , long_help = " Methods to choose similarity level of images which will be considered as duplicated. " ) ]
2021-11-18 23:23:17 +13:00
similarity_preset : SimilarityPreset ,
2020-10-15 08:10:27 +13:00
#[ structopt(flatten) ]
excluded_items : ExcludedItems ,
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
2021-11-28 08:57:10 +13:00
#[ structopt(short = " g " , long, default_value = " Gradient " , parse(try_from_str = parse_similar_hash_algorithm), help = " Hash algorithm (allowed: Mean, Gradient, Blockhash, VertGradient, DoubleGradient) " ) ]
2021-11-18 23:23:17 +13:00
hash_alg : HashAlg ,
2021-11-28 08:57:10 +13:00
#[ structopt(short = " z " , long, default_value = " Lanczos3 " , parse(try_from_str = parse_similar_image_filter), help = " Hash algorithm (allowed: Lanczos3, Nearest, Triangle, Faussian, Catmullrom) " ) ]
2021-11-18 23:23:17 +13:00
image_filter : FilterType ,
2021-11-28 08:57:10 +13:00
#[ structopt(short = " c " , long, default_value = " 8 " , parse(try_from_str = parse_image_hash_size), help = " Hash size (allowed: 4, 8, 16) " ) ]
2021-11-18 23:23:17 +13:00
hash_size : u8 ,
2020-10-15 08:10:27 +13:00
} ,
2020-11-03 09:56:07 +13:00
#[ structopt(name = " music " , about = " Finds same music by tags " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka music -d /home/rafal -f results.txt " ) ]
SameMusic {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
excluded_directories : ExcludedDirectories ,
#[ structopt(flatten) ]
excluded_items : ExcludedItems ,
// #[structopt(short = "D", long, help = "Delete found files")]
// delete_files: bool, TODO
#[ structopt(short = " z " , long, default_value = " artist,title " , parse(try_from_str = parse_music_duplicate_type), help = " Search method (title, artist, album_title, album_artist, year) " , long_help = " Sets which rows must be equal to set this files as duplicates(may be mixed, but must be divided by commas). " ) ]
music_similarity : MusicSimilarity ,
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
2021-08-07 09:23:11 +12:00
#[ structopt(short, long, parse(try_from_str = parse_minimal_file_size), default_value = " 8192 " , help = " Minimum size in bytes " , long_help = " Minimum size of checked files in bytes, assigning bigger value may speed up searching " ) ]
2020-11-03 09:56:07 +13:00
minimal_file_size : u64 ,
2021-08-07 09:23:11 +12:00
#[ structopt(short = " i " , long, parse(try_from_str = parse_maximal_file_size), default_value = " 18446744073709551615 " , help = " Maximum size in bytes " , long_help = " Maximum size of checked files in bytes, assigning lower value may speed up searching " ) ]
maximal_file_size : u64 ,
2020-11-03 09:56:07 +13:00
} ,
2020-12-22 04:09:39 +13:00
#[ structopt(name = " symlinks " , about = " Finds invalid symlinks " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka symlinks -d /home/kicikici/ /home/szczek -e /home/kicikici/jestempsem -x jpg -f results.txt " ) ]
InvalidSymlinks {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
excluded_directories : ExcludedDirectories ,
#[ structopt(flatten) ]
excluded_items : ExcludedItems ,
#[ structopt(flatten) ]
allowed_extensions : AllowedExtensions ,
#[ structopt(short = " D " , long, help = " Delete found files " ) ]
delete_files : bool ,
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
} ,
2021-01-13 08:06:12 +13:00
#[ structopt(name = " broken " , about = " Finds broken files " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka broken -d /home/kicikici/ /home/szczek -e /home/kicikici/jestempsem -x jpg -f results.txt " ) ]
BrokenFiles {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
excluded_directories : ExcludedDirectories ,
#[ structopt(flatten) ]
excluded_items : ExcludedItems ,
#[ structopt(flatten) ]
allowed_extensions : AllowedExtensions ,
#[ structopt(short = " D " , long, help = " Delete found files " ) ]
delete_files : bool ,
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
} ,
2021-11-23 23:10:24 +13:00
#[ structopt(name = " video " , about = " Finds similar video files " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka videos -d /home/rafal -f results.txt " ) ]
SimilarVideos {
#[ structopt(flatten) ]
directories : Directories ,
#[ structopt(flatten) ]
excluded_directories : ExcludedDirectories ,
#[ structopt(flatten) ]
excluded_items : ExcludedItems ,
// #[structopt(short = "D", long, help = "Delete found files")]
// delete_files: bool, TODO
#[ structopt(flatten) ]
file_to_save : FileToSave ,
#[ structopt(flatten) ]
allowed_extensions : AllowedExtensions ,
#[ structopt(flatten) ]
not_recursive : NotRecursive ,
#[ structopt(short, long, parse(try_from_str = parse_minimal_file_size), default_value = " 8192 " , help = " Minimum size in bytes " , long_help = " Minimum size of checked files in bytes, assigning bigger value may speed up searching " ) ]
minimal_file_size : u64 ,
#[ structopt(short = " i " , long, parse(try_from_str = parse_maximal_file_size), default_value = " 18446744073709551615 " , help = " Maximum size in bytes " , long_help = " Maximum size of checked files in bytes, assigning lower value may speed up searching " ) ]
maximal_file_size : u64 ,
#[ structopt(short = " t " , long, parse(try_from_str = parse_tolerance), default_value = " 10 " , help = " Video maximium difference (allowed values <0,20>) " , long_help = " Maximum difference between video frames, bigger value means that videos can looks more and more different (allowed values <0,20>) " ) ]
tolerance : i32 ,
} ,
2021-11-18 23:23:17 +13:00
#[ structopt(name = " tester " , about = " Contains various test " , help_message = HELP_MESSAGE, after_help = " EXAMPLE: \n czkawka tests -i " ) ]
Tester {
#[ structopt(short = " i " , long = " test_image " , help = " Test speed of hashing provided test.jpg image with different filters and methods. " ) ]
test_image : bool ,
} ,
2020-10-05 10:36:49 +13:00
}
#[ derive(Debug, StructOpt) ]
pub struct Directories {
2021-12-22 06:44:20 +13:00
#[ structopt(
short ,
long ,
parse ( from_os_str ) ,
required = true ,
help = " Directorie(s) to search " ,
long_help = " List of directorie(s) which will be searched(absolute path) "
) ]
2020-10-05 10:36:49 +13:00
pub directories : Vec < PathBuf > ,
}
#[ derive(Debug, StructOpt) ]
2020-10-07 21:34:15 +13:00
pub struct ExcludedDirectories {
2021-12-22 06:44:20 +13:00
#[ structopt(
short ,
long ,
parse ( from_os_str ) ,
help = " Excluded directorie(s) " ,
long_help = " List of directorie(s) which will be excluded from search(absolute path) "
) ]
2020-10-05 10:36:49 +13:00
pub excluded_directories : Vec < PathBuf > ,
}
#[ derive(Debug, StructOpt) ]
2020-10-07 21:34:15 +13:00
pub struct ExcludedItems {
2021-12-22 06:44:20 +13:00
#[ structopt(
short = " E " ,
long ,
help = " Excluded item(s) " ,
long_help = " List of excluded item(s) which contains * wildcard(may be slow, so use -e where possible) "
) ]
2021-01-11 08:44:10 +13:00
pub excluded_items : Vec < String > ,
2020-10-05 10:36:49 +13:00
}
#[ derive(Debug, StructOpt) ]
pub struct AllowedExtensions {
#[ structopt(
short = " x " ,
long ,
help = " Allowed file extension(s) " ,
2021-01-14 04:03:05 +13:00
long_help = " List of checked files with provided extension(s). There are also helpful macros which allow to easy use a typical extensions like: \n IMAGE( \" jpg,kra,gif,png,bmp,tiff,hdr,svg \" ), \n TEXT( \" txt,doc,docx,odt,rtf \" ), \n VIDEO( \" mp4,flv,mkv,webm,vob,ogv,gifv,avi,mov,wmv,mpg,m4v,m4p,mpeg,3gp \" ) or \n MUSIC( \" mp3,flac,ogg,tta,wma,webm \" ) \n "
2020-10-05 10:36:49 +13:00
) ]
pub allowed_extensions : Vec < String > ,
}
#[ derive(Debug, StructOpt) ]
pub struct NotRecursive {
#[ structopt(short = " R " , long, help = " Prevents from recursive check of folders " ) ]
pub not_recursive : bool ,
}
#[ derive(Debug, StructOpt) ]
pub struct FileToSave {
#[ structopt(short, long, value_name = " file-name " , help = " Saves the results into the file " ) ]
pub file_to_save : Option < PathBuf > ,
}
2021-02-23 08:14:33 +13:00
#[ derive(Debug, StructOpt) ]
pub struct AllowHardLinks {
#[ structopt(short = " L " , long, help = " Do not ignore hard links " ) ]
pub allow_hard_links : bool ,
}
2021-03-02 00:23:43 +13:00
#[ derive(Debug, StructOpt) ]
pub struct DryRun {
#[ structopt(long, help = " Do nothing and print the operation that would happen. " ) ]
pub dryrun : bool ,
}
2020-10-05 10:36:49 +13:00
impl FileToSave {
pub fn file_name ( & self ) -> Option < & str > {
if let Some ( file_name ) = & self . file_to_save {
return file_name . to_str ( ) ;
}
None
}
}
2021-02-21 17:59:07 +13:00
fn parse_hash_type ( src : & str ) -> Result < HashType , & 'static str > {
match src . to_ascii_lowercase ( ) . as_str ( ) {
" blake3 " = > Ok ( HashType ::Blake3 ) ,
2021-03-28 01:14:02 +13:00
" crc32 " = > Ok ( HashType ::Crc32 ) ,
" xxh3 " = > Ok ( HashType ::Xxh3 ) ,
2021-02-21 17:59:07 +13:00
_ = > Err ( " Couldn't parse the hash type (allowed: BLAKE3, CRC32, XXH3) " ) ,
}
}
2021-11-23 23:10:24 +13:00
fn parse_tolerance ( src : & str ) -> Result < i32 , & 'static str > {
match src . parse ::< i32 > ( ) {
Ok ( t ) = > {
if ( 0 ..= 20 ) . contains ( & t ) {
Ok ( t )
} else {
Err ( " Tolerance should be in range <0,20>(Higher and lower similarity ) " )
}
}
_ = > Err ( " Failed to parse tolerance as i32 value. " ) ,
}
}
2020-10-05 10:36:49 +13:00
fn parse_checking_method ( src : & str ) -> Result < CheckingMethod , & 'static str > {
match src . to_ascii_lowercase ( ) . as_str ( ) {
2020-10-25 07:44:21 +13:00
" name " = > Ok ( CheckingMethod ::Name ) ,
2020-10-05 10:36:49 +13:00
" size " = > Ok ( CheckingMethod ::Size ) ,
" hash " = > Ok ( CheckingMethod ::Hash ) ,
2021-12-02 10:34:49 +13:00
_ = > Err ( " Couldn't parse the search method (allowed: NAME, SIZE, HASH) " ) ,
2020-10-05 10:36:49 +13:00
}
}
fn parse_delete_method ( src : & str ) -> Result < DeleteMethod , & 'static str > {
match src . to_ascii_lowercase ( ) . as_str ( ) {
2020-10-13 02:25:32 +13:00
" none " = > Ok ( DeleteMethod ::None ) ,
2020-10-05 10:36:49 +13:00
" aen " = > Ok ( DeleteMethod ::AllExceptNewest ) ,
" aeo " = > Ok ( DeleteMethod ::AllExceptOldest ) ,
2021-02-06 05:59:34 +13:00
" hard " = > Ok ( DeleteMethod ::HardLink ) ,
2020-10-05 10:36:49 +13:00
" on " = > Ok ( DeleteMethod ::OneNewest ) ,
" oo " = > Ok ( DeleteMethod ::OneOldest ) ,
2021-02-06 05:59:34 +13:00
_ = > Err ( " Couldn't parse the delete method (allowed: AEN, AEO, ON, OO, HARD) " ) ,
2020-10-05 10:36:49 +13:00
}
}
2021-11-18 23:23:17 +13:00
fn parse_similar_images_similarity ( src : & str ) -> Result < SimilarityPreset , & 'static str > {
match src . to_lowercase ( ) . replace ( '_' , " " ) . as_str ( ) {
" minimal " = > Ok ( SimilarityPreset ::Minimal ) ,
" verysmall " = > Ok ( SimilarityPreset ::VerySmall ) ,
" small " = > Ok ( SimilarityPreset ::Small ) ,
" medium " = > Ok ( SimilarityPreset ::Medium ) ,
" high " = > Ok ( SimilarityPreset ::High ) ,
" veryhigh " = > Ok ( SimilarityPreset ::VeryHigh ) ,
_ = > Err ( " Couldn't parse the image similarity preset (allowed: Minimal, VerySmall, Small, Medium, High, VeryHigh) " ) ,
2020-11-10 00:55:27 +13:00
}
}
2020-10-07 21:34:15 +13:00
fn parse_minimal_file_size ( src : & str ) -> Result < u64 , String > {
2020-10-05 10:36:49 +13:00
match src . parse ::< u64 > ( ) {
2020-10-15 08:10:27 +13:00
Ok ( minimal_file_size ) = > {
if minimal_file_size > 0 {
Ok ( minimal_file_size )
2020-10-05 10:36:49 +13:00
} else {
Err ( " Minimum file size must be at least 1 byte " . to_string ( ) )
}
}
Err ( e ) = > Err ( e . to_string ( ) ) ,
}
}
2021-08-07 09:23:11 +12:00
fn parse_maximal_file_size ( src : & str ) -> Result < u64 , String > {
match src . parse ::< u64 > ( ) {
Ok ( maximal_file_size ) = > Ok ( maximal_file_size ) ,
Err ( e ) = > Err ( e . to_string ( ) ) ,
}
}
2021-11-18 23:23:17 +13:00
fn parse_similar_image_filter ( src : & str ) -> Result < FilterType , String > {
2021-12-19 11:45:37 +13:00
let filter_type = match src . to_lowercase ( ) . as_str ( ) {
2021-11-18 23:23:17 +13:00
" lanczos3 " = > FilterType ::Lanczos3 ,
" nearest " = > FilterType ::Nearest ,
" triangle " = > FilterType ::Triangle ,
" faussian " = > FilterType ::Gaussian ,
" catmullrom " = > FilterType ::CatmullRom ,
_ = > return Err ( " Couldn't parse the image resize filter (allowed: Lanczos3, Nearest, Triangle, Faussian, Catmullrom) " . to_string ( ) ) ,
} ;
Ok ( filter_type )
}
2021-11-28 08:57:10 +13:00
2021-11-18 23:23:17 +13:00
fn parse_similar_hash_algorithm ( src : & str ) -> Result < HashAlg , String > {
2021-12-19 11:45:37 +13:00
let algorithm = match src . to_lowercase ( ) . as_str ( ) {
2021-11-18 23:23:17 +13:00
" mean " = > HashAlg ::Mean ,
" gradient " = > HashAlg ::Gradient ,
" blockhash " = > HashAlg ::Blockhash ,
" vertgradient " = > HashAlg ::VertGradient ,
" doublegradient " = > HashAlg ::DoubleGradient ,
_ = > return Err ( " Couldn't parse the hash algorithm (allowed: Mean, Gradient, Blockhash, VertGradient, DoubleGradient) " . to_string ( ) ) ,
} ;
Ok ( algorithm )
}
fn parse_image_hash_size ( src : & str ) -> Result < u8 , String > {
2021-12-19 11:45:37 +13:00
let hash_size = match src . to_lowercase ( ) . as_str ( ) {
2021-11-18 23:23:17 +13:00
" 8 " = > 8 ,
" 16 " = > 16 ,
2021-12-03 03:33:06 +13:00
" 32 " = > 32 ,
" 64 " = > 64 ,
_ = > return Err ( " Couldn't parse the image hash size (allowed: 8, 16, 32, 64) " . to_string ( ) ) ,
2021-11-18 23:23:17 +13:00
} ;
Ok ( hash_size )
}
2020-11-03 09:56:07 +13:00
fn parse_music_duplicate_type ( src : & str ) -> Result < MusicSimilarity , String > {
if src . is_empty ( ) {
return Ok ( MusicSimilarity ::NONE ) ;
}
let mut similarity : MusicSimilarity = MusicSimilarity ::NONE ;
let parts : Vec < & str > = src . split ( ',' ) . collect ( ) ;
if parts . iter ( ) . any ( | e | e . to_lowercase ( ) . contains ( " title " ) & & ! e . to_lowercase ( ) . contains ( " album " ) ) {
similarity | = MusicSimilarity ::TITLE ;
}
if parts . iter ( ) . any ( | e | e . to_lowercase ( ) . contains ( " artist " ) & & ! e . to_lowercase ( ) . contains ( " album " ) ) {
similarity | = MusicSimilarity ::ARTIST ;
}
if parts . iter ( ) . any ( | e | e . to_lowercase ( ) . contains ( " title " ) & & e . to_lowercase ( ) . contains ( " album " ) ) {
similarity | = MusicSimilarity ::ALBUM_TITLE ;
}
if parts . iter ( ) . any ( | e | e . to_lowercase ( ) . contains ( " artist " ) & & e . to_lowercase ( ) . contains ( " album " ) ) {
similarity | = MusicSimilarity ::ALBUM_ARTIST ;
}
if parts . iter ( ) . any ( | e | e . to_lowercase ( ) . contains ( " year " ) ) {
similarity | = MusicSimilarity ::YEAR ;
}
if similarity = = MusicSimilarity ::NONE {
return Err ( " Couldn't parse the music search method (allowed: title,artist,album_title,album_artist,year) " . to_string ( ) ) ;
}
Ok ( similarity )
}
2020-10-05 10:36:49 +13:00
static HELP_MESSAGE : & str = " Prints help information (--help will give more information) " ;
const HELP_TEMPLATE : & str = r #"
{ bin } { version }
USAGE :
{ usage } [ SCFLAGS ] [ SCOPTIONS ]
FLAGS :
{ flags }
SUBCOMMANDS :
{ subcommands }
try " {usage} -h " to get more info about a specific tool
EXAMPLES :
2021-12-02 00:37:17 +13:00
{ bin } dup - d / home / rafal - e / home / rafal / Obrazy - m 25 - x 7 z rar IMAGE - s hash - f results . txt - D aeo
2020-10-05 10:36:49 +13:00
{ bin } empty - folders - d / home / rafal / rr / home / gateway - f results . txt
{ bin } big - d / home / rafal / / home / piszczal - e / home / rafal / Roman - n 25 - x VIDEO - f results . txt
{ bin } empty - files - d / home / rafal / home / szczekacz - e / home / rafal / Pulpit - R - f results . txt
2020-10-25 07:44:21 +13:00
{ bin } temp - d / home / rafal / - E * / . git * / tmp * * Pulpit - f results . txt - D
2020-10-31 22:29:11 +13:00
{ bin } image - d / home / rafal - e / home / rafal / Pulpit - f results . txt
2020-12-22 04:09:39 +13:00
{ bin } music - d / home / rafal - e / home / rafal / Pulpit - z " artist,year, ARTISTALBUM, ALBUM___tiTlE " - f results . txt
2021-01-13 08:06:12 +13:00
{ bin } symlinks - d / home / kicikici / / home / szczek - e / home / kicikici / jestempsem - x jpg - f results . txt
{ bin } broken - d / home / mikrut / - e / home / mikrut / trakt - f results . txt " #;