dotfiles/hm/scripts/music_remove_dashes

35 lines
805 B
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env nix-shell
#! nix-shell -i python3 --pure
#! nix-shell -p python3
2019-11-01 18:34:45 +01:00
"""
Small script to convert music files in the form:
$(tracknumber) - $(title).$(ext)
to the form
$(tracknumber) $(title).$(ext)
(note the absence of dash)
"""
import os
import re
def main() -> None:
"""
Function that executes the script.
"""
2021-06-13 11:49:21 +02:00
for root, _, files in os.walk("."):
2019-11-01 18:34:45 +01:00
for filename in files:
2021-06-13 11:49:21 +02:00
match = re.match(r"^(\d+) - (.+)$", filename)
2019-11-01 18:34:45 +01:00
if not match:
continue
new_filename = f"{match[1]} {match[2]}"
old_path = os.path.join(root, filename)
new_path = os.path.join(root, new_filename)
2021-06-13 11:49:21 +02:00
print(old_path, "->", new_path)
2019-11-01 18:34:45 +01:00
os.rename(old_path, new_path)
2021-06-13 11:49:21 +02:00
if __name__ == "__main__":
2019-11-01 18:34:45 +01:00
main()