curds: Replace track.add() with track.lookup()
Now that we have a "new-track" notification, we can replace the add function with a lookup function that more closely mirrors how we look up album tags. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
8a4d3219d2
commit
1beb3cf869
|
@ -16,10 +16,9 @@ class LibraryPlaylist(playlist.Playlist):
|
|||
library_thread.push(self.thread_scan)
|
||||
|
||||
def thread_add(self, path):
|
||||
track = tags.Track.add(path)
|
||||
if track != None:
|
||||
track = tags.Track.lookup(path)
|
||||
if not track in self:
|
||||
self.add(track)
|
||||
notify.Notify.notify("on-scan", self, track)
|
||||
|
||||
def thread_scan(self):
|
||||
for dirname, subdirs, files in os.walk(self.name):
|
||||
|
|
|
@ -18,7 +18,6 @@ class TestLibraryPlaylist(unittest.TestCase):
|
|||
library.library_thread.stop()
|
||||
library.library_thread = threadqueue.ThreadQueue()
|
||||
tags.tag_map.clear()
|
||||
self.scan_count = 0
|
||||
|
||||
def tearDownClass():
|
||||
library.library_thread.stop()
|
||||
|
@ -30,20 +29,13 @@ class TestLibraryPlaylist(unittest.TestCase):
|
|||
self.assertIsInstance(plist, playlist.Playlist)
|
||||
self.assertEqual(plist.name, test_library)
|
||||
|
||||
def on_scan(self, plist, track):
|
||||
self.scan_count += 1
|
||||
|
||||
def test_playlist_library_scan(self):
|
||||
notify.Notify.notify_me("on-scan", self.on_scan)
|
||||
|
||||
plist = library.LibraryPlaylist(test_library)
|
||||
self.assertGreater(library.library_thread.qsize(), 0)
|
||||
library.library_thread.join()
|
||||
self.assertEqual(len(plist), 1250)
|
||||
self.assertEqual(self.scan_count, 1250)
|
||||
self.assertEqual(plist.runtime(), "1 hour, 54 minutes, 35 seconds")
|
||||
|
||||
plist.scan()
|
||||
library.library_thread.join()
|
||||
self.assertEqual(len(plist), 1250)
|
||||
self.assertEqual(self.scan_count, 1250)
|
||||
|
|
|
@ -25,11 +25,11 @@ class TestPlaylist(unittest.TestCase):
|
|||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
||||
plist = playlist.Playlist("Test Playlist")
|
||||
|
||||
plist.add(tags.Track.add(os.path.join(path, "01 - Test Track 01.ogg")))
|
||||
plist.add(tags.Track.lookup(os.path.join(path, "01 - Test Track 01.ogg")))
|
||||
self.assertEqual(len(plist), 1)
|
||||
self.assertEqual(plist.runtime(), "1 second")
|
||||
|
||||
plist.add(tags.Track.add(os.path.join(path, "02 - Test Track 02.ogg")))
|
||||
plist.add(tags.Track.lookup(os.path.join(path, "02 - Test Track 02.ogg")))
|
||||
self.assertEqual(len(plist), 2)
|
||||
self.assertEqual(plist.runtime(), "3 seconds")
|
||||
|
||||
|
@ -40,7 +40,7 @@ class TestPlaylist(unittest.TestCase):
|
|||
|
||||
def test_playlist_runtime(self):
|
||||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
||||
track = tags.Track.add(os.path.join(path, "01 - Test Track 01.ogg"))
|
||||
track = tags.Track.lookup(os.path.join(path, "01 - Test Track 01.ogg"))
|
||||
plist = playlist.Playlist("Test Playlist")
|
||||
|
||||
plist.add(track)
|
||||
|
@ -66,7 +66,7 @@ class TestPlaylist(unittest.TestCase):
|
|||
|
||||
def test_playlist_notifications(self):
|
||||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
||||
track = tags.Track.add(os.path.join(path, "01 - Test Track 01.ogg"))
|
||||
track = tags.Track.lookup(os.path.join(path, "01 - Test Track 01.ogg"))
|
||||
plist = playlist.Playlist("Test Playlist")
|
||||
|
||||
notify.Notify.notify_me("on-add", self.on_add)
|
||||
|
|
|
@ -69,9 +69,8 @@ class Track(Tag):
|
|||
return hash((hash(self.album), self.title, self.artist,
|
||||
self.tracknumber, self.discnumber))
|
||||
|
||||
def add(path):
|
||||
track = Track(path)
|
||||
return track if Tag.lookup(track, "new-track") == track else None
|
||||
def lookup(path):
|
||||
return Tag.lookup(Track(path), "new-track")
|
||||
|
||||
|
||||
def save():
|
||||
|
|
|
@ -20,7 +20,7 @@ class TestTags(unittest.TestCase):
|
|||
tags.load()
|
||||
self.assertEqual(len(tags.tag_map), 0)
|
||||
|
||||
t = tags.Track.add(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
||||
t = tags.Track.lookup(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
||||
self.assertFalse(dfile.exists())
|
||||
tags.save()
|
||||
self.assertTrue(dfile.exists())
|
||||
|
@ -44,7 +44,7 @@ class TestTags(unittest.TestCase):
|
|||
for dirname, subdirs, files in os.walk(test_library):
|
||||
save = False
|
||||
for f in files:
|
||||
tq.push(tags.Track.add, os.path.join(dirname, f))
|
||||
tq.push(tags.Track.lookup, os.path.join(dirname, f))
|
||||
tracks += 1
|
||||
save = True
|
||||
if save == True:
|
||||
|
|
|
@ -61,7 +61,7 @@ class TestTrackTag(unittest.TestCase):
|
|||
|
||||
def test_track_add(self):
|
||||
notify.Notify.notify_me("new-track", self.on_new_track)
|
||||
t = tags.Track.add(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
||||
t = tags.Track.lookup(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
||||
self.assertIsNotNone(t)
|
||||
self.assertIn(t, tags.tag_map.values())
|
||||
self.assertIn(t.album, tags.tag_map.values())
|
||||
|
@ -69,8 +69,8 @@ class TestTrackTag(unittest.TestCase):
|
|||
|
||||
self.cb_track = None
|
||||
for i in range(10):
|
||||
u = tags.Track.add(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
||||
self.assertIsNone(u)
|
||||
u = tags.Track.lookup(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
||||
self.assertEqual(t, u)
|
||||
self.assertIsNone(self.cb_track)
|
||||
self.assertEqual(len(tags.tag_map), 2)
|
||||
|
||||
|
|
Loading…
Reference in New Issue