mirror of
https://github.com/tdeerenberg/Musort.git
synced 2025-07-17 19:04:18 +00:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
f4e4aa51bc | |||
ee8753d561 | |||
f968b002a5 | |||
e87cc49b28 | |||
3c79631a84 | |||
b13711f3d6 | |||
0aeb8a15ce | |||
239a71bec8 | |||
6388a53867 | |||
dfde71a213 |
@ -1,7 +1,7 @@
|
|||||||
https://user-images.githubusercontent.com/113618658/214463785-49c419e9-c959-4849-91d2-f3407ecaa73d.mp4
|
https://user-images.githubusercontent.com/113618658/214463785-49c419e9-c959-4849-91d2-f3407ecaa73d.mp4
|
||||||
# Musort
|
# Musort
|
||||||
|
|
||||||
A Python3 program that renames all selected music/audio files in a folder with a specified naming convention. Names are generated from the metadata (ID3) from the audio files. Before using this program, use a metadata editor like MusicBrainz Picard, Beets or EasyTAG to add the correct metadata to the audio files.
|
Ogranize your music library. A Python3 program that renames all selected music/audio files in a folder with a specified naming convention. Names are generated from the metadata (ID3) from the audio files. Before using this program, use a metadata editor like MusicBrainz Picard, Beets or EasyTAG to add the correct metadata to the audio files.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ import os
|
|||||||
import sys, getopt
|
import sys, getopt
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
version = "Musort v0.1 (c) tdeerenberg"
|
supported_formats = ["flac", "mp3", "mp2", "mp1", "opus", "ogg", "wma"]
|
||||||
|
|
||||||
|
version = "Musort v0.2 (c) tdeerenberg"
|
||||||
help=\
|
help=\
|
||||||
"""Musort (c) 2023 tdeerenberg (github.com/tdeerenberg)
|
"""Musort (c) 2023 tdeerenberg (github.com/tdeerenberg)
|
||||||
|
|
||||||
@ -80,28 +82,21 @@ class Music:
|
|||||||
def get_compatible(self):
|
def get_compatible(self):
|
||||||
music = []
|
music = []
|
||||||
for file in self.files:
|
for file in self.files:
|
||||||
match file.split("."):
|
file_extension = file.split(".")[-1]
|
||||||
case [*_, "flac"]:
|
|
||||||
music.append(file)
|
if file_extension in supported_formats:
|
||||||
case [*_, "mp3"]:
|
music.append(file)
|
||||||
music.append(file)
|
|
||||||
case [*_, "mp1"]:
|
|
||||||
music.append(file)
|
|
||||||
case [*_, "mp2"]:
|
|
||||||
music.append(file)
|
|
||||||
case [*_, "opus"]:
|
|
||||||
music.append(file)
|
|
||||||
case [*_, "ogg"]:
|
|
||||||
music.append(file)
|
|
||||||
case [*_, "wma"]:
|
|
||||||
music.append(file)
|
|
||||||
self.compatible = music
|
self.compatible = music
|
||||||
|
|
||||||
def set_separator(self, sep):
|
def set_separator(self, sep):
|
||||||
"""Sets the separator for naming the audio files
|
"""Sets the separator for naming the audio files
|
||||||
(ex. 01-songname.mp3 or 01.songname.flac)"""
|
(ex. 01-songname.mp3 or 01.songname.flac)"""
|
||||||
|
if sep in ['\\', '/', '|', '*', '<', '>', '"', '?']:
|
||||||
|
sep = "_"
|
||||||
|
logging.warning("Given separator contains invalid filename symbols, defaulting to .")
|
||||||
self.separator = sep
|
self.separator = sep
|
||||||
self.separator_status = True
|
|
||||||
def set_format(self, val):
|
def set_format(self, val):
|
||||||
"""Sets the naming convention of the audio files
|
"""Sets the naming convention of the audio files
|
||||||
(ex. title-artist or artist-track-title)"""
|
(ex. title-artist or artist-track-title)"""
|
||||||
@ -125,46 +120,21 @@ class Music:
|
|||||||
|
|
||||||
"""Uses the given format to set new filename"""
|
"""Uses the given format to set new filename"""
|
||||||
for f in self.format:
|
for f in self.format:
|
||||||
match f:
|
|
||||||
case "track":
|
if f == "track":
|
||||||
rename.append(f"{int(track.track):02}")
|
rename.append(f"{int(track.track):02}")
|
||||||
case "album":
|
else:
|
||||||
rename.append(track.album)
|
"""getattr gets attribute in track with name f"""
|
||||||
case "albumartist":
|
rename.append(getattr(track, f))
|
||||||
rename.append(track.albumartist)
|
|
||||||
case "artist":
|
|
||||||
rename.append(track.artist)
|
|
||||||
case "audio_offset":
|
|
||||||
rename.append(track.audio_offset)
|
|
||||||
case "bitdepth":
|
|
||||||
rename.append(track.bitdepth)
|
|
||||||
case "bitrate":
|
|
||||||
rename.append(track.bitrate)
|
|
||||||
case "comment":
|
|
||||||
rename.append(track.commment)
|
|
||||||
case "composer":
|
|
||||||
rename.append(track.composer)
|
|
||||||
case "disc":
|
|
||||||
rename.append(track.disc)
|
|
||||||
case "disc_total":
|
|
||||||
rename.append(track.disc_total)
|
|
||||||
case "duration":
|
|
||||||
rename.append(track.duration)
|
|
||||||
case "filesize":
|
|
||||||
rename.append(track.filesize)
|
|
||||||
case "genre":
|
|
||||||
rename.append(track.genre)
|
|
||||||
case "samplerate":
|
|
||||||
rename.append(track.samplerate)
|
|
||||||
case "title":
|
|
||||||
rename.append(track.title)
|
|
||||||
case "track_total":
|
|
||||||
rename.append(track.track_total)
|
|
||||||
case "year":
|
|
||||||
rename.append(track.year)
|
|
||||||
rename.append(self.separator)
|
rename.append(self.separator)
|
||||||
rename.pop()
|
rename.pop()
|
||||||
rename = ''.join(rename)+ext
|
rename = ''.join(rename)+ext
|
||||||
|
"""Replacing forbidden path characters in UNIX and Windows with underscores"""
|
||||||
|
for forbidden_character in ['\\', '/', '|', '*', '<', '>', '"', '?']:
|
||||||
|
if forbidden_character in rename:
|
||||||
|
logging.warning(f"Track contains forbidden path character ({forbidden_character}) in the new file name, replaced symbol with _")
|
||||||
|
rename = rename.replace(forbidden_character, "_")
|
||||||
|
|
||||||
"""Get the absolute path and rename the audio file"""
|
"""Get the absolute path and rename the audio file"""
|
||||||
dst = os.path.join(os.path.abspath(os.path.dirname(file)), rename)
|
dst = os.path.join(os.path.abspath(os.path.dirname(file)), rename)
|
||||||
@ -212,5 +182,6 @@ def main():
|
|||||||
|
|
||||||
music.set_format(sys.argv[2])
|
music.set_format(sys.argv[2])
|
||||||
music.rename_music()
|
music.rename_music()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Reference in New Issue
Block a user