set audio file tags based on file name
Project description
nametag - set audio file tags based on file name
nametag uses regular expressions to parse paths of audio files and then sets the file tags based on the parsed data. This allows you to keep paths and tags in sync by creating the tags from the paths.
Everything is configurable with some custom python code: the path
regexes, the character substitution, and the handling of special
cases. For example, the album if_then_else
by The Gathering should
not have its underscores changed to spaces.
Examples
# dry run (do not modify files) + verbose (shows info)
$ nametag -v --dry-run Between_the_Buried_and_Me/04-Colors_\(2007\)/05-Ants_of_the_Sky.mp3
/.../Between_the_Buried_and_Me/04-Colors_(2007)/05-Ants_of_the_Sky.mp3:
artist='Between the Buried and Me' album='Colors' track='05' title='Ants of the Sky' ext='mp3' album_n='04' year='2007'
# extra verbose (shows info before and after processing)
$ nametag -vv Between_the_Buried_and_Me/04-Colors_\(2007\)/05-Ants_of_the_Sky.mp3
/.../Between_the_Buried_and_Me/04-Colors_(2007)/05-Ants_of_the_Sky.mp3:
- artist='Between_the_Buried_and_Me' album='Colors' track='05' title='Ants_of_the_Sky' ext='mp3' album_n='04' year='2007'
+ artist='Between the Buried and Me' album='Colors' track='05' title='Ants of the Sky' ext='mp3' album_n='04' year='2007'
Configuration
Example ~/.nametagrc.py
:
# regexes array; each one is tried in turn to match the path; the
# default regex (nametag.RX) matches paths as in the examples above.
regexes.append(re.compile(r"""..."""))
# character substitutions; the default is { "_|": " /" }
tr["~"] = "_"
# custom processing rules; each one is tried in turn until one returns a value
@rule
def if_then_else(info, tr):
if info.artist == "The_Gathering" and info.album == "if_then_else":
return info._map_values(lambda k, v: v if k == "album" else tr(v))
$ nametag --show-config
=== config ===
regexes:
'/(?P<artist>[^/]*)/(?:(?P<album_n>\\d+)-)?(?P<album>[^/]*?)(?:_\\((?P<year>\\d{4})\\))?/(?P<track>\\d+)(?:-(?P<title>[^/]*))?\\.(?P<ext>mp3|ogg|flac)\\Z'
'...'
tr: {'_|': ' /', '~': '_'}
rules: if_then_else
Help
$ nametag --help
Tab Completion
For Bash, add this to ~/.bashrc
:
eval "$(_NAMETAG_COMPLETE=source_bash nametag)"
For Zsh, add this to ~/.zshrc
:
eval "$(_NAMETAG_COMPLETE=source_zsh nametag)"
For Fish, add this to ~/.config/fish/completions/nametag.fish
:
eval (env _NAMETAG_COMPLETE=source_fish nametag)
Requirements
- Python >= 3.8 + click + pytaglib.
Debian/Ubuntu
$ apt install python3-click python3-taglib
Installing
Using pip
$ pip install nametag
NB: depending on your system you may need to use e.g. pip3 --user
instead of just pip
.
From git
NB: this installs the latest development version, not the latest release.
$ git clone https://github.com/obfusk/nametag.py.git
$ cd nametag
$ pip install -e .
NB: you may need to add e.g. ~/.local/bin
to your $PATH
in order
to run nametag
.
To update to the latest development version:
$ cd nametag
$ git pull --rebase
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nametag-0.1.0.tar.gz
.
File metadata
- Download URL: nametag-0.1.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b8760f2150d0e2716a869fd3488cf66dc04c9833420d8b56aaf2d2ebefc5f89 |
|
MD5 | ae0607a1081afa9c930baf706bc7cc8c |
|
BLAKE2b-256 | 4041735b06b90d489256a8e0a9153e18f82a29492777603b166c27d4ac73bf0c |
File details
Details for the file nametag-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: nametag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7abf98e90a53cb998c552dd79190cb0f6489a561080c2649e293ac2bf8c6bb1 |
|
MD5 | 241b22778a5ddd7ec4d56196158c041d |
|
BLAKE2b-256 | c576e591a6b35da0fa6e6510e408548b4994c92bc4c87f81ea22c2543a41b6fa |