def _saveas_playlist_cb(widget, name, page, context): exaile = main.exaile() name = dialogs.ask_for_playlist_name(exaile.playlists, "") if name is not None: pl = playlist.Playlist(name, page.playlist[:]) exaile.playlists.save_playlist(pl) page.container.create_tab_from_playlist(pl)
def on_saveas(self): exaile = main.exaile() name = dialogs.ask_for_playlist_name(exaile.gui.main.window, exaile.playlists) if name is not None: pl = playlist.Playlist(name, self.playlist[:]) exaile.playlists.save_playlist(pl) self.plcontainer.create_tab_from_playlist(pl)
def on_saveas(self): exaile = main.exaile() name = dialogs.ask_for_playlist_name( exaile.gui.main.window, exaile.playlists) if name is not None: pl = playlist.Playlist(name, self.playlist[:]) exaile.playlists.save_playlist(pl) self.plcontainer.create_tab_from_playlist(pl)
def add_new_playlist(self, tracks=[], name = None): """ Adds a new playlist to the list of playlists. If name is None or the name conflicts with an existing playlist, the user will be queried for a new name. Returns the name of the new playlist, or None if it was not added. """ do_add_playlist = False if name: if name in self.playlist_manager.playlists: name = dialogs.ask_for_playlist_name( self.get_panel().get_toplevel(), self.playlist_manager, name) else: if tracks: artists = [] composers = [] albums = [] for track in tracks: artist = track.get_tag_display('artist', artist_compilations=False) if artist is not None: artists += [artist] composer = track.get_tag_display('composer', artist_compilations=False) if composer is not None: composers += composer album = track.get_tag_display('album') if album is not None: albums += album artists = list(set(artists))[:3] composers = list(set(composers))[:3] albums = list(set(albums))[:3] if len(artists) > 0: name = artists[0] if len(artists) > 2: # TRANSLATORS: Playlist title suggestion with more # than two values name = _('%(first)s, %(second)s and others') % { 'first': artists[0], 'second': artists[1] } elif len(artists) > 1: # TRANSLATORS: Playlist title suggestion with two values name = _('%(first)s and %(second)s') % { 'first': artists[0], 'second': artists[1] } elif len(composers) > 0: name = composers[0] if len(composers) > 2: # TRANSLATORS: Playlist title suggestion with more # than two values name = _('%(first)s, %(second)s and others') % { 'first': composers[0], 'second': composers[1] } elif len(composers) > 1: # TRANSLATORS: Playlist title suggestion with two values name = _('%(first)s and %(second)s') % { 'first': composers[0], 'second': composers[1] } elif len(albums) > 0: name = albums[0] if len(albums) > 2: # TRANSLATORS: Playlist title suggestion with more # than two values name = _('%(first)s, %(second)s and others') % { 'first': albums[0], 'second': albums[1] } elif len(albums) > 1: # TRANSLATORS: Playlist title suggestion with two values name = _('%(first)s and %(second)s') % { 'first': albums[0], 'second': albums[1] } else: name = '' name = dialogs.ask_for_playlist_name( self.get_panel().get_toplevel(), self.playlist_manager, name) if name is not None: #Create the playlist from all of the tracks new_playlist = playlist.Playlist(name) new_playlist.extend(tracks) # We are adding a completely new playlist with tracks so we save it self.playlist_manager.save_playlist(new_playlist) return name
def add_new_playlist(self, tracks=[], name=None): """ Adds a new playlist to the list of playlists. If name is None or the name conflicts with an existing playlist, the user will be queried for a new name. Returns the name of the new playlist, or None if it was not added. """ if name: if name in self.playlist_manager.playlists: name = dialogs.ask_for_playlist_name( self.get_panel().get_toplevel(), self.playlist_manager, name) else: if tracks: artists = [] composers = [] albums = [] for track in tracks: artist = track.get_tag_display('artist', artist_compilations=False) if artist is not None: artists += [artist] composer = track.get_tag_display('composer', artist_compilations=False) if composer is not None: composers += composer album = track.get_tag_display('album') if album is not None: albums += album artists = list(set(artists))[:3] composers = list(set(composers))[:3] albums = list(set(albums))[:3] if len(artists) > 0: name = artists[0] if len(artists) > 2: # TRANSLATORS: Playlist title suggestion with more # than two values name = _('%(first)s, %(second)s and others') % { 'first': artists[0], 'second': artists[1], } elif len(artists) > 1: # TRANSLATORS: Playlist title suggestion with two values name = _('%(first)s and %(second)s') % { 'first': artists[0], 'second': artists[1], } elif len(composers) > 0: name = composers[0] if len(composers) > 2: # TRANSLATORS: Playlist title suggestion with more # than two values name = _('%(first)s, %(second)s and others') % { 'first': composers[0], 'second': composers[1], } elif len(composers) > 1: # TRANSLATORS: Playlist title suggestion with two values name = _('%(first)s and %(second)s') % { 'first': composers[0], 'second': composers[1], } elif len(albums) > 0: name = albums[0] if len(albums) > 2: # TRANSLATORS: Playlist title suggestion with more # than two values name = _('%(first)s, %(second)s and others') % { 'first': albums[0], 'second': albums[1], } elif len(albums) > 1: # TRANSLATORS: Playlist title suggestion with two values name = _('%(first)s and %(second)s') % { 'first': albums[0], 'second': albums[1], } else: name = '' name = dialogs.ask_for_playlist_name( self.get_panel().get_toplevel(), self.playlist_manager, name) if name is not None: # Create the playlist from all of the tracks new_playlist = xl_playlist.Playlist(name) new_playlist.extend(tracks) # We are adding a completely new playlist with tracks so we save it self.playlist_manager.save_playlist(new_playlist) return name