[PYTHON] I want to extract the tag information (title and artist) of a music file (flac, wav).

at first

I don't know about mp3 because I only have high resolution sound source. I want to get FLAC and WAVE tag information (song title and artist). In the mutagen library, the tag information of the wav format music file could not be obtained, so the pytaglib library was used.

PC environment

windows10 pro 64bit python 3.8.1 64bit

install pytaglib

pytaglib is a library that binds a C ++ library called TagLib so that it works from python.

Windows cannot be used with "pip install pytaglib"

"Manual Compilation: Windows" at the bottom of the formula was implemented below. pytaglib official

Preparation

Download TagLib and unzip it. (https://taglib.org/#windows)

Step 1

1. Install Microsoft Visual Studio 2015 Community Edition. In the installation process, be sure to enable C/C++ support. Alternatively, install Visual Studio 2017, but install the "v140" C++ toolset and use the "Visual Studio 2015" version of the developer command prompt below.

I'm using SDK8.1 to build C ++, but I can't install SDK8.1 with Microsoft Visual Studio 2019, so I'll install the old Visual Studio.

Step 2-1

Download the current taglib release and extract it somewhere on your computer.

Download TagLib and unzip it. (https://taglib.org/#windows)

Step 2-2

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

Execute "VS 2015 x64 Native Tools Command Prompt" from the start menu. ★ There are multiple command prompts, so don't make a mistake! image.png

Step 2-3

3. 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.

Move to the decompression destination of taglib and execute the following command (*) cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=".\taglib-install"

A "taglib-install" folder will be created in the taglib folder, and the library will be created.

Step 3

3. Still in the VS2015 command prompt, navigate to the pytaglib directory.

Change to the pytaglib directory on the command prompt in step 2.

Step 4

4. Tell pytaglib where to find taglib: set TAGLIB_HOME=C:\Path\To\taglib-install

Pass through the C ++ TagLib path created in step 2.

Step 5

5. Build pytaglib: python setup.py build and install: python setup.py install

Execute the following command to make it available in python.

python setup.py build
python setup.py install

★ If you make a mistake and execute it at another command prompt, you will get angry with "fatal error LNK1112". I got stuck here for a day ...

Finally

With this, I finally got the tag information as if it were in the sample! Since flac and wave can be obtained with the same code, I personally felt that it was better than mutagen. However, work is required from the build of TagLib's C ++ library, and there is little information in Japanese, so preparation is difficult.

sample.py


import taglib
song = taglib.File("/path/to/my/file.wave")
print(song.tags)

reference

-mutagen link: available with pip install mutagen. If you don't care about waves, this is enough

Recommended Posts

I want to extract the tag information (title and artist) of a music file (flac, wav).
I want to make a music player and file music at the same time
I want to add silence to the beginning of a wav file for 1 second
I want to get the operation information of yahoo route
I want to know the features of Python and pip
I want to find the intersection of a Bezier curve and a straight line (Bezier Clipping method)
I want to record the execution time and keep a log.
I want to get information from fstab at the ssh connection destination and execute a command
I want to clear up the question of the "__init__" method and the "self" argument of a Python class.
[Python scraping] Output the URL and title of the site containing a specific keyword to a text file
I want to sort a list in the order of other lists
I tried to extract and illustrate the stage of the story using COTOHA
I want to analyze the emotions of people who want to meet and tremble
I made a program to check the size of a file in Python
Python: I want to measure the processing time of a function neatly
I want to receive the configuration file and check if the JSON file generated by jinja2 is a valid JSON
I want to customize the appearance of zabbix
I want to write to a file with Python
I want to get the path of the directory where the running file is stored.
I want to display only different lines of a text file with diff
The story of IPv6 address that I want to keep at a minimum
I want to drop a file on tkinter and get its path [Tkinter DnD2]
Save an array of numpy to a wav file using the wave module
I want to set a life cycle in the task definition of ECS
I want to see a list of WebDAV files in the Requests module
I want to get the file name, line number, and function name in Python 3.4
How to save the feature point information of an image in a file and use it for matching
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I want to grep the execution result of strace
I want to plot the location information of GTFS Realtime on Jupyter! (With balloon)
I want to randomly sample a file in Python
I want to fully understand the basics of Bokeh
I tried to extract the text in the image file using Tesseract of the OCR engine
I want to take a screenshot of the site on Docker using any font
I want to replace the variables in the python template file and mass-produce it in another file.
I tried to visualize the spacha information of VTuber
I just wanted to extract the data of the desired date and time with Django
I want to increase the security of ssh connections
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
Extract only the sound of a specific instrument from a MIDI file and make it a separate file
I want to output a beautifully customized heat map of the correlation matrix. matplotlib edition
I tried to predict the genre of music from the song title on the Recurrent Neural Network
I considered the machine learning method and its implementation language from the tag information of Qiita
I tried to get the location information of Odakyu Bus
I want to start a lot of processes from python
I want to use only the normalization process of SudachiPy
NikuGan ~ I want to see a lot of delicious meat! !!
I made a function to check the model of DCGAN
I want to judge the authenticity of the elements of numpy array
I want to map the EDINET code and securities number
Keras I want to get the output of any layer !!
I want to know the legend of the IT technology world
I want to create a Dockerfile for the time being.
I tried to make a site that makes it easy to see the update information of Azure
I want to extract an arbitrary URL from the character string of the html source with python
I want to create a histogram and overlay the normal distribution curve on it. matplotlib edition
[Twitter] I want to make the downloaded past tweets (of my account) into a beautiful CSV
I want to get the name of the function / method being executed
I want to manually assign the training parameters of the [Pytorch] model
Conditional branch due to the existence of a shell script file
[Introduction to Python] I compared the naming conventions of C # and Python.