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)
|
library_thread.push(self.thread_scan)
|
||||||
|
|
||||||
def thread_add(self, path):
|
def thread_add(self, path):
|
||||||
track = tags.Track.add(path)
|
track = tags.Track.lookup(path)
|
||||||
if track != None:
|
if not track in self:
|
||||||
self.add(track)
|
self.add(track)
|
||||||
notify.Notify.notify("on-scan", self, track)
|
|
||||||
|
|
||||||
def thread_scan(self):
|
def thread_scan(self):
|
||||||
for dirname, subdirs, files in os.walk(self.name):
|
for dirname, subdirs, files in os.walk(self.name):
|
||||||
|
|
|
@ -18,7 +18,6 @@ class TestLibraryPlaylist(unittest.TestCase):
|
||||||
library.library_thread.stop()
|
library.library_thread.stop()
|
||||||
library.library_thread = threadqueue.ThreadQueue()
|
library.library_thread = threadqueue.ThreadQueue()
|
||||||
tags.tag_map.clear()
|
tags.tag_map.clear()
|
||||||
self.scan_count = 0
|
|
||||||
|
|
||||||
def tearDownClass():
|
def tearDownClass():
|
||||||
library.library_thread.stop()
|
library.library_thread.stop()
|
||||||
|
@ -30,20 +29,13 @@ class TestLibraryPlaylist(unittest.TestCase):
|
||||||
self.assertIsInstance(plist, playlist.Playlist)
|
self.assertIsInstance(plist, playlist.Playlist)
|
||||||
self.assertEqual(plist.name, test_library)
|
self.assertEqual(plist.name, test_library)
|
||||||
|
|
||||||
def on_scan(self, plist, track):
|
|
||||||
self.scan_count += 1
|
|
||||||
|
|
||||||
def test_playlist_library_scan(self):
|
def test_playlist_library_scan(self):
|
||||||
notify.Notify.notify_me("on-scan", self.on_scan)
|
|
||||||
|
|
||||||
plist = library.LibraryPlaylist(test_library)
|
plist = library.LibraryPlaylist(test_library)
|
||||||
self.assertGreater(library.library_thread.qsize(), 0)
|
self.assertGreater(library.library_thread.qsize(), 0)
|
||||||
library.library_thread.join()
|
library.library_thread.join()
|
||||||
self.assertEqual(len(plist), 1250)
|
self.assertEqual(len(plist), 1250)
|
||||||
self.assertEqual(self.scan_count, 1250)
|
|
||||||
self.assertEqual(plist.runtime(), "1 hour, 54 minutes, 35 seconds")
|
self.assertEqual(plist.runtime(), "1 hour, 54 minutes, 35 seconds")
|
||||||
|
|
||||||
plist.scan()
|
plist.scan()
|
||||||
library.library_thread.join()
|
library.library_thread.join()
|
||||||
self.assertEqual(len(plist), 1250)
|
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")
|
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
||||||
plist = playlist.Playlist("Test Playlist")
|
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(len(plist), 1)
|
||||||
self.assertEqual(plist.runtime(), "1 second")
|
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(len(plist), 2)
|
||||||
self.assertEqual(plist.runtime(), "3 seconds")
|
self.assertEqual(plist.runtime(), "3 seconds")
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class TestPlaylist(unittest.TestCase):
|
||||||
|
|
||||||
def test_playlist_runtime(self):
|
def test_playlist_runtime(self):
|
||||||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
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 = playlist.Playlist("Test Playlist")
|
||||||
|
|
||||||
plist.add(track)
|
plist.add(track)
|
||||||
|
@ -66,7 +66,7 @@ class TestPlaylist(unittest.TestCase):
|
||||||
|
|
||||||
def test_playlist_notifications(self):
|
def test_playlist_notifications(self):
|
||||||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
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 = playlist.Playlist("Test Playlist")
|
||||||
|
|
||||||
notify.Notify.notify_me("on-add", self.on_add)
|
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,
|
return hash((hash(self.album), self.title, self.artist,
|
||||||
self.tracknumber, self.discnumber))
|
self.tracknumber, self.discnumber))
|
||||||
|
|
||||||
def add(path):
|
def lookup(path):
|
||||||
track = Track(path)
|
return Tag.lookup(Track(path), "new-track")
|
||||||
return track if Tag.lookup(track, "new-track") == track else None
|
|
||||||
|
|
||||||
|
|
||||||
def save():
|
def save():
|
||||||
|
|
|
@ -20,7 +20,7 @@ class TestTags(unittest.TestCase):
|
||||||
tags.load()
|
tags.load()
|
||||||
self.assertEqual(len(tags.tag_map), 0)
|
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())
|
self.assertFalse(dfile.exists())
|
||||||
tags.save()
|
tags.save()
|
||||||
self.assertTrue(dfile.exists())
|
self.assertTrue(dfile.exists())
|
||||||
|
@ -44,7 +44,7 @@ class TestTags(unittest.TestCase):
|
||||||
for dirname, subdirs, files in os.walk(test_library):
|
for dirname, subdirs, files in os.walk(test_library):
|
||||||
save = False
|
save = False
|
||||||
for f in files:
|
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
|
tracks += 1
|
||||||
save = True
|
save = True
|
||||||
if save == True:
|
if save == True:
|
||||||
|
|
|
@ -61,7 +61,7 @@ class TestTrackTag(unittest.TestCase):
|
||||||
|
|
||||||
def test_track_add(self):
|
def test_track_add(self):
|
||||||
notify.Notify.notify_me("new-track", self.on_new_track)
|
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.assertIsNotNone(t)
|
||||||
self.assertIn(t, tags.tag_map.values())
|
self.assertIn(t, tags.tag_map.values())
|
||||||
self.assertIn(t.album, tags.tag_map.values())
|
self.assertIn(t.album, tags.tag_map.values())
|
||||||
|
@ -69,8 +69,8 @@ class TestTrackTag(unittest.TestCase):
|
||||||
|
|
||||||
self.cb_track = None
|
self.cb_track = None
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
u = tags.Track.add(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
u = tags.Track.lookup(os.path.join(test_tracks, "01 - Test Track.ogg"))
|
||||||
self.assertIsNone(u)
|
self.assertEqual(t, u)
|
||||||
self.assertIsNone(self.cb_track)
|
self.assertIsNone(self.cb_track)
|
||||||
self.assertEqual(len(tags.tag_map), 2)
|
self.assertEqual(len(tags.tag_map), 2)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue