MediaFile¶
-
class
beets.mediafile.MediaFile(path)¶ Represents a multimedia file on disk and provides access to its metadata.
-
__init__(path)¶ Constructs a new MediaFile reflecting the file at path. May throw UnreadableFileError.
-
classmethod
fields()¶ Get the names of all writable properties that reflect metadata tags (i.e., those that are instances of
MediaField).
-
classmethod
readable_fields()¶ Get all metadata fields: the writable ones from
fields()and also other audio properties.
-
save(id3v23=False)¶ Write the object’s tags back to the file.
By default, MP3 files are saved with ID3v2.4 tags. You can use the older ID3v2.3 standard by specifying the id3v23 option.
-
update(dict)¶ Set all field values from a dictionary.
For any key in dict that is also a field to store tags the method retrieves the corresponding value from dict and updates the MediaFile. If a key has the value None, the corresponding property is deleted from the MediaFile.
-
-
class
beets.mediafile.MediaField(*styles, **kwargs)¶ A descriptor providing access to a particular (abstract) metadata field.
-
__init__(*styles, **kwargs)¶ Creates a new MediaField.
Parameters: - styles – StorageStyle instances that describe the strategy for reading and writing the field in particular formats. There must be at least one style for each possible file format.
- out_type – the type of the value that should be returned when getting this property.
-
-
class
beets.mediafile.StorageStyle(key, as_type=<type 'unicode'>, suffix=None, float_places=2)¶ A strategy for storing a value for a certain tag format (or set of tag formats). This basic StorageStyle describes simple 1:1 mapping from raw values to keys in a Mutagen file object; subclasses describe more sophisticated translations or format-specific access strategies.
MediaFile uses a StorageStyle via three methods:
get(),set(), anddelete(). It passes a Mutagen file object to each.Internally, the StorageStyle implements
get()andset()using two steps that may be overridden by subtypes. To get a value, the StorageStyle first callsfetch()to retrieve the value corresponding to a key and thendeserialize()to convert the raw Mutagen value to a consumable Python value. Similarly, to set a field, we callserialize()to encode the value and thenstore()to assign the result into the Mutagen object.Each StorageStyle type has a class-level formats attribute that is a list of strings indicating the formats that the style applies to. MediaFile only uses StorageStyles that apply to the correct type for a given audio file.
-
delete(mutagen_file)¶ Remove the tag from the file.
-
deserialize(mutagen_value)¶ Given a raw value stored on a Mutagen object, decode and return the represented value.
-
fetch(mutagen_file)¶ Retrieve the raw value of for this tag from the Mutagen file object.
-
formats= ['FLAC', 'OggOpus', 'OggTheora', 'OggSpeex', 'OggVorbis', 'OggFlac', 'APEv2File', 'WavPack', 'Musepack', 'MonkeysAudio']¶ List of mutagen classes the StorageStyle can handle.
-
get(mutagen_file)¶ Get the value for the field using this style.
-
serialize(value)¶ Convert the external Python value to a type that is suitable for storing in a Mutagen file object.
-
set(mutagen_file, value)¶ Assign the value for the field using this style.
-
store(mutagen_file, value)¶ Store a serialized value in the Mutagen file object.
-