Meta Tags
Attention
Keep in mind that the main rule of MusicDB is: The Filesystem Is Always Right.
All data collected via this class shall only be uses as addition information, not as primary source!
MetaTags Class
- class musicdb.lib.metatags.MetaTags(root='/')[source]
This class can be used to access the metadata of the music files.
- Parameters:
root (str/Path) – All paths used in this class are relative to this path. Default is
"/".
- AnalysePlaytime()[source]
Analyses the playtime of a file using
ffprobe.The corresponding command line is the following:
ffprobe -v error -show_entries format=duration -print_format default=noprint_wrappers=1:nokey=1 $PATH
- Returns:
The duration in seconds (as float) or
Noneif the analysis fails
- CheckArtwork()[source]
See
StoreArtwork(). This method is the same asStoreArtwork(None).
- GetAlbumname()[source]
This method returns the name of the album
- Returns:
The album name as string, or
Noneif entry does not exist
- GetAllMetadata()[source]
This method collects as much information as possible from a file. The information gets stored in a dictionary.
song:GetSongname()album:GetAlbumname()artist:GetArtistname()releaseyear:GetReleaseyear()origin:GetOrigin()playtime:GetPlaytime()
- Additional information for audio files
cdnumber:GetCDNumber()songnumber:GetTracknumber()lyrics:GetLyrics()bitrate:GetBitrate()
- Additional information for video files
codec:GetVideoCodec()xresolution,yresolution:GetVideoResolution()
- GetArtistname()[source]
This method returns the name of the artist
- Returns:
The artist name as string, or
Noneif entry does not exist
- GetCDNumber()[source]
This method returns the CD Number. The CD number is only read from MP4 and MP3 metadata. For all other formats, this method always returns
0- Returns:
The CD number as integer, or
0if entry does not exist
- GetLyrics()[source]
This method tries to get lyrics from the metadata. If on lyrics were found,
Nonegets returned.- Returns:
The lyrics as string, or
Noneif entry does not exist
- GetOrigin()[source]
This method tries to determine where the file come from. The following origins can be detected:
"iTunes""bandcamp""Amazon""Google""music163"aka 网易云音乐"CD"as fallback for unknown flac files"internet"as fallback for any other unknown files
- Returns:
Name of the origin as string
- GetPlaytime()[source]
This method tries to determine the playtime of a song. It first calls
AnalysePlaytime()which gets the playtime direct form file usingffprobe. Only if this method fails, the playtime gets read from the meta data.- Returns:
playtime in second, or
0if there is no way to get the time
- GetReleaseyear()[source]
This method returns the release year
- Returns:
The release year as integer, or
0if entry does not exist
- GetSongname()[source]
This method returns the name of a song
- Returns:
The song name as string, or
Noneif entry does not exist
- GetTracknumber()[source]
This method returns the track number.
- Returns:
The track number as integer, or
0if entry does not exist
- GetVideoCodec()[source]
Tries to identify the video codec of a video file.
The corresponding command line is the following:
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 $PATH
- Returns:
A string with the identified codec like
"h264"orNone
- GetVideoResolution()[source]
Tries to identify the video resolution of a video file. There may be differences between the given resolution and the actual resolution of the video in the video player. This is due to the Sample Aspect Ratio (SAR). This method considers the SAR by returning the width multiplied by this ratio:

The height will not be changed.
The corresponding command line is the following:
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio -of csv=s=x:p=0 $PATH
- Returns:
A tuple
(width,height)with the identified resolution like(1920, 1080)orNone
- Load(path)[source]
Supported file extensions for audio files:
For MPEG4:
aac,m4aFor MPEG3:
mp3,MP3For FLAC:
flac
Supported file extensions for video files:
For MPEG4:
m4v(mp4)For WebM:
webm
The corner case of an
mp4file gets not handled as video because it is not clear if it shall be handled as audio or video file. A warning gets written into the log and aValueErrorexception raised.- Parameters:
path (str/Path) – path to the song file that shall be loaded
- Returns:
Nothing
- Raises:
TypeError – If path is not a string or pathlib.Path object
ValueError – If file not exist or file cannot be read.
ValueError – If the file extension or file format is not supported
- StoreArtwork(imgfilename)[source]
This method stores an artwork from the metadata into a file. If there is no artwork in the metadata,
Falsegets returned.If the file already exists, it gets overwritten.
If the path variable is
None, the image will not be stored. Then the return value indictes if there is an artwork embedded in the song file.If the path variable is not
None, the the return value also indicated if storing the artwork into the file succeeded.- Parameters:
imgfilename (str) – Absolute path to an image file to store the image at, or
None- Returns:
Trueon success, otherwiseFalse