예제 #1
0
 def test_load_legacy_format_to_xspf(self):
     playlist_fn = "old"
     songs_lib = FileLibrary()
     songs_lib.add(NUMERIC_SONGS)
     old_pl = FileBackedPlaylist(self.temp, playlist_fn)
     old_pl.extend(NUMERIC_SONGS)
     pl = XSPFBackedPlaylist.from_playlist(old_pl,
                                           songs_lib=songs_lib,
                                           pl_lib=None)
     expected_filenames = {s("~filename") for s in NUMERIC_SONGS}
     assert {s("~filename") for s in pl.songs} == expected_filenames
예제 #2
0
    def _read_playlists(self, library) -> None:
        print_d(
            f"Reading playlist directory {self.pl_dir} (library: {library})")
        try:
            fns = os.listdir(self.pl_dir)
        except FileNotFoundError as e:
            print_w(
                f"No playlist dir found in {self.pl_dir!r}, creating. ({e})")
            os.mkdir(self.pl_dir)
            fns = []

        # Populate this library by relying on existing signal passing.
        # Weird, but allows keeping the logic in one place
        for fn in fns:
            full_path = os.path.join(self.pl_dir, fn)
            if os.path.isdir(full_path):
                continue
            if HIDDEN_RE.match(fsn2text(fn)):
                print_d(f"Ignoring hidden file {fn!r}")
                continue
            try:
                XSPFBackedPlaylist(self.pl_dir,
                                   fn,
                                   songs_lib=library,
                                   pl_lib=self)
            except TypeError as e:
                # Don't add to library - it's temporary
                legacy = FileBackedPlaylist(self.pl_dir,
                                            fn,
                                            songs_lib=library,
                                            pl_lib=None)
                print_w(f"Converting {fn!r} to XSPF format ({e})")
                XSPFBackedPlaylist.from_playlist(legacy,
                                                 songs_lib=library,
                                                 pl_lib=self)
            except EnvironmentError:
                print_w(f"Invalid Playlist {fn!r}")
예제 #3
0
    def init(klass, library):
        klass.library = library
        model = klass.__lists.get_model()
        for playlist in os.listdir(PLAYLISTS):
            if os.path.isdir(os.path.join(PLAYLISTS, playlist)):
                continue
            try:
                playlist = XSPFBackedPlaylist(PLAYLISTS, playlist, library)
                model.append(row=[playlist])
            except TypeError:
                legacy = FileBackedPlaylist(PLAYLISTS, playlist, library)
                print_w("Converting \"%s\" to XSPF format" % playlist)
                playlist = XSPFBackedPlaylist.from_playlist(legacy, library)
                model.append(row=[playlist])
            except EnvironmentError:
                print_w("Invalid Playlist '%s'" % playlist)

        klass._ids = [
            library.connect('removed', klass.__removed),
            library.connect('added', klass.__added),
            library.connect('changed', klass.__changed),
        ]
        klass.load_pattern()