Skip to content

Commit

Permalink
refactor: query and hold artist and album name
Browse files Browse the repository at this point in the history
  • Loading branch information
add-n2x committed Jan 2, 2025
1 parent 7102d62 commit 5159c11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/ndtoolbox/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_media_file(self, file_path: str) -> MediaFile:
file_path (str): The path of the media file to retrieve.
"""
query = """
SELECT id, title, year, track_number, duration, bit_rate, artist_id, album_id, mbz_recording_id
SELECT id, title, year, track_number, duration, bit_rate, artist_id, artist, album_id, album, mbz_recording_id
FROM media_file
WHERE path LIKE ?
"""
Expand All @@ -164,6 +164,8 @@ def get_media_file(self, file_path: str) -> MediaFile:
result[6],
result[7],
result[8],
result[9],
result[10],
)

def get_artist(self, media_file: MediaFile, artist_id: str) -> Artist:
Expand Down
15 changes: 12 additions & 3 deletions src/ndtoolbox/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ class MediaFile:
bitrate (int): The bitrate of the media file in kbps.
annotation (Annotation): The annotation of the media file.
artist_id (str): The foreign key referencing the artist of the media file.
artist_name (str): The name of the artist of the media file (optional).
artist (Artist): The artist of the media file.
album_id (str): The foreign key referencing the album of the media file.
album (Album): The album of the media file.
album_name (str): The name of the album of the media file.
album (Album): The album of the media file (optional).
mbz_recording_id (str): The MusicBrainz recording ID of the media file.
has_keepable (bool): Indicates whether some of its media files is keepable.
"""
Expand All @@ -133,8 +135,10 @@ class MediaFile:
bitrate: int # in kbps
annotation: Optional[Annotation]
artist_id: Optional[str] # foreign key
arist_name: str
artist: Artist
album_id: Optional[str] # foreign key
album_name: str
album: Album
mbz_recording_id: str
has_keepable: bool
Expand All @@ -149,7 +153,9 @@ def __init__(
duration: int,
bitrate: int,
artist_id: str,
artist_name: str,
album_id: str,
album_name: str,
mbz_recording_id: str,
):
"""Init instance."""
Expand All @@ -161,15 +167,18 @@ def __init__(
self.duration = duration
self.bitrate = int(bitrate)
self.artist_id = artist_id
self.artist_name = artist_name
self.artist = None
self.album_id = album_id
self.album_name = album_name
self.album = None
self.mbz_recording_id = mbz_recording_id
self.annotation = None
self.has_keepable = False

def __repr__(self):
def __repr__(self) -> str:
"""Instance representation."""
return f"MediaFile(id={self.id}, path={self.path}, title={self.title}, year={self.year}, \
track_number={self.track_number}, duration={self.duration}, bitrate={self.bitrate}, \
artist_id={self.artist_id}, album_id={self.album_id}, mbz_recording_id={self.mbz_recording_id})"
artist_id={self.artist_id}, artist_name={self.artist_name} album_id={self.album_id}, \
album_name={self.album_name}, mbz_recording_id={self.mbz_recording_id})"

0 comments on commit 5159c11

Please sign in to comment.