Beispiel #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
Beispiel #2
0
    def init(klass, library):
        model = klass.__lists.get_model()
        for playlist in os.listdir(PLAYLISTS):
            try:
                playlist = FileBackedPlaylist(PLAYLISTS,
                      FileBackedPlaylist.unquote(playlist), library=library)
                model.append(row=[playlist])
            except EnvironmentError:
                print_w("Invalid Playlist '%s'" % playlist)
                pass

        klass._ids = [
            library.connect('removed', klass.__removed),
            library.connect('added', klass.__added),
            library.connect('changed', klass.__changed),
        ]
        klass.load_pattern()
 def create_playlist_file(self, pl_dir) -> None:
     # Won't exist, we haven't started the library yet
     temp_path = Path(_TEMP_DIR).absolute()
     parents = {path.absolute() for path in pl_dir.parents}
     assert temp_path in parents or os.environ.get('CI',
                                                   False), "Dangerous test!"
     shutil.rmtree(pl_dir, ignore_errors=True)
     os.makedirs(pl_dir)
     fn = FileBackedPlaylist.filename_for(PL_NAME)
     # No PL library given - rely on import
     self.pl = pl = FileBackedPlaylist(str(pl_dir), fn, self.underlying,
                                       None)
     pl.extend(list(sorted(self.underlying))[-3:])
     assert len(pl) == 3, "Should have only the three songs just added"
     diff = set(self.underlying) - set(pl)
     assert all(song in self.underlying
                for song in pl), f"Missing from lib: {diff}"
     pl.finalize()
     pl.write()
    def test_import(self):
        pl_name = u"_€3 œufs à Noël"
        pl = FileBackedPlaylist(_TEMP_DIR, pl_name, None)
        pl.extend(SONGS)
        pl.write()
        new_fn = os.path.splitext(text2fsn(pl.name))[0] + '.m3u'
        new_path = os.path.join(pl.dir, new_fn)
        os.rename(pl.filename, new_path)
        added = self.bar._import_playlists([new_path], self.lib)
        self.failUnlessEqual(added, 1, msg="Failed to add '%s'" % new_path)
        os.unlink(new_path)
        pls = self.bar.playlists()
        self.failUnlessEqual(len(pls), 3)
        # Leading underscore makes it always the last entry
        imported = pls[-1]
        self.failUnlessEqual(imported.name, pl_name)

        def fns(songs):
            return [song('~filename') for song in songs]

        self.failUnlessEqual(fns(imported.songs), fns(pl.songs))
Beispiel #5
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()
Beispiel #6
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}")
 def pl(self, name, lib=None):
     return FileBackedPlaylist(self.temp, name, lib)