cross-platform, Python 2.x/3.x audio metadata ("tagging") library based on TagLib
Project description
pytaglib is a Python audio tagging library. It is cross-platform, works with all Python versions, and is very simple to use yet fully featured:
supports more than a dozen file formats including mp3, flac, ogg, wma, and mp4,
support arbitrary, non-standard tag names,
support multiple values per tag.
pytaglib is a very thin wrapper (<150 lines of code) around the fast and rock-solid TagLib C++ library.
Get it
In most cases, you should install pytaglib with pip:
pip install pytaglib
See installation notes below for requirements and manual compilation.
Usage
>>> import taglib
>>> song = taglib.File("/path/to/my/file.mp3")
>>> song.tags
{'ARTIST': ['piman', 'jzig'], 'ALBUM': ['Quod Libet Test Data'], 'TITLE': ['Silence'], 'GENRE': ['Silence'], 'TRACKNUMBER': ['02/10'], 'DATE': ['2004']}
>>> song.length
239
>>> song.tags["ALBUM"] = ["White Album"] # always use lists, even for single values
>>> del song.tags["DATE"]
>>> song.tags["GENRE"] = ["Vocal", "Classical"]
>>> song.tags["PERFORMER:HARPSICHORD"] = ["Ton Koopman"]
>>> song.save()
For detailed API documentation, use the docstrings of the taglib.File class or view the source code directly.
Note: pytaglib uses unicode strings (type str in Python 3 and unicode in Python 2) for both tag names and values. The library converts byte-strings to unicode strings on assignment, but it is recommended to provide unicode strings only to avoid encoding problems.
Installation Notes #installnotes
The most recommended installation method is
pip install pytaglib
subject to the following notes:
Ensure that pip points to the correct Python version; you might need to use, e.g., pip-3.5 if you want to install pytaglib for Python 3.5 and your system’s default is Python 2.7.
You may need administrator rights to install a package, i.e., sudo pip install pytaglib on Unix or running the command on a Admin console on windows
Alternatively, install locally into your user home with pip install --user pytaglib.
You need to have taglib installed with development headers (package libtag1-dev for debian-based linux, brew install taglib on OS X).
If taglib is installed at a non-standard location, you can tell pip where to look for its include (-I) and library (-L) files:
pip install --global-option=build_ext --global-option="-I/usr/local/include/" --global-option="-L/usr/local/lib" pytaglib
If the above does not work, continue reading for alternative methods of installation.
Linux / Unix
Distribution-Specific Packages
Debian- and Ubuntu-based linux flavors have binary packages for the Python 3 version, called python3-taglib. Unfortunatelly, they are heavily outdated, so you should use the above “pip” method whenever possible.
For Arch users, there is a package in the user repository (AUR) which I try to keep up-to-date.
Manual Compilation
Alternatively, you can download / checkout the sources and compile manually:
python setup.py build python setup.py test # optional sudo python setup.py install
You can manually specify taglib’s include and library directories:
python setup.py build --include-dirs /usr/local/include --library-dirs /usr/local/lib
Note: The taglib Python extension is built from the file taglib.cpp which in turn is auto-generated by Cython from taglib.pyx. To re-cythonize this file instead of using the shipped taglib.cpp, invoke setup.py with the --cython option.
Windows
Currently, the PyPI archive contains a binary version only for Python3.5/x64. For different combinations of Python version and architecture, you need to build yourself.
Note: The following procedure was tested for Python 3.5 on x64 only. Other python versions probably require some more work; see e.g. this page.
Install Microsoft Visual Studio 2015 Community Edition. In the installation process, be sure to enable C/C++ support.
Download and build taglib:
Download the current taglib release and extract it somewhere on your computer.
Start the VS2015 x64 Native Tools Command Prompt. On Windows 8/10, it might not appear in your start menu, but you can find it here: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools\Windows Desktop Command Prompts
Navigate to the extracted taglib folder and type: cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=".\taglib-install" to generate the Visual Studio project files.
Type msbuild INSTALL.vcxproj /p:Configuration=Release which will “install” taglib into the taglib-install subdirectory.
Still in the VS2015 command prompt, navigate to the pytaglib directory.
Tell pytaglib where to find taglib: set TAGLIB_HOME=C:\Path\To\taglib-install
Build pytaglib: python setup.py build and install: python setup.py install
Contact
For bug reports or feature requests, please use the issue tracker on GitHub. For anything else, contact me by email.
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 Distributions
Hashes for pytaglib-1.4.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5fb0eec4a8151a23597909cd058ab0343c114279397ad8c6d58f56236d05a80 |
|
MD5 | 42b1d9c6a95fd8db214c87e1ddc46309 |
|
BLAKE2b-256 | b8bfe73c32fdd108bb07eee8f2500ba5e2c0889afe12d97cdaa59100b8bcf41b |
Hashes for pytaglib-1.4.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9d7cdeffb4e9987a70548cfee4aabb69e01cedb52f9e1a11db2520fcbc84a47 |
|
MD5 | 881edd57f45ced3dcd54dcf009308e4e |
|
BLAKE2b-256 | 5465c61970bb4440aef874b3007c86d417097aada4647fa76ef81d7298944336 |
Hashes for pytaglib-1.4.2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99c03c94e0123b8457ef91b4b90c1efc95a44f442614d477ee4b07b81b0870e9 |
|
MD5 | e736e6efcde263c076fbc245ad9e0e8f |
|
BLAKE2b-256 | d4b4b4aa5e546b45bd1e7720292d6fc740ab142adfa16c92ef2a290ef97f2f74 |
Hashes for pytaglib-1.4.2-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7930504a964cbf1c870bb88df4a3dcf032de34970a2b0dd38b7994a0b1fac806 |
|
MD5 | 458f3cd689a863bbb691b378274b2257 |
|
BLAKE2b-256 | ab77da1fb1299d0c8819bb50d5dfbb04243d830718693e6b082d35e7fbc5ebf2 |