#!/usr/bin/env python3 import concurrent.futures import subprocess import glob import os import multiprocessing import re import nltk from nltk.corpus import words from nltk.corpus import wordnet # Different ways to get CPU count logical_cores = os.cpu_count() # All cores including hyperthreading physical_cores = multiprocessing.cpu_count() # Same as above # For more detailed info on Apple Silicon: try: # This works on macOS to get performance core count p_cores = len([x for x in os.sched_getaffinity(0) if x < os.cpu_count()//2]) except AttributeError: p_cores = physical_cores print(f"System has {logical_cores} logical cores") max_workers = max(1, logical_cores - 2) # Leave 2 cores free for system def convert_file(aax_file): mp3_file = aax_file.replace('.aax', '.mp3') print(f"Converting {aax_file} to {mp3_file}") subprocess.run(['ffmpeg', '-activation_bytes', os.getenv('AUDIBLE_ACTIVATION_BYTES'), '-i', aax_file, mp3_file], check=True) return mp3_file def rename_file(mp3_file): print(f"\n{'='*50}") print(f"Original: {mp3_file}") base, ext = os.path.splitext(mp3_file) new_base = rename_base(base) new_name = new_base + ext print(f"New name: {new_name}") if new_name != mp3_file: try: os.rename(mp3_file, new_name) print(f"Renamed: {mp3_file} -> {new_name}") except OSError as e: print(f"Error renaming {mp3_file}: {e}") def rename_base(base): words = re.split('(?