diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-04-14 21:35:10 +0200 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-04-14 21:35:10 +0200 |
| commit | 38cd71544686e861d2218592082a48ccfdd19985 (patch) | |
| tree | be0294b379a2983c2a86d90a6c5a082f584d71a5 | |
| parent | a8cb9a7992e3358f91af883dcde369496108449e (diff) | |
| download | dotfiles-38cd71544686e861d2218592082a48ccfdd19985.tar.gz dotfiles-38cd71544686e861d2218592082a48ccfdd19985.zip | |
add script, that organizes music and sends it to server
| -rwxr-xr-x | bin/organize_music | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/organize_music b/bin/organize_music new file mode 100755 index 0000000..de21327 --- /dev/null +++ b/bin/organize_music @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import os +import sys +import eyed3 +import shutil + +def sanitize_filename(name): + return "".join(c for c in name if c.isalnum() or c in (' ', '-', '_')).rstrip() + +def organize_mp3s(directory): + if not os.path.isdir(directory): + print(f"Directory '{directory}' does not exist.") + return + + for filename in os.listdir(directory): + if not filename.lower().endswith(".mp3"): + continue + + filepath = os.path.join(directory, filename) + audiofile = eyed3.load(filepath) + + title = sanitize_filename(audiofile.tag.title) + artist = sanitize_filename(audiofile.tag.album_artist) + album = sanitize_filename(audiofile.tag.album) + + new_filename = f"{title} - {artist}.mp3" + target_dir = os.path.join(directory, artist, album) + + os.makedirs(target_dir, exist_ok=True) + + new_path = os.path.join(target_dir, new_filename) + + shutil.move(filepath, new_path) + +if len(sys.argv) < 2: + print("Usage: python organize_mp3s.py <directory_path>") +else: + organize_mp3s(sys.argv[1]) + os.system(f"rsync -avz {sys.argv[1]}/* admin@krinitsin.com:/var/music/") |