Пример #1
0
 def test_v1_load_non_compliant_xspf(self):
     """See #3983"""
     songs_lib = FileLibrary()
     test_filename = ("/music/Funk & Disco/"
                      "Average White Band - Pickin' Up The Pieces/"
                      "Average White Band - Your Love Is a Miracle.flac")
     songs_lib.add([AudioFile({"~filename": test_filename})])
     playlist_fn = "non-compliant.xspf"
     path = str(Path(__file__).parent / "data")
     pl = XSPFBackedPlaylist(path,
                             playlist_fn,
                             songs_lib=songs_lib,
                             pl_lib=None)
     assert {s("~filename") for s in pl.songs}, set(test_filename)
Пример #2
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()
Пример #3
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}")