| 
					
				 | 
			
			
				@@ -11,8 +11,6 @@ import sys 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import symuid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# http://id3.org/id3v2.4.0-frames#4.1. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-TRACK_UUID_ID3_OWNER_ID = 'symuid' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # freeform keys start with '----' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # http://mutagen.readthedocs.io/en/latest/api/mp4.html 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 TRACK_UUID_MP4_TAG = '----:symuid:uuid' 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -23,26 +21,18 @@ def generate_uuid(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return subprocess.check_output(['uuid', '-v', '4', '-F', 'BIN']).strip() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-def get_uuid_id3(id3_tags): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    assert isinstance(id3_tags, mutagen.id3.ID3), type(id3_tags) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ufids = id3_tags.getall('UFID') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    for ufid in ufids: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ufid.owner == TRACK_UUID_ID3_OWNER_ID: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return ufid.data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-def get_or_assign_uuid_id3(id3_tags): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    uuid = get_uuid_id3(id3_tags) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def get_or_assign_uuid_id3(track): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    uuid = track._iface.get_uuid() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if uuid is None: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        id3_tags = track._iface._mutagen_file.tags 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         # mutagen.id3._specs.EncodedTextSpec.write encodes 'owner' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         id3_tags.add(mutagen.id3.UFID( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            owner=TRACK_UUID_ID3_OWNER_ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            owner=track._iface._UFID_OWNER_ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             data=generate_uuid(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         )) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         id3_tags.save() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         id3_tags.load(filename=id3_tags.filename) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        uuid = get_uuid_id3(id3_tags) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        uuid = track._iface.get_uuid() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         print("{!r}: assigned uuid {!r}".format(id3_tags.filename, uuid)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         assert uuid is not None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return uuid 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -66,9 +56,11 @@ def get_or_assign_uuid_mp4(mp4_file): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def log_path(track_path, msg, stream=sys.stdout): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     stream.write("{!r}: {}\n".format(track_path, msg)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def log_path_error(track_path, msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     log_path(track_path, msg, stream=sys.stderr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def symuid_sync(path, path_ignore_regex, show_ignored=False): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for track in symuid.Track.walk( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             root_path=path, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -79,7 +71,7 @@ def symuid_sync(path, path_ignore_regex, show_ignored=False): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if isinstance(track._iface, symuid.tag_interface.MP4): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             get_or_assign_uuid_mp4(track._iface._mutagen_file) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         elif isinstance(track._iface, symuid.tag_interface.ID3): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            get_or_assign_uuid_id3(track._iface._mutagen_file.tags) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            get_or_assign_uuid_id3(track) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             raise Exception(track) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |