Writer

Inheritance diagram of musify.libraries.local.track.tags.writer

Implements all functionality pertaining to writing and deleting metadata/tags/properties for a LocalTrack.

Classes:

SyncResultTrack(saved, updated)

Stores the results of a sync with local track

TagWriter(file, tag_map[, remote_wrangler])

Functionality for updating and removing tags/metadata/properties from a mutagen object.

class musify.libraries.local.track.tags.writer.SyncResultTrack(saved, updated)

Bases: Result

Stores the results of a sync with local track

Attributes:

saved

Were changes to the file on the disk made.

updated

Map of the tag updated and the index of the condition it satisfied to be updated.

saved: bool

Were changes to the file on the disk made.

updated: Mapping[LocalTrackField, int]

Map of the tag updated and the index of the condition it satisfied to be updated.

class musify.libraries.local.track.tags.writer.TagWriter(file, tag_map, remote_wrangler=None)

Bases: TagProcessor, ABC, Generic

Functionality for updating and removing tags/metadata/properties from a mutagen object.

Attributes:

date_format

The date format to use when saving string representations of dates to tag values

Methods:

delete_tags([tags, dry_run])

Remove tags from file.

delete_tag(tag_name[, dry_run])

Remove a tag by its tag name.

write(source, target[, tags, replace, dry_run])

Write the tags from the target track to the source track.

write_tag(tag_id, tag_value[, dry_run])

Generic method for updating a tag value in the file.

write_title(source, target[, replace, dry_run])

Write track title tags to file if appropriate related conditions are met.

write_artist(source, target[, replace, dry_run])

Write the track artist tags to file if appropriate related conditions are met.

write_album(source, target[, replace, dry_run])

Write the track album tags to file if appropriate related conditions are met.

write_album_artist(source, target[, ...])

Write the track album artist tags to file if appropriate related conditions are met.

write_track(source, target[, replace, dry_run])

Write the track number and track total tags to file if appropriate related conditions are met.

write_genres(source, target[, replace, dry_run])

Write the track genre tags to file if appropriate related conditions are met.

write_date(source, target[, replace, dry_run])

Write the track date and/or year/month/day tags to file if appropriate related conditions are met.

write_bpm(source, target[, replace, dry_run])

Write track bpm tags to file if appropriate related conditions are met.

write_key(source, target[, replace, dry_run])

Write track key tags to file if appropriate related conditions are met.

write_disc(source, target[, replace, dry_run])

Write track dic number and disc total tags to file if appropriate related conditions are met.

write_compilation(source, target[, replace, ...])

Write track compilation tags to file if appropriate related conditions are met.

write_comments(source, target[, replace, ...])

Write track comments tags to file if appropriate related conditions are met.

write_uri(source, target[, replace, dry_run])

Write track URI tag to file if appropriate related conditions are met.

write_images(source, target[, replace, dry_run])

Write images to file if appropriate related conditions are met.

date_format = '%Y-%m-%d'

The date format to use when saving string representations of dates to tag values

delete_tags(tags=(), dry_run=True)

Remove tags from file.

Parameters:
  • tags (Union[LocalTrackField, Iterable[LocalTrackField]] (default: ())) – Tags to remove.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

SyncResultTrack – List of tags that have been removed.

delete_tag(tag_name, dry_run=True)

Remove a tag by its tag name.

Parameters:
  • tag_name (str) – Tag name as found in TagMap to remove.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

bool – True if tag has been remove, False otherwise.

write(source, target, tags=LocalTrackField.ALL, replace=False, dry_run=True)

Write the tags from the target track to the source track. Filter the tags written by supplying tags.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • tags (Union[LocalTrackField, Iterable[LocalTrackField]] (default: <LocalTrackField.ALL: 0>)) – The tags to be updated.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

abstract write_tag(tag_id, tag_value, dry_run=True)

Generic method for updating a tag value in the file.

Parameters:
  • tag_id (str | None) – ID of the tag for this file type.

  • tag_value (Any) – New value to assign.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

bool | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_title(source, target, replace=False, dry_run=True)

Write track title tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • replace – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_artist(source, target, replace=False, dry_run=True)

Write the track artist tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_album(source, target, replace=False, dry_run=True)

Write the track album tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_album_artist(source, target, replace=False, dry_run=True)

Write the track album artist tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_track(source, target, replace=False, dry_run=True)

Write the track number and track total tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_genres(source, target, replace=False, dry_run=True)

Write the track genre tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_date(source, target, replace=False, dry_run=True)

Write the track date and/or year/month/day tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

dict[LocalTrackField, int] | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_bpm(source, target, replace=False, dry_run=True)

Write track bpm tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_key(source, target, replace=False, dry_run=True)

Write track key tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_disc(source, target, replace=False, dry_run=True)

Write track dic number and disc total tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_compilation(source, target, replace=False, dry_run=True)

Write track compilation tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_comments(source, target, replace=False, dry_run=True)

Write track comments tags to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_uri(source, target, replace=False, dry_run=True)

Write track URI tag to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Ignored.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.

write_images(source, target, replace=False, dry_run=True)

Write images to file if appropriate related conditions are met.

Parameters:
  • source (Track) – The source track i.e. the track object representing the currently saved file on the drive.

  • target (Track) – The target track i.e. the track object containing new tags with which to update the file.

  • replace (bool (default: False)) – Destructively overwrite the tag on the file if the source and target tags differ.

  • dry_run (bool (default: True)) – Run function, but do not modify the file on the disk.

Returns:

int | None – The index number of the conditional that was met to warrant updating the file’s tags. None if none of the conditions were met.