Rename Pinchflat files
unknown
python
2 months ago
1.5 kB
4
Indexable
import os import re from pathlib import Path # Base directory containing the files BASE_DIR = "/mnt/usb/media03/youtube/pinchflat/shows" def rename_files(base_dir): for root, _, files in os.walk(base_dir): # Extract date from the directory path match = re.search(r'(\d{4})-(\d{2})-(\d{2})', root) if not match: continue year, month, day = match.groups() season_dir = f"Season {year}" episode_number = f"s{year}e{month}{day}00" parent_dir = Path(root).parent # Parent directory before the date folder new_dir = parent_dir / season_dir # Ensure the season directory exists new_dir.mkdir(parents=True, exist_ok=True) for file in files: if file.endswith(".mp4"): # Extract video identifier from the filename video_id_match = re.search(r'\[([A-Za-z0-9_-]+)\]\.mp4$', file) if not video_id_match: continue video_id = video_id_match.group(1) # Construct new filename new_filename = f"{episode_number} - [{video_id}].mp4" # Rename and move file old_path = Path(root) / file new_path = new_dir / new_filename print(f"Renaming: {old_path} -> {new_path}") os.rename(old_path, new_path) if __name__ == "__main__": rename_files(BASE_DIR)
Editor is loading...
Leave a Comment