curds: Add library playlist
This playlist represents all tracks in a given subdirectory, and is how we control adding or removing tracks. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
e0763ec727
commit
b9a563024f
|
@ -0,0 +1,24 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from . import playlist
|
||||
from .. import tags
|
||||
from .. import threadqueue
|
||||
import os
|
||||
|
||||
library_thread = threadqueue.ThreadQueue()
|
||||
|
||||
class LibraryPlaylist(playlist.Playlist):
|
||||
def __init__(self, path):
|
||||
playlist.Playlist.__init__(self, os.path.abspath(path))
|
||||
self.scan()
|
||||
|
||||
def scan(self):
|
||||
library_thread.push(self.thread_scan)
|
||||
|
||||
def thread_add(self, path):
|
||||
track = tags.Track.add(path)
|
||||
self.add(track)
|
||||
|
||||
def thread_scan(self):
|
||||
for dirname, subdirs, files in os.walk(self.name):
|
||||
for f in files:
|
||||
library_thread.push(self.thread_add, os.path.join(dirname, f))
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from . import library
|
||||
from . import playlist
|
||||
from .. import tags
|
||||
from .. import threadqueue
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
|
||||
test_library = os.path.abspath("./trier/Test Library")
|
||||
|
||||
class TestLibraryPlaylist(unittest.TestCase):
|
||||
def setUp(self):
|
||||
library.library_thread.stop()
|
||||
library.library_thread = threadqueue.ThreadQueue()
|
||||
tags.tag_map.clear()
|
||||
|
||||
def tearDownClass():
|
||||
library.library_thread.stop()
|
||||
|
||||
def test_playlist_library_init(self):
|
||||
self.assertIsInstance(library.library_thread, threadqueue.ThreadQueue)
|
||||
|
||||
plist = library.LibraryPlaylist(test_library + "/")
|
||||
self.assertIsInstance(plist, playlist.Playlist)
|
||||
self.assertEqual(plist.name, test_library)
|
||||
|
||||
def test_playlist_library_scan(self):
|
||||
plist = library.LibraryPlaylist(test_library)
|
||||
self.assertGreater(library.library_thread.qsize(), 0)
|
||||
library.library_thread.join()
|
||||
self.assertEqual(len(plist), 1250)
|
||||
self.assertEqual(plist.runtime(), "1 hour, 54 minutes, 35 seconds")
|
|
@ -9,4 +9,5 @@ class TestEmmental(unittest.TestCase):
|
|||
self.assertIsNotNone(curds.tags)
|
||||
self.assertIsNotNone(curds.threadqueue)
|
||||
self.assertIsNotNone(curds.playlist)
|
||||
self.assertIsNotNone(curds.playlist.library)
|
||||
self.assertIsNotNone(curds.playlist.playlist)
|
||||
|
|
Loading…
Reference in New Issue