Access metadata of various audio and video file formats using Python – tinytag library
Last Updated :
12 Nov, 2020
Metadata extraction is a necessary task while making music players or other related applications. The best python library to read music metadata of various audio and video file formats is tinytag. This library allows you to access metadata of various audio and video file formats like mp3, m4a, mp4, flac, wav etc.
The list of attributes you can access the album, album artist, artist, audio_offset, bitrate, comment, composer, disc, disc_total, duration, filesize, genre, sample rate, title, track, track_total, and year. Note that you can only read and not edit the metadata.
Installation:
This module does not come built-in with Python. To install this module type the below command in the terminal.
pip install tinytag
This library supports python 2.7+ and 3.4+ and pypy.
Extraction of metadata
First, import the Tinytag method from the tinytag library. Then, pass the file name to the Tinytag.get() method if it is present in the same directory, if not, pass the full path and assign this to any variable. Now, the attributes can be accessed using the following format: variable_name.attribute_name.
You can check if the file format you are using is supported or not using the method: TinyTag.is_supported(filename) which returns a bool value.
Note: Missing metadata will be shown as None
If you’d like to follow along, the download link for the audio and video file used in this article is given: m4a(audio) and mp4(video).
Example 1(Audio):
Python3
from tinytag import TinyTag
audio = TinyTag.get( "GeeksForGeeks_Audio.m4a" )
print ( "Title:" + audio.title)
print ( "Artist: " + audio.artist)
print ( "Genre:" + audio.genre)
print ( "Year Released: " + audio.year)
print ( "Bitrate:" + str (audio.bitrate) + " kBits/s" )
print ( "Composer: " + audio.composer)
print ( "Filesize: " + str (audio.filesize) + " bytes" )
print ( "AlbumArtist: " + audio.albumartist)
print ( "Duration: " + str (audio.duration) + " seconds" )
print ( "TrackTotal: " + str (audio.track_total))
|
Output:
Title:GeeksForGeeks_Audio
Artist: Neeraj Rana/GFG
Genre:Geek Music
Year Released: 2020
Bitrate:182.72 kBits/s
Composer: GeeksForGeeks Team
Filesize: 63076 bytes
AlbumArtist: Voice Recorder
Duration: 2.7306458333333334 seconds
TrackTotal: None
Example 2(Video):
Python3
from tinytag import TinyTag
video = TinyTag.get( "GeeksForGeeks_Video.mp4" )
print ( "Title:" + video.title)
print ( "Artist: " + video.artist)
print ( "Genre:" + video.genre)
print ( "Year Released: " + video.year)
print ( "Bitrate:" + str (video.bitrate) + " kBits/s" )
print ( "Composer: " + video.composer)
print ( "Filesize: " + str (video.filesize) + " bytes" )
print ( "AlbumArtist: " + str (video.albumartist))
print ( "Duration: " + str (video.duration) + " seconds" )
print ( "TrackTotal: " + str (video.track_total))
|
Output:
Title:GeeksForGeeks_Video
Artist: Neeraj Rana/GFG
Genre:Geek Video
Year Released: 2020
Bitrate:294651.393 kBits/s
Composer: GFG Video Team
Filesize: 511940 bytes
AlbumArtist: None
Duration: 1.8239333333333334 seconds
TrackTotal: None
If you come across any TypeError, you can use typecasting.
Similar Reads
Extract and Add FLAC Audio Metadata using the mutagen module in Python
Audio metadata is information embedded into audio files to identify and label audio files. Metadata includes information like artist, genre, album and track number. This information is very essential for making music players and other related applications. Streaming platforms also use metadata to ca
3 min read
Convert Audio to Video using Static Images in Python
In this article, we are going to convert an audio file(mp3) Â to a video file(mp4) using the images provided by the user to be shown during the duration of the video using Python. To do this, we will first convert the images to a GIF file and then combining with the audio file to produce the final vi
5 min read
How to extract image information from YouTube Playlist using Python?
Prerequisite: YouTube API Google provides a large set of APIs for the developer to choose from. Each and every service provided by Google has an associated API. Being one of them, YouTube Data API is very simple to use provides features like â Search for videosHandle videos like retrieve information
2 min read
Build a Music Player with Tkinter and Pygame in Python
We all use music players like Windows Media Player or VLC to play music on our system. Have you ever wanted to create your own music player if your answer is yes then with Python, you can build a customized Music Player. In this article, you will see how to build a simple yet functional music player
7 min read
MoviePy â Loading Audio File from Video
In this article we will see how we can load audio file from the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIFâs. Video is formed by the frames, combination of frames creates a video each frame is an individual image
1 min read
Python VLC Instance - Setting Meta Data of Application
In this article we will see how we can set the meta information of the application from the Instance class in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. Instance act as
2 min read
Video to Audio convert using Python
Prerequisites: Python Programming Language There are several libraries and techniques available in Python for the conversion of Video to Audio. One such library is Movie Editor. MoviePy can read and write all the most common audio and video formats, including GIF, and runs on Windows/Mac/Linux, with
1 min read
Python - Read blob object in python using wand library
BLOB stands for Binary Large OBject. A blob is a data type that can store binary data. This is different than most other data types used in databases, such as integers, floating point numbers, characters, and strings, which store letters and numbers. BLOB is a large complex collection of binary data
2 min read
Voice Assistant for Movies using Python
In this article, we will see how a voice assistant can be made for searching for movies or films. After giving input as movie name in audio format and it will give the information about that movie in audio format as well. As we know the greatest searching website for movies is IMDb. IMDb is an onlin
6 min read
Python VLC MediaList - Setting Single Media object to it
In this article we will see how we can set single media object to the MediaList object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediaList object contains the multip
2 min read