mirror of
https://github.com/beetbox/beets.git
synced 2026-02-25 00:32:50 +01:00
don't count existing items/albums as duplicates (allowing update)
This commit is contained in:
parent
58fb4392ee
commit
f3130152b1
2 changed files with 41 additions and 16 deletions
|
|
@ -106,8 +106,14 @@ def _duplicate_check(lib, task, recent=None):
|
|||
recent.add((artist, album))
|
||||
|
||||
# Look in the library.
|
||||
cur_paths = set(i.path for i in task.items)
|
||||
for album_cand in lib.albums(artist=artist):
|
||||
if album_cand.album == album:
|
||||
# Check whether the album is identical in contents, in which
|
||||
# case it is not a duplicate (will be replaced).
|
||||
other_paths = set(i.path for i in album_cand.items())
|
||||
if other_paths == cur_paths:
|
||||
continue
|
||||
return True
|
||||
|
||||
return False
|
||||
|
|
@ -132,13 +138,14 @@ def _item_duplicate_check(lib, task, recent=None):
|
|||
# Check the library.
|
||||
item_iter = lib.items(artist=artist, title=title)
|
||||
try:
|
||||
item_iter.next()
|
||||
except StopIteration:
|
||||
return False
|
||||
for other_item in item_iter:
|
||||
# Existing items not considered duplicates.
|
||||
if other_item.path == task.item.path:
|
||||
continue
|
||||
return True
|
||||
finally:
|
||||
item_iter.close()
|
||||
|
||||
return True
|
||||
return False
|
||||
|
||||
def _infer_album_fields(task):
|
||||
"""Given an album and an associated import task, massage the
|
||||
|
|
|
|||
|
|
@ -434,27 +434,35 @@ class DuplicateCheckTest(unittest.TestCase):
|
|||
self.i = _common.item()
|
||||
self.album = self.lib.add_album([self.i])
|
||||
|
||||
def _album_task(self, asis, artist=None, album=None):
|
||||
artist = artist or self.i.albumartist
|
||||
album = album or self.i.album
|
||||
def _album_task(self, asis, artist=None, album=None, existing=False):
|
||||
if existing:
|
||||
item = self.i
|
||||
else:
|
||||
item = _common.item()
|
||||
artist = artist or item.albumartist
|
||||
album = album or item.album
|
||||
|
||||
task = importer.ImportTask(path='a path', toppath='top path',
|
||||
items=[self.i])
|
||||
items=[item])
|
||||
task.set_match(artist, album, None, None)
|
||||
if asis:
|
||||
task.set_choice(importer.action.ASIS)
|
||||
else:
|
||||
task.set_choice(({'artist': artist, 'album': album}, [self.i]))
|
||||
task.set_choice(({'artist': artist, 'album': album}, [item]))
|
||||
return task
|
||||
|
||||
def _item_task(self, asis, artist=None, title=None):
|
||||
artist = artist or self.i.artist
|
||||
title = title or self.i.title
|
||||
def _item_task(self, asis, artist=None, title=None, existing=False):
|
||||
if existing:
|
||||
item = self.i
|
||||
else:
|
||||
item = _common.item()
|
||||
artist = artist or item.artist
|
||||
title = title or item.title
|
||||
|
||||
task = importer.ImportTask.item_task(self.i)
|
||||
task = importer.ImportTask.item_task(item)
|
||||
if asis:
|
||||
self.i.artist = artist
|
||||
self.i.title = title
|
||||
item.artist = artist
|
||||
item.title = title
|
||||
task.set_choice(importer.action.ASIS)
|
||||
else:
|
||||
task.set_choice({'artist': artist, 'title': title})
|
||||
|
|
@ -524,6 +532,16 @@ class DuplicateCheckTest(unittest.TestCase):
|
|||
recent)
|
||||
self.assertTrue(res)
|
||||
|
||||
def test_duplicate_album_existing(self):
|
||||
res = importer._duplicate_check(self.lib,
|
||||
self._album_task(False, existing=True))
|
||||
self.assertFalse(res)
|
||||
|
||||
def test_duplicate_item_existing(self):
|
||||
res = importer._item_duplicate_check(self.lib,
|
||||
self._item_task(False, existing=True))
|
||||
self.assertFalse(res)
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue