@@ -104,6 +104,26 @@ def xml_parse(metafile_path):
104
104
return files_metadata
105
105
106
106
107
+ def dump_hashes (args , files_metadata ):
108
+ metafile_type = files_metadata [0 ]['type' ]
109
+
110
+ hash_types = []
111
+ for hash , do_dump in zip (('md5' , 'crc32' , 'sha1' ), (args .dump_md5 , args .dump_crc32 , args .dump_sha1 )):
112
+ if do_dump :
113
+ hash_types .append (hash )
114
+
115
+ for idx , hash in enumerate (hash_types , start = 1 ):
116
+ if metafile_type == 'sqlite' and hash != 'md5' :
117
+ eprint (f'Cannot dump { hash .upper ()} hashes, sqlite format contains only MD5.' )
118
+ continue
119
+ if len (hash_types ) > 1 :
120
+ print (f'{ hash .upper ()} :' )
121
+ for file in files_metadata :
122
+ print (f'{ file [hash ]} { file ["path" ]} ' )
123
+ if idx != len (hash_types ):
124
+ print ()
125
+
126
+
107
127
def main ():
108
128
parser = ArgumentParser (
109
129
description = 'A tool to verify internet archive downloads offline using the xml or sqlite metadata files.' )
@@ -121,6 +141,12 @@ def main():
121
141
help = "Don't print corrupted files." )
122
142
parser .add_argument ('-q' , '--no-file-messages' , action = 'store_true' ,
123
143
help = "Don't print any file messages. Same as setting all --no options" )
144
+ parser .add_argument ('--dump-md5' , action = 'store_true' ,
145
+ help = 'Dump MD5 hashes from metadata file instead of processing.' )
146
+ parser .add_argument ('--dump-crc32' , action = 'store_true' ,
147
+ help = 'Dump CRC32 hashes from metadata file instead of processing (XML metadata file only)' )
148
+ parser .add_argument ('--dump-sha1' , action = 'store_true' ,
149
+ help = 'Dump SHA1 hashes from metadata file instead of processing (XML metadata file only)' )
124
150
args = parser .parse_args ()
125
151
126
152
if args .no_file_messages :
@@ -160,6 +186,10 @@ def main():
160
186
if not (files_metadata := sqlite_parse (metafile_path )):
161
187
continue
162
188
189
+ if args .dump_md5 or args .dump_crc32 or args .dump_sha1 :
190
+ dump_hashes (args , files_metadata )
191
+ continue
192
+
163
193
files_count = len (files_metadata )
164
194
files_width = len (str (files_count ))
165
195
clear_progress = '\r ' + (' ' * len (PROGRESS_LINE_FMT .format (f_pct = 0 , f_num = 0 , t_wid = files_width ,
0 commit comments