Trackο
Compositely combine reader and writer classes for metadata/tags/properties operations on Track files.
Classes:
|
Generic track object for extracting, modifying, and saving metadata/tags/properties for a given file. |
- class musify.libraries.local.track.track.LocalTrack(file, remote_wrangler=None)ο
Bases:
LocalItem
,Track
,Generic
Generic track object for extracting, modifying, and saving metadata/tags/properties for a given file.
- Parameters:
file (
Union
[str
,Path
,TypeVar
(T
, bound=FileType
)]) β The path or Mutagen object of the file to load.remote_wrangler (
RemoteDataWrangler
(default:None
)) β Optionally, provide aRemoteDataWrangler
object for processing URIs. This object will be used to check for and validate a URI tag on the file. The tag that is used for reading and writing is set by theuri_tag
class attribute. If noremote_wrangler
is given, no URI processing will occur.
Attributes:
A name for this object
The map of tag names to tag IDs for the given file type.
This track's title
Joined string representation of all artists featured on this track
List of all artists featured on this track.
The album this track is featured on
The artist of the album this track is featured on
The position this track has on the album it is featured on
The track number of tracks on the album this track is featured on
List of genres associated with this track
A
date
object representing the release date of this trackThe year this track was released
The month this track was released
The day this track was released
The tempo of this track
The key of this track in alphabetical musical notation format
The number of the disc from the album this track is featured on
The total number the discs from the album this track is featured on
Is the album this track is featured on a compilation
Comments associated with this track set by the user
Does this track have a valid associated URI.
The images associated with the album this track is featured on in the form
{<image name/type>: <image link>}
Does the album this track is associated with have an image
Total duration of this track in seconds
The rating for this track
The path to the file.
The type of audio file of this track
The number of channels in this audio file i.e. 1 for mono, 2 for stereo, .
The bit rate of this track in kilobytes per second
The bit depth of this track in bits
The sample rate of this track in kHz
The timestamp for when this track was added to the associated collection
The timestamp when this track was last played
The total number of times this track has been played
Methods:
load
()Load local file from scratch using mutagen from the path stored in this object.
refresh
()Extract update tags for this object from the loaded mutagen object.
save
([tags,Β replace,Β dry_run])Update file's tags from given dictionary of tags.
delete_tags
([tags,Β dry_run])Remove tags from file.
merge
(track[,Β tags])Set the tags of this track equal to the given
track
.extract_images_to_file
(output_folder)Reload the file, extract and save all embedded images from file.
as_dict
()Return a dictionary representation of the key attributes of this object.
- property nameο
A name for this object
- property titleο
This trackβs title
- property artistο
Joined string representation of all artists featured on this track
- property artists: list[str]ο
List of all artists featured on this track.
- property albumο
The album this track is featured on
- property album_artistο
The artist of the album this track is featured on
- property track_numberο
The position this track has on the album it is featured on
- property track_totalο
The track number of tracks on the album this track is featured on
- property genresο
List of genres associated with this track
- property yearο
The year this track was released
- property monthο
The month this track was released
- property dayο
The day this track was released
- property bpmο
The tempo of this track
- property keyο
The key of this track in alphabetical musical notation format
- property disc_numberο
The number of the disc from the album this track is featured on
- property disc_totalο
The total number the discs from the album this track is featured on
- property compilationο
Is the album this track is featured on a compilation
- property commentsο
Comments associated with this track set by the user
- property has_uriο
Does this track have a valid associated URI. When None, answer is unknown.
- property image_linksο
The images associated with the album this track is featured on in the form
{<image name/type>: <image link>}
- property has_imageο
Does the album this track is associated with have an image
- property lengthο
Total duration of this track in seconds
- property ratingο
The rating for this track
- property pathο
The path to the file.
- property typeο
The type of audio file of this track
- property channels: intο
The number of channels in this audio file i.e. 1 for mono, 2 for stereo, β¦
- property bit_rate: floatο
The bit rate of this track in kilobytes per second
- property bit_depth: int | Noneο
The bit depth of this track in bits
- property sample_rate: floatο
The sample rate of this track in kHz
- property date_added: datetime | Noneο
The timestamp for when this track was added to the associated collection
- property last_played: datetime | Noneο
The timestamp when this track was last played
- property play_count: int | Noneο
The total number of times this track has been played
- async load()ο
Load local file from scratch using mutagen from the path stored in this object. Refreshes the metadata loaded into this object and returns self.
- Returns:
Self
β Self.- Raises:
FileDoesNotExistError β If the file cannot be found.
InvalidFileType β If the file type is not supported.
- refresh()ο
Extract update tags for this object from the loaded mutagen object.
- Return type:
None
- async save(tags=LocalTrackField.ALL, replace=False, dry_run=True)ο
Update fileβs tags from given dictionary of tags.
- Parameters:
tags (
GenericAlias
[LocalTrackField
] (default:<LocalTrackField.ALL: 0>
)) β Tags to be updated.replace (
bool
(default:False
)) β Destructively replace tags in each file.dry_run (
bool
(default:True
)) β Run function, but do not modify the file on the disk.
- Returns:
SyncResultTrack
β List of tags that have been updated.
- async delete_tags(tags=(), dry_run=True)ο
Remove tags from file.
- Parameters:
tags (
GenericAlias
[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.
- merge(track, tags=TrackField.ALL)ο
Set the tags of this track equal to the given
track
. Give a list oftags
to limit which are set- Return type:
None
- extract_images_to_file(output_folder)ο
Reload the file, extract and save all embedded images from file. Returns the number of images extracted.
- Return type:
int
- as_dict()ο
Return a dictionary representation of the key attributes of this object.
- The results of this function are used to produce the following:
A JSON representation of the object when calling
json()
The string representation of the object when calling str() on the object
The representation of the object when calling repr() on the object