|
@@ -55,7 +55,7 @@ class Indexer(Thread):
|
|
|
buffer = deque()
|
|
buffer = deque()
|
|
|
|
|
|
|
|
# -- Walk through music folders
|
|
# -- Walk through music folders
|
|
|
- # Index new files
|
|
|
|
|
|
|
+ # Put new files in buffer
|
|
|
for music_folder in music_folders:
|
|
for music_folder in music_folders:
|
|
|
music_folder_path = Path(music_folder.path)
|
|
music_folder_path = Path(music_folder.path)
|
|
|
|
|
|
|
@@ -88,7 +88,7 @@ class Indexer(Thread):
|
|
|
buffer.append(track.id)
|
|
buffer.append(track.id)
|
|
|
del index[filename]
|
|
del index[filename]
|
|
|
|
|
|
|
|
- # Index missing files
|
|
|
|
|
|
|
+ # Put missing files in buffer
|
|
|
for filename, track in index.items():
|
|
for filename, track in index.items():
|
|
|
if track.id in buffer:
|
|
if track.id in buffer:
|
|
|
continue
|
|
continue
|
|
@@ -103,7 +103,7 @@ class Indexer(Thread):
|
|
|
while buffer:
|
|
while buffer:
|
|
|
filename_or_id = buffer.pop()
|
|
filename_or_id = buffer.pop()
|
|
|
try:
|
|
try:
|
|
|
- track = self.index(track_repo, filename_or_id)
|
|
|
|
|
|
|
+ track = self.index(track_repo, filename_or_id, tracks)
|
|
|
tracks.append(track)
|
|
tracks.append(track)
|
|
|
except AlreadyIndexed:
|
|
except AlreadyIndexed:
|
|
|
pass
|
|
pass
|
|
@@ -123,9 +123,11 @@ class Indexer(Thread):
|
|
|
logger.info(f"{len(tracks)} tracks indexed")
|
|
logger.info(f"{len(tracks)} tracks indexed")
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
- def index(track_repo, filename_or_track_id):
|
|
|
|
|
|
|
+ def index(track_repo, filename_or_track_id, previously_indexed=None):
|
|
|
""" index a media file from the filesystem or a track id """
|
|
""" index a media file from the filesystem or a track id """
|
|
|
|
|
|
|
|
|
|
+ previously_indexed = previously_indexed or []
|
|
|
|
|
+
|
|
|
if type(filename_or_track_id) is int:
|
|
if type(filename_or_track_id) is int:
|
|
|
track = track_repo.get_by_id(filename_or_track_id)
|
|
track = track_repo.get_by_id(filename_or_track_id)
|
|
|
filename = Path(track.path)
|
|
filename = Path(track.path)
|
|
@@ -144,6 +146,9 @@ class Indexer(Thread):
|
|
|
|
|
|
|
|
track_hash = hash_file(filename)
|
|
track_hash = hash_file(filename)
|
|
|
|
|
|
|
|
|
|
+ if any(t.hash == track_hash for t in previously_indexed):
|
|
|
|
|
+ raise AlreadyIndexed(f"File already indexed")
|
|
|
|
|
+
|
|
|
track = track_repo.get_by_hash(track_hash)
|
|
track = track_repo.get_by_hash(track_hash)
|
|
|
if not track:
|
|
if not track:
|
|
|
track = Track()
|
|
track = Track()
|