package

mmusicc.metadata module

Base Module for all metadata interactions with files and the database.

Hint

how to doc metaclass properties and functions in class?

class mmusicc.metadata.MetadataMeta(name, bases, nmspc)[source]

Bases: type

Meta Object for Metadata class.

dry_run

Get or set. If True do everything as usual, but without writing data.

Type:bool
is_linked_database

Get True if a database is linked to class.

Type:bool

Link a database to class.

Parameters:database_url (str) – database url following RFC-1738*. If the sting, does not contain ‘://’, a filepath for a sqlite database is assumed.
Raises:Exception – if a database is already linked

Unlink the database from the class.

Raises:Exception – if no database is linked
class mmusicc.metadata.Metadata(file_path=None, read_tag=True)[source]

Bases: object

Class containing Metadata Information,

either from a linked file or loaded from a database.

Parameters:
  • file_path (str or pathlib.Path, optional) – path to an supported audio file, can be set later with ‘link_audio_file()’ too. Defaults to None.
  • read_tag (bool, optional) – enables automatic reading of metadata from file at class initialisation. Defaults to True.
file_path

Get file path of linked audio file.

Type:pathlib.Path
audio_file_linked

Get True if a audio file is linked to instance.

Type:bool

Links audio file with given path to instance.

Parameters:file_path (str or pathlib.Path) – file path of audio file.
Raises:FileNotFoundError – if file does not exist.
unprocessed_tag

Get file path of linked audio file.

Type:pathlib.Path
dict_data

Get the dict containing tags

Type:MetadataDict
get_tag(str_tag_key)[source]

Get value of given str_tag_key

set_tag(str_tag_key, value)[source]

Set value of tag with given str_tag_key

read_tags()[source]

Read metadata from linked audio file into dict meta.

Raises:Exception – if no file is linked
write_tags(remove_existing=False, write_empty=False)[source]

write metadata to linked audio file

Parameters:
  • remove_existing (bool, optional) – If true clear all tags on file before writing. Defaults to False.
  • write_empty (bool) – if true write empty tags, exact effect depends on comment type. Either the tag entries will not exist or overwritten with None/Null/”“. Defaults to False.
Returns:

1 if data was saved to file, zero if nothing was changed on file.

Return type:

int

Raises:

Exception – if no file is linked

import_tags(source_meta, whitelist=None, blacklist=None, skip_none=True, clear_blacklisted=False)[source]

Imports metadata from another Metadata object.

Parameters:
  • source_meta (Metadata) – Metadata object containing the tags to be imported.
  • whitelist (list of str, optional) – whitelist of tags to be imported. If None, loads all tags (except blacklisted). Defaults to None.
  • blacklist (list of str, optional) – blacklist of tags not to be imported. Applied after whitelist. If None, no tags are blacklisted. Defaults to None.
  • skip_none (bool, optional) – If True, don’t overwrite values in target, which are None in source. Defaults to True.
  • clear_blacklisted (bool, optional) – Clear tags (set None) that are not in whitelist and/or in blacklist.
import_tags_from_db(primary_key=None, whitelist=None, blacklist=None, skip_none=True, clear_blacklisted=False)[source]

Imports metadata from the database.

Parameters:
  • primary_key (str, None) – unique identifier of the item which data has to be loaded. The save function only uses the absolute filepath atm. If value is None, a algorithm takes the path of the linked file works and works itself backward (beginning at the leave) in the key list of the DB until only one key is left, which is used. In other words, its acts like the keys are relative file path (with unknown working directory). Defaults to None.
  • whitelist (list of str, optional) – whitelist of tags to be imported. If None, loads all tags (except blacklisted). Defaults to None.
  • blacklist (list of str, optional) – blacklist of tags not to be imported. Applied after whitelist. If None, no tags are blacklisted. Defaults to None.
  • skip_none (bool, optional) – If True, don’t overwrite values in target, which are None in source. Defaults to True.
  • clear_blacklisted (bool, optional) – Clear tags (set None) that are not in whitelist and/or in blacklist.
  • Raises – Exception: if no database linked to class
export_tags_to_db()[source]

Saves all tags to database.

This is the secure way. Data not wanted does not have to be loaded, but all data can still be accessed in case it is needed again.

Raises:Exception – if no database linked to class
auto_fill_tags()[source]

Automatic fill/autocomplete tags with in config file defined rules.

This future is intended to fix small consistency errors in metadata, like missing album artists or leading 0 before a single digit tracknumber.

class mmusicc.metadata.GroupMetadata(list_metadata)[source]

Bases: mmusicc.metadata.Metadata

Class holding one ore many Metadata Objects. Subclasses Metadata and

overwrites Metadata functions so that you don’t have to care if you have one file or a list of files like an album. Tags in dict are a summary of the tags of individual values of the contained metadata. If all values of a tag are identical the value is in dict as it is, otherwise a Div object is created managing different values.

Parameters:list_metadata (list of Metadata or list of str or list of pathlib.Path) – list of Metadata objects or file paths.

Note

Not all properties and functions of Metadata are supported (like file_path, obviously). Stick with the documented ones.

get_tag(str_tag_key)[source]

Super-Method applied to all Objects in list. See Metadata.

set_tag(str_tag_key, value)[source]

Super-Method applied to all Objects in list. See Metadata.

auto_fill_tags()[source]

Super-Method applied to all Objects in list. See Metadata.

read_tags()[source]

Super-Method applied to all Objects in list. See Metadata.

write_tags(remove_existing=False, write_empty=False)[source]

Super-Method applied to all Objects in list. See Metadata.

import_tags(source_meta, whitelist=None, blacklist=None, skip_none=True, clear_blacklisted=False)[source]

Super-Method applied to all Objects in list. See Metadata.

Parameters:
  • source_meta (GroupMetadata) – group metadata object.
  • whitelist (list<str>, optional) – See Metadata.import_tags().
  • blacklist (list<str>, optional) – See Metadata.import_tags().
  • skip_none (bool, optional) – See Metadata.import_tags().
  • clear_blacklisted (bool, optional) – See Metadata.import_tags().
import_tags_from_db(whitelist=None, blacklist=None, skip_none=True, clear_blacklisted=False, primary_key=None)[source]

Super-Method applied to all Objects in list. See Metadata.

Parameters:
  • whitelist (list<str>, optional) – See Metadata.import_tags().
  • blacklist (list<str>, optional) – See Metadata.import_tags().
  • skip_none (bool, optional) – See Metadata.import_tags().
  • clear_blacklisted (bool, optional) – See Metadata.import_tags().
  • primary_key (str, None) – no function .
export_tags_to_db()[source]

Super-Method applied to all Objects in list. See Metadata.

audio_file_linked

Do not use this property. Only applies to Metadata.

unprocessed_tag

Super-Method applied to all Objects in list. See Metadata.

file_path

Do not use this property. Only applies to Metadata.

Do not use this property. Only applies to Metadata.

class mmusicc.metadata.AlbumMetadata(path_album)[source]

Bases: mmusicc.metadata.GroupMetadata

Special case of GroupMetadata where Metadata list is created from a Folder/Album path. Skips non audio files.

Parameters:path_album – filepath of album or folder to be accessed as group.

mmusicc.mmusicc module

Module handling user interaction, providing the command line interface, using the functions provided by ffmpeg and metadata. See usage for more information.