def setUp(self): # Testing locally is VERY dangerous without this... self.assertTrue(_TEMP_DIR in PLAYLISTS or os.name == "nt", msg="Failing, don't want to delete %s" % PLAYLISTS) try: shutil.rmtree(PLAYLISTS) except OSError: pass mkdir(PLAYLISTS) self.lib = quodlibet.browsers.playlists.library = SongLibrary() self.lib.librarian = SongLibrarian() all_songs = SONGS + [self.ANOTHER_SONG] for af in all_songs: af.sanitize() self.lib.add(all_songs) self.big = pl = Playlist.new(PLAYLISTS, "Big", self.lib) pl.extend(SONGS) pl.write() self.small = pl = Playlist.new(PLAYLISTS, "Small", self.lib) pl.extend([self.ANOTHER_SONG]) pl.write() PlaylistsBrowser.init(self.lib) self.bar = PlaylistsBrowser(self.lib) self.bar.connect('songs-selected', self._expected) self.bar._select_playlist(self.bar.playlists()[0]) self.expected = None
def setUp(self): try: shutil.rmtree(PLAYLISTS) except OSError: pass mkdir(PLAYLISTS) self.lib = quodlibet.browsers.playlists.library = SongLibrary() self.lib.librarian = SongLibrarian() all_songs = SONGS + [self.ANOTHER_SONG] for af in all_songs: af.sanitize() self.lib.add(all_songs) pl = Playlist.new(PLAYLISTS, "Big", self.lib) pl.extend(SONGS) pl.write() pl = Playlist.new(PLAYLISTS, "Small", self.lib) pl.extend([self.ANOTHER_SONG]) pl.write() PlaylistsBrowser.init(self.lib) self.bar = PlaylistsBrowser(self.lib) self.bar.connect('songs-selected', self._expected) self.bar._select_playlist(self.bar.playlists()[0]) self.expected = None
def test_make_dup(self): p1 = Playlist.new(self.temp, "Does not exist") p2 = Playlist.new(self.temp, "Does not exist") self.failUnlessEqual(p1.name, "Does not exist") self.failUnless(p2.name.startswith("Does not exist")) self.failIfEqual(p1.name, p2.name) p1.delete() p2.delete()
def __parse_playlist(name, plfilename, files, library): playlist = Playlist.new(PLAYLISTS, name, library=library) songs = [] win = WaitLoadWindow(None, len(files), _("Importing playlist.\n\n%(current)d/%(total)d songs added.")) win.show() for i, filename in enumerate(files): try: uri = URI(filename) except ValueError: if os.name == "nt": filename = filename.decode("utf-8", "replace") # Plain filename. filename = os.path.realpath(os.path.join(os.path.dirname(plfilename), filename)) if library and filename in library: songs.append(library[filename]) else: songs.append(formats.MusicFile(filename)) else: if uri.scheme == "file": # URI-encoded local filename. filename = os.path.realpath(os.path.join(os.path.dirname(plfilename), uri.filename)) if library and filename in library: songs.append(library[filename]) else: songs.append(formats.MusicFile(filename)) else: # Who knows! Hand it off to GStreamer. songs.append(formats.remote.RemoteFile(uri)) if win.step(): break win.destroy() playlist.extend(filter(None, songs)) return playlist
def __parse_playlist(name, plfilename, files, library): playlist = Playlist.new(PLAYLISTS, name, library=library) songs = [] win = WaitLoadWindow( None, len(files), _("Importing playlist.\n\n%(current)d/%(total)d songs added.")) win.show() for i, filename in enumerate(files): try: uri = URI(filename) except ValueError: # Plain filename. filename = os.path.realpath( os.path.join(os.path.dirname(plfilename), filename)) if library and filename in library: songs.append(library[filename]) else: songs.append(formats.MusicFile(filename)) else: if uri.scheme == "file": # URI-encoded local filename. filename = os.path.realpath( os.path.join(os.path.dirname(plfilename), uri.filename)) if library and filename in library: songs.append(library[filename]) else: songs.append(formats.MusicFile(filename)) else: # Who knows! Hand it off to GStreamer. songs.append(formats.remote.RemoteFile(uri)) if win.step(): break win.destroy() playlist.extend(filter(None, songs)) return playlist
def setUp(self): quodlibet.config.init() self.lib = quodlibet.browsers.search.library = FileLibrary() quodlibet.browsers.search.library.librarian = SongLibrarian() for af in self.SONGS: af.sanitize() self.lib.add(self.SONGS) self._dir = mkdtemp() self.pl = Playlist.new(self._dir, "Foobar", self.lib) self.pl.extend(self.SONGS)
def __add_to_new_playlist(songs, parent): if len(songs) == 1: title = songs[0].comma("title") else: title = ngettext("%(title)s and %(count)d more", "%(title)s and %(count)d more", len(songs) - 1) % { 'title': songs[0].comma("title"), 'count': len(songs) - 1 } title = GetPlaylistName(qltk.get_top_parent(parent)).run(title) if title is None: return playlist = Playlist.new(PLAYLISTS, title) PlaylistMenu.__add_songs_to_playlist(playlist, songs)
def __add_to_playlist(playlist, songs, parent): if playlist is None: if len(songs) == 1: title = songs[0].comma("title") else: title = ngettext( "%(title)s and %(count)d more", "%(title)s and %(count)d more", len(songs) - 1) % ( {'title': songs[0].comma("title"), 'count': len(songs) - 1}) title = GetPlaylistName(qltk.get_top_parent(parent)).run(title) if title is None: return playlist = Playlist.new(PLAYLISTS, title) playlist.extend(songs) Playlists.changed(playlist)
def _on_new_playlist_activate(self, item, songs): parent = get_menu_item_top_parent(item) if len(songs) == 1: title = songs[0].comma("title") else: title = ngettext("%(title)s and %(count)d more", "%(title)s and %(count)d more", len(songs) - 1) % { 'title': songs[0].comma("title"), 'count': len(songs) - 1 } title = GetPlaylistName(qltk.get_top_parent(parent)).run(title) if title is None: return playlist = Playlist.new(PLAYLISTS, title) playlist.extend(songs) PlaylistsBrowser.changed(playlist)
def _on_new_playlist_activate(self, item, songs): parent = get_menu_item_top_parent(item) if len(songs) == 1: title = songs[0].comma("title") else: title = ngettext( "%(title)s and %(count)d more", "%(title)s and %(count)d more", len(songs) - 1) % { 'title': songs[0].comma("title"), 'count': len(songs) - 1 } title = GetPlaylistName(qltk.get_top_parent(parent)).run(title) if title is None: return playlist = Playlist.new(PLAYLISTS, title) playlist.extend(songs) PlaylistsBrowser.changed(playlist)
def test_rename_nothing(self): p1 = Playlist.new(self.temp, "Foobar") self.failUnlessRaises(ValueError, p1.rename, "") p1.delete()
def test_make(self): p1 = Playlist.new(self.temp, "Does not exist") self.failUnlessEqual(0, len(p1)) self.failUnlessEqual(p1.name, "Does not exist") p1.delete()
def test_rename_working(self): p1 = Playlist.new(self.temp, "Foobar") p1.rename("Foo Quuxly") self.failUnlessEqual(p1.name, "Foo Quuxly") p1.delete()
def test_remove_no_lib(self): pl = Playlist.new(self._dir, "Foobar") pl.extend(self.SONGS) self.assertTrue(len(pl)) pl.remove_songs(self.SONGS, False) self.assertFalse(len(pl))
def __new_playlist(self, activator): playlist = Playlist.new(PLAYLISTS) self.__lists.get_model().append(row=[playlist]) self.__select_playlist(playlist)
def test_rename_dup(self): p1 = Playlist.new(self.temp, "Foobar") p2 = Playlist.new(self.temp, "Crazy") self.failUnlessRaises(ValueError, p2.rename, "Foobar") p1.delete() p2.delete()
def _create_temp_playlist_with(cls, name, songs): pl = Playlist.new(PLAYLISTS, name, cls.lib) pl.extend(songs) pl.write()