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 None if the analysis fails

CheckArtwork()[source]

See StoreArtwork(). This method is the same as StoreArtwork(None).

GetAlbumname()[source]

This method returns the name of the album

Returns

The album name as string, or None if entry does not exist

GetAllMetadata()[source]

This method collects as much information as possible from a file. The information gets stored in a dictionary.

Additional information for audio files
Additional information for video files
GetArtistname()[source]

This method returns the name of the artist

Returns

The artist name as string, or None if entry does not exist

GetBitrate()[source]

This method returns the bitrate of the file.

Returns

bitrate as integer or 0

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 0 if entry does not exist

GetLyrics()[source]

This method tries to get lyrics from the metadata. If on lyrics were found, None gets returned.

Returns

The lyrics as string, or None if 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 using ffprobe. Only if this method fails, the playtime gets read from the meta data.

Returns

playtime in second, or 0 if there is no way to get the time

GetReleaseyear()[source]

This method returns the release year

Returns

The release year as integer, or 0 if entry does not exist

GetSongname()[source]

This method returns the name of a song

Returns

The song name as string, or None if entry does not exist

GetTracknumber()[source]

This method returns the track number.

Returns

The track number as integer, or 0 if 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" or None

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:

width_{correct} = width_{meta} \cdot SAR

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) or None

Load(path)[source]

Supported file extensions for audio files:

  • For MPEG4: aac, m4a

  • For MPEG3: mp3, MP3

  • For FLAC: flac

Supported file extensions for video files:

  • For MPEG4: m4v (mp4)

  • For WebM: webm

The corner case of an mp4 file 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 a ValueError exception 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, False gets 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

True on success, otherwise False