Fbrowser/python-src/extraction.py
stan44 565be4e1e7 Migrate Fbrowser to Rust and Tauri desktop app
- Replace the Python/Docker setup with a Rust workspace and Tauri frontend
- Add core crates for archive, audio, MIDI, plugin, and desktop UI layers
- Refresh the app scaffolding, build config, and documentation
2026-03-30 16:18:26 -05:00

75 lines
2.8 KiB
Python

# extractor.py
import os
import zipfile
import rarfile
import py7zr
import argparse
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor
class Extractor:
def zipviewer(self, source, destination):
print(f"checking if {source} exists")
if not os.path.exists(source):
print(f"Error: Archive file not found: {source}")
return
try:
print(f"checking if {destination} exists")
if not os.path.exists(destination):
print(f"{destination} does not exist, creating {destination}")
os.makedirs(destination)
print(f"{destination} created")
else:
print(f"{destination} exists")
print(f"checking if {source} is a valid archive file")
if source.endswith(".zip"):
print(f"Extracting all files from {source} to {destination}")
with zipfile.ZipFile(source, 'r') as zip_ref:
zip_ref.extractall(destination)
print(f"Extracted all files from {source} to {destination}")
elif source.endswith(".rar, .tar.gz, .tar.bz2, .tar.xz, .tar.zst"):
with rarfile.RarFile(source, 'r') as rar_ref:
rar_ref.extractall(destination)
print(f"Extracted all files from {source} to {destination}")
elif source.endswith(".7z"):
with py7zr.SevenZipFile(source, 'r') as sevenzip_ref:
sevenzip_ref.extractall(destination)
print(f"Extracted all files from {source} to {destination}")
else:
print(f"Unsupported file format: {source}")
except (zipfile.BadZipFile, zipfile.LargeZipFile) as e:
print(f"ZIP Extraction Error: {e}")
except (rarfile.RarFileException, rarfile.NotRARFile) as e:
print(f"RAR Extraction Error: {e}")
except py7zr.exceptions.SevenZipException as e:
print(f"7z Extraction Error: {e}")
except OSError as e:
print(f"Extraction Error: {e}")
def main():
print("Welcome to the Archive Extractor!")
parser = argparse.ArgumentParser(description="Compress or extract files")
subparsers = parser.add_subparsers(title="Command", dest="command")
# Subparser for extraction
extract_parser = subparsers.add_parser("extract")
extract_parser.add_argument("source", help="Path to the archive file")
extract_parser.add_argument("destination", help="Extraction directory")
args = parser.parse_args()
if args.command == "extract":
print(f"Extracting {args.source} to {args.destination}")
extractor = Extractor()
extractor.zipviewer(args.source, args.destination)
if __name__ == "__main__":
main()