Skip to content

Commit 0227e4c

Browse files
committed
Add options to dump file hashes
1 parent 8232831 commit 0227e4c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

ia-verify.py

+30
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ def xml_parse(metafile_path):
104104
return files_metadata
105105

106106

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+
107127
def main():
108128
parser = ArgumentParser(
109129
description='A tool to verify internet archive downloads offline using the xml or sqlite metadata files.')
@@ -121,6 +141,12 @@ def main():
121141
help="Don't print corrupted files.")
122142
parser.add_argument('-q', '--no-file-messages', action='store_true',
123143
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)')
124150
args = parser.parse_args()
125151

126152
if args.no_file_messages:
@@ -160,6 +186,10 @@ def main():
160186
if not (files_metadata := sqlite_parse(metafile_path)):
161187
continue
162188

189+
if args.dump_md5 or args.dump_crc32 or args.dump_sha1:
190+
dump_hashes(args, files_metadata)
191+
continue
192+
163193
files_count = len(files_metadata)
164194
files_width = len(str(files_count))
165195
clear_progress = '\r' + (' ' * len(PROGRESS_LINE_FMT.format(f_pct=0, f_num=0, t_wid=files_width,

0 commit comments

Comments
 (0)