def __init__(self, player): Playlist.__init__( self, _('History') ) # catch the history event.add_ui_callback( self.__on_playback_track_start, 'playback_track_start', player ) if player.is_paused() or player.is_playing(): self.__on_playback_track_start( 'playback_track_start', player, player.current )
def __on_playback_track_start(self, event, player, track): '''Every time a track plays, add it to the playlist''' maxlen = int(settings.get_option( 'plugin/history/history_length', history_preferences.history_length_default )) if maxlen < 0: maxlen = 0 settings.set_option( 'plugin/history/history_length', 0 ) if len(self) >= maxlen-1: Playlist.__delitem__( self, slice(0, max(0, len(self)-(maxlen-1)), None) ) Playlist.__setitem__( self, slice(len(self),len(self),None), [track] )
def _migrate_playlists(db, newdb, playlists): p_rows = db.select('SELECT name, id, type FROM playlists ORDER BY name') for p_row in p_rows: if p_row[2]: continue pl = Playlist(p_row[0]) rows = db.select('SELECT paths.name FROM playlist_items,paths WHERE ' 'playlist_items.path=paths.id AND playlist=?', (p_row[1],)) locs = ['file://' + row[0] for row in rows] tracks = newdb.get_tracks_by_locs(locs) if tracks: pl.add_tracks(tracks, add_duplicates=False) playlists.save_playlist(pl) playlists.save_order()
def create_new_playlist(self): """ Create a new tab containing a blank playlist. The tab will be automatically given a unique name. """ seen = [] default_playlist_name = _('Playlist %d') # Split into 'Playlist ' and '' default_name_parts = default_playlist_name.split('%d') for n in range(self.get_n_pages()): page = self.get_nth_page(n) name = page.get_page_name() name_parts = [ # 'Playlist 99' => 'Playlist ' name[0:len(default_name_parts[0])], # 'Playlist 99' => '' name[len(name) - len(default_name_parts[1]):] ] # Playlist name matches our format if name_parts == default_name_parts: # Extract possible number between name parts number = name[len(name_parts[0]):len(name) - len(name_parts[1])] try: number = int(number) except ValueError: pass else: seen += [number] seen.sort() n = 1 while True: if n not in seen: break n += 1 playlist = Playlist(default_playlist_name % n) return self.create_tab_from_playlist(playlist)
def clear(self): Playlist.__delitem__(self, slice(None, None, None))
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 = 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 clear(self): Playlist.__delitem__( self, slice(None, None, None) )