Example #1
0
    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()
Example #2
0
    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()
Example #3
0
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")
Example #4
0
    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)
Example #5
0
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")
Example #6
0
    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)
Example #7
0
 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()
Example #8
0
 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()
Example #9
0
def get_scan_dirs():
    dirs = split_scan_dirs(config.get("settings", "scan"))
    return [bytes2fsnative(d) for d in dirs if d]
Example #10
0
def get_scan_dirs():
    dirs = split_scan_dirs(config.get("settings", "scan"))
    return [bytes2fsnative(d) for d in dirs if d]