def __init__(self, dir, name, library=None): super(Playlist, self).__init__() self.__instances.append(self) if isinstance(name, unicode) and os.name != "nt": name = name.encode('utf-8') self.name = name self.dir = dir self.library = library self._list = HashedList() try: with open(self.filename, "rb") as h: for line in h: assert library is not None try: line = bytes2fsnative(line.rstrip()) except ValueError: # decoding failed continue if line in library: self._list.append(library[line]) elif library and library.masked(line): self._list.append(line) except IOError: if self.name: self.write()
def scan_library(library, force): """Start the global library re-scan If `force` is True, reload all existing valid items. """ paths = get_scan_dirs() exclude = split_scan_dirs(config.get("library", "exclude")) exclude = [bytes2fsnative(e) for e in exclude] copool.add(library.rebuild, paths, force, exclude, cofuncid="library", funcid="library")
def test_main(self): v = fsnative(u"foo") self.assertTrue(is_fsnative(v)) v2 = glib2fsnative(fsnative2glib(v)) self.assertTrue(is_fsnative(v2)) self.assertEqual(v, v2) v3 = bytes2fsnative(fsnative2bytes(v)) self.assertTrue(is_fsnative(v3)) self.assertEqual(v, v3)
def __populate_from_file(self): library = self.library try: with open(self.filename, "rb") as h: for line in h: assert library is not None try: line = bytes2fsnative(line.rstrip()) except ValueError: # decoding failed continue if line in library: self._list.append(library[line]) elif library and library.masked(line): self._list.append(line) except IOError: if self.name: print_d("Playlist '%s' not found, creating new." % self.name) self.write()
def get_scan_dirs(): dirs = split_scan_dirs(config.get("settings", "scan")) return [bytes2fsnative(d) for d in dirs if d]