From 60575c798920729bc4c2a1afb4488b9b3205207c Mon Sep 17 00:00:00 2001 From: KnugiHK <24708955+KnugiHK@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:34:34 +0800 Subject: [PATCH] Implement #25 Copying media folder to the output directory will be the default starting from this commit. --- Whatsapp_Chat_Exporter/__main__.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Whatsapp_Chat_Exporter/__main__.py b/Whatsapp_Chat_Exporter/__main__.py index b35d79a..7ae3c01 100644 --- a/Whatsapp_Chat_Exporter/__main__.py +++ b/Whatsapp_Chat_Exporter/__main__.py @@ -93,6 +93,13 @@ def main(): default=False, action='store_true', help="Show the HEX key used to decrypt the database") + parser.add_option( + "-c", + "--copy-media", + dest="copy_media", + default=True, + action='store_true', + help="Copy media directory to output directory, otherwise move the media directory to output directory") (options, args) = parser.parse_args() if options.android and options.iphone: @@ -193,13 +200,18 @@ def main(): ) exit(2) - if os.path.isdir(options.media) and \ - not os.path.isdir(f"{options.output}/{options.media}"): - try: - shutil.move(options.media, f"{options.output}/") - except PermissionError: - print("Cannot remove original WhatsApp directory. " - "Perhaps the directory is opened?") + if os.path.isdir(options.media): + if os.path.isdir(f"{options.output}/{options.media}"): + print("Media directory already exists in output directory. Skipping...") + else: + if options.copy_media: + shutil.copytree(options.media, f"{options.output}/WhatsApp") + else: + try: + shutil.move(options.media, f"{options.output}/") + except PermissionError: + print("Cannot remove original WhatsApp directory. " + "Perhaps the directory is opened?") if options.json: with open("result.json", "w") as f: