Skip to content

Commit

Permalink
fix: tags now written to tracks if album fields changed
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpavlock committed Oct 12, 2022
1 parent 82d8591 commit 48f7076
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 6 additions & 3 deletions moe/plugins/write.py
Expand Up @@ -7,7 +7,7 @@

import moe
from moe import config
from moe.library import LibItem, Track
from moe.library import Album, LibItem, Track

__all__ = ["write_tags"]

Expand Down Expand Up @@ -62,10 +62,13 @@ def process_new_items(items: list[LibItem]):

@moe.hookimpl
def process_changed_items(items: list[LibItem]):
"""Writes tags to any altered tracks in the library."""
"""Writes tags to any altered tracks or albums in the library."""
for item in items:
if isinstance(item, Track):
if isinstance(item, Track) and item.album_obj not in items:
write_tags(item)
elif isinstance(item, Album):
for track in item.tracks:
write_tags(track)


@moe.hookimpl(tryfirst=True)
Expand Down
16 changes: 13 additions & 3 deletions tests/plugins/test_write.py
Expand Up @@ -169,10 +169,12 @@ def test_process_extra(self, mock_write):
mock_write.assert_not_called()

def test_process_album(self, mock_write):
"""Any altered albums are ignored."""
config.CONFIG.pm.hook.process_changed_items(items=[album_factory()])
"""Any altered albums should have their tracks written."""
album = album_factory()
config.CONFIG.pm.hook.process_changed_items(items=[album])

mock_write.assert_not_called()
for track in album.tracks:
mock_write.assert_any_call(track)

def test_process_multiple_tracks(self, mock_write):
"""All altered tracks are written."""
Expand All @@ -183,3 +185,11 @@ def test_process_multiple_tracks(self, mock_write):
for track in tracks:
mock_write.assert_any_call(track)
assert mock_write.call_count == 2

def test_dont_write_tracks_twice(self, mock_write):
"""Don't write a track twice if it's album is also in `items`."""
track = track_factory()

config.CONFIG.pm.hook.process_changed_items(items=[track, track.album_obj])

mock_write.assert_called_once_with(track)

0 comments on commit 48f7076

Please sign in to comment.