Last active
November 10, 2019 02:32
-
-
Save caseyanderson/ab55317e7f90b2993919eb63689df0a7 to your computer and use it in GitHub Desktop.
cleanup filenames of .wav files for subsonic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
subsonic_cleanup | |
example input: "the body - No One Deserves Happiness - 01 Wanderings.wav" | |
example output: "01 Wanderings.wav" | |
usage: python3 subsonic_cleanup.py --path "the body - No One Deserves Happiness/" --ext "wav" | |
TODO: | |
* check to see if album or artist has digit, need alternate procedure for such a case | |
* remove artist name from directory | |
""" | |
import argparse | |
from pathlib import Path, PurePath | |
import re | |
# parse command line arguments | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--path", type=str, help="the path") | |
parser.add_argument("--ext", type=str, default="wav", help="file extension") | |
args = parser.parse_args() | |
ext = "".join([".", args.ext]) | |
entries = Path(args.path) | |
for entry in entries.iterdir(): | |
if entry.suffix == ext: | |
new_name = re.sub(r'^[^\d]+', '', entry.name) | |
entries = PurePath(entries) | |
full_path = entries / new_name | |
entry.rename(full_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment