emmental/curds/playlist/library.py

53 lines
1.3 KiB
Python

# Copyright 2019 (c) Anna Schumaker.
from . import playlist
from .. import notify
from .. import threadqueue
from .. import trak
from .. import tree
import os
LIBRARY_ICON = "folder-music"
library_thread = threadqueue.ThreadQueue()
class LibraryPlaylist(playlist.Playlist):
def scan(self):
library_thread.push(self.thread_scan)
def thread_add(self, path):
self.add(trak.lookup(path))
def thread_save(self):
notify.notify("save-data")
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))
library_thread.push(self.thread_save)
class LibraryNode(tree.ETree):
def __init__(self):
tree.ETree.__init__(self, "Libraries", "folder-music")
def alloc_child(self, path, icon):
return LibraryPlaylist(path, icon,
[ "artist", "date", "album", "discnumber", "tracknumber" ])
def lookup(self, path):
library = self.find_child(os.path.abspath(path), LIBRARY_ICON)
library.scan()
return library
def join():
library_thread.join()
def reset():
global library_thread
if not library_thread.is_alive():
library_thread = threadqueue.ThreadQueue()
def stop():
library_thread.stop()