-sod--open-604- ----- 500 Sex 2006-05-04.avi Link

# Remove codes, dashes, and potentially unwanted words (like "SEX") clean_name = re.sub(r'[-_]+', ' ', name) clean_name = re.sub(r'\bSEX\b', '', clean_name, flags=re.IGNORECASE) clean_name = re.sub(r'\s+', ' ', clean_name).strip()

new_filename = f"{date_str}_{clean_name}{ext}" new_path = os.path.join(dirname, new_filename) -SOD--OPEN-604- ----- 500 SEX 2006-05-04.avi

# Look for date pattern like 2006-05-04 or 20060504 date_match = re.search(r'(\d{4})-?(\d{2})-?(\d{2})', name) if not date_match: # Try to get date from file's mtime or metadata via ffprobe if available try: cmd = ['ffprobe', '-v', 'error', '-show_entries', 'format=creation_time', '-of', 'default=noprint_wrappers=1:nokey=1', filepath] creation = subprocess.check_output(cmd, text=True).strip() if creation: date_obj = datetime.fromisoformat(creation.split('T')[0]) date_str = date_obj.strftime('%Y-%m-%d') else: date_str = datetime.fromtimestamp(os.path.getmtime(filepath)).strftime('%Y-%m-%d') except: date_str = "unknown_date" else: y, m, d = date_match.groups() date_str = f"{y}-{m}-{d}" # Remove codes, dashes, and potentially unwanted words

# If clean_name is too short or empty, use a generic descriptor if len(clean_name) < 3: clean_name = "video" # Remove codes

if not dry_run: os.rename(filepath, new_path) print(f"Renamed: {filename} -> {new_filename}") else: print(f"[DRY RUN] Would rename: {filename} -> {new_filename}")