Skip to main content

GitHub Release PyPI Version Python Versions CI GPLv3+

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

GPLv3+

Metadata

Release files for nametag 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nametag 0.1.0
File Size Uploaded
nametag-0.1.0.tar.gz 18.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nametag 0.1.0
File Interpreter ABI Platform
nametag-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.7 kB

Release files / nametag-0.1.0.tar.gz

Download URL nametag-0.1.0.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4b8760f2150d0e2716a869fd3488cf66dc04c9833420d8b56aaf2d2ebefc5f89
BLAKE2b-256 checksum
How to use checksums
4041735b06b90d489256a8e0a9153e18f82a29492777603b166c27d4ac73bf0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / nametag-0.1.0-py3-none-any.whl

Download URL nametag-0.1.0-py3-none-any.whl
Size 19.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7abf98e90a53cb998c552dd79190cb0f6489a561080c2649e293ac2bf8c6bb1
BLAKE2b-256 checksum
How to use checksums
c576e591a6b35da0fa6e6510e408548b4994c92bc4c87f81ea22c2543a41b6fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page