|
@@ -8,7 +8,9 @@ import symuid
|
|
from symuid._uuid import generate_uuid4_bytes
|
|
from symuid._uuid import generate_uuid4_bytes
|
|
|
|
|
|
|
|
|
|
-def _log_path(track_path, msg, stream=sys.stdout):
|
|
|
|
|
|
+def _log_path(track_path, msg, stream=None):
|
|
|
|
+ if not stream: # pytest capsys
|
|
|
|
+ stream = sys.stdout
|
|
stream.write("{!r}: {}\n".format(track_path, msg))
|
|
stream.write("{!r}: {}\n".format(track_path, msg))
|
|
|
|
|
|
|
|
|
|
@@ -26,18 +28,19 @@ class _SyncPosition:
|
|
self._tracks.add(track)
|
|
self._tracks.add(track)
|
|
self._play_counts.update(track.get_play_counts())
|
|
self._play_counts.update(track.get_play_counts())
|
|
|
|
|
|
- @property
|
|
|
|
- def play_counts(self) -> typing.Set[symuid.PlayCount]:
|
|
|
|
- return self._play_counts
|
|
|
|
-
|
|
|
|
- @property
|
|
|
|
- def tracks(self) -> typing.Set[symuid.Track]:
|
|
|
|
- return self._tracks
|
|
|
|
|
|
+ def sync(self, play_count_added_cb=None) -> None:
|
|
|
|
+ for track in self._tracks:
|
|
|
|
+ track_play_counts = set(track.get_play_counts())
|
|
|
|
+ for play_count in self._play_counts:
|
|
|
|
+ if play_count not in track_play_counts:
|
|
|
|
+ track.register_play_count(
|
|
|
|
+ play_count, tag_set_cb=play_count_added_cb)
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
def __repr__(self) -> str:
|
|
return repr(vars(self))
|
|
return repr(vars(self))
|
|
|
|
|
|
-def sync(path, path_ignore_regex, show_ignored=False):
|
|
|
|
|
|
+def sync(path, path_ignore_regex, show_ignored=False,
|
|
|
|
+ play_count_added_cb=None):
|
|
sync_positions = collections.defaultdict(_SyncPosition)
|
|
sync_positions = collections.defaultdict(_SyncPosition)
|
|
for track in symuid.Track.walk(
|
|
for track in symuid.Track.walk(
|
|
root_path=path,
|
|
root_path=path,
|
|
@@ -52,11 +55,7 @@ def sync(path, path_ignore_regex, show_ignored=False):
|
|
track.get_uuid()))
|
|
track.get_uuid()))
|
|
sync_positions[track.get_uuid()].add_track(track)
|
|
sync_positions[track.get_uuid()].add_track(track)
|
|
for sync_position in sync_positions.values():
|
|
for sync_position in sync_positions.values():
|
|
- for track in sync_position.tracks:
|
|
|
|
- track_play_counts = set(track.get_play_counts())
|
|
|
|
- for play_count in sync_position.play_counts:
|
|
|
|
- if play_count not in track_play_counts:
|
|
|
|
- track.register_play_count(play_count)
|
|
|
|
|
|
+ sync_position.sync(play_count_added_cb=play_count_added_cb)
|
|
|
|
|
|
|
|
|
|
def _init_argparser():
|
|
def _init_argparser():
|
|
@@ -81,4 +80,6 @@ def _init_argparser():
|
|
def _main():
|
|
def _main():
|
|
argparser = _init_argparser()
|
|
argparser = _init_argparser()
|
|
args = argparser.parse_args()
|
|
args = argparser.parse_args()
|
|
- sync(**vars(args))
|
|
|
|
|
|
+ sync(**vars(args),
|
|
|
|
+ play_count_added_cb=lambda track, tag:
|
|
|
|
+ _log_path(track.path, 'added play count tag {!r}'.format(tag)))
|