Browse Source

added symuid.Track.get/assign_uuid()

Fabian Peter Hammerle 5 years ago
parent
commit
4fa97e201b
3 changed files with 16 additions and 8 deletions
  1. 3 4
      symuid-sync
  2. 9 0
      symuid/__init__.py
  3. 4 4
      symuid/tag_interface.py

+ 3 - 4
symuid-sync

@@ -33,10 +33,9 @@ def symuid_sync(path, path_ignore_regex, show_ignored=False):
             ignored_cb=lambda p: show_ignored and log_path(p, 'ignored'),
             unsupported_cb=lambda p, e: log_path_error(p, 'unsupported type, skipped'),
         ):
-        if track._iface.get_uuid() is None:
-            track._iface.set_uuid(generate_uuid())
-            track._iface.save()
-            log_path(track.path, 'assigned uuid {!r}'.format(track._iface.get_uuid()))
+        if track.get_uuid() is None:
+            track.assign_uuid(generate_uuid())
+            log_path(track.path, 'assigned uuid {!r}'.format(track.get_uuid()))
 
 
 def _init_argparser():

+ 9 - 0
symuid/__init__.py

@@ -45,6 +45,15 @@ class Track:
     def path(self):
         return self._iface.track_path
 
+    def get_uuid(self):
+        return self._iface.get_track_uuid()
+
+    def assign_uuid(self, uuid):
+        if self.get_uuid():
+            raise Exception("{!r} already has an uuid".format(self.path))
+        self._iface.set_track_uuid(uuid)
+        self._iface.save()
+
     def _get_play_counts(self, player=None, library_id=None):
         label = 'symuid:pcnt'
         assert library_id is None or player is not None

+ 4 - 4
symuid/tag_interface.py

@@ -51,13 +51,13 @@ class ID3(_mutagen):
         self._mutagen_file.tags.add(tag)
         return tag
 
-    def get_uuid(self):
+    def get_track_uuid(self):
         for ufid in self._mutagen_file.tags.getall('UFID'):
             if ufid.owner == self._UFID_OWNER_ID:
                 return ufid.data
         return None
 
-    def set_uuid(self, uuid):
+    def set_track_uuid(self, uuid):
         # mutagen.id3._specs.EncodedTextSpec.write encodes 'owner'
         tag = mutagen.id3.UFID(owner=self._UFID_OWNER_ID, data=uuid)
         self._mutagen_file.tags.add(tag)
@@ -127,11 +127,11 @@ class MP4(_mutagen):
         self._mutagen_file.tags['----:' + tag_label] = [tag]
         return tag
 
-    def get_uuid(self):
+    def get_track_uuid(self):
         try:
             return self._get_free_uuid(self._UUID_TAG_KEY)
         except KeyError:
             return None
 
-    def set_uuid(self, uuid):
+    def set_track_uuid(self, uuid):
         return self._set_free_uuid(self._UUID_TAG_KEY, uuid)