Skip to content

obfusk/nametag.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

NB: the syntax for the environment variable changed in click >= 8.0, use e.g. source_bash instead of bash_source for older versions.

For Bash, add this to ~/.bashrc:

eval "$(_NAMETAG_COMPLETE=bash_source nametag)"

For Zsh, add this to ~/.zshrc:

eval "$(_NAMETAG_COMPLETE=zsh_source nametag)"

For Fish, add this to ~/.config/fish/completions/nametag.fish:

eval (env _NAMETAG_COMPLETE=fish_source 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+