Skip to content

Instantly share code, notes, and snippets.

@caseyanderson
Last active November 10, 2019 02:32
Show Gist options
  • Save caseyanderson/ab55317e7f90b2993919eb63689df0a7 to your computer and use it in GitHub Desktop.
Save caseyanderson/ab55317e7f90b2993919eb63689df0a7 to your computer and use it in GitHub Desktop.
cleanup filenames of .wav files for subsonic
"""
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