def load(): items = [] is_compilation = artist_ids and artist_ids[0] == Type.COMPILATIONS if genre_ids and genre_ids[0] == Type.ALL: if is_compilation or\ Lp().settings.get_value("show-compilations"): items = Lp().albums.get_compilation_ids() if not is_compilation: items += Lp().albums.get_ids() elif genre_ids and genre_ids[0] == Type.POPULARS: items = Lp().albums.get_rated() count = 100 - len(items) for album in Lp().albums.get_populars(count): if album not in items: items.append(album) elif genre_ids and genre_ids[0] == Type.LOVED: items = Lp().albums.get_loves() elif genre_ids and genre_ids[0] == Type.RECENTS: items = Lp().albums.get_recents() elif genre_ids and genre_ids[0] == Type.NEVER: items = Lp().albums.get_never_listened_to() elif genre_ids and genre_ids[0] == Type.RANDOMS: items = Lp().albums.get_randoms() else: if is_compilation or\ Lp().settings.get_value("show-compilations"): items = Lp().albums.get_compilation_ids(genre_ids) if not is_compilation: items += Lp().albums.get_ids([], genre_ids) return items
def load(): items = [] is_compilation = artist_ids and artist_ids[0] == Type.COMPILATIONS if genre_ids and genre_ids[0] == Type.ALL: if is_compilation or\ Lp().settings.get_value("show-compilations"): items = Lp().albums.get_compilation_ids() if not is_compilation: items += Lp().albums.get_ids() elif genre_ids and genre_ids[0] == Type.POPULARS: items = Lp().albums.get_rated() count = 100 - len(items) for album in Lp().albums.get_populars(count): if album not in items: items.append(album) elif genre_ids and genre_ids[0] == Type.LOVED: items = Lp().albums.get_loves() elif genre_ids and genre_ids[0] == Type.RECENTS: items = Lp().albums.get_recents() elif genre_ids and genre_ids[0] == Type.RANDOMS: items = Lp().albums.get_randoms() elif genre_ids and genre_ids[0] in [Type.SPOTIFY, Type.LASTFM]: items = Lp().tracks.get_charts_ids(genre_ids) elif genre_ids and genre_ids[0] == Type.ITUNES: items = Lp().albums.get_charts_ids(genre_ids) elif artist_ids and artist_ids[0] == Type.CHARTS: items = Lp().albums.get_charts_ids(genre_ids) else: if is_compilation or\ Lp().settings.get_value("show-compilations"): items = Lp().albums.get_compilation_ids(genre_ids) if not is_compilation: items += Lp().albums.get_ids([], genre_ids) return items
def load(): items = [] is_compilation = artist_ids and artist_ids[0] == Type.COMPILATIONS if genre_ids and genre_ids[0] == Type.ALL: if is_compilation or\ Lp().settings.get_value('show-compilations'): items = Lp().albums.get_compilation_ids() if not is_compilation: items += Lp().albums.get_ids() elif genre_ids and genre_ids[0] == Type.POPULARS: items = Lp().albums.get_rated() count = 100 - len(items) for album in Lp().albums.get_populars(count): if album not in items: items.append(album) elif genre_ids and genre_ids[0] == Type.LOVED: items = Lp().albums.get_loves() elif genre_ids and genre_ids[0] == Type.RECENTS: items = Lp().albums.get_recents() elif genre_ids and genre_ids[0] == Type.RANDOMS: items = Lp().albums.get_randoms() elif genre_ids and genre_ids[0] in [Type.SPOTIFY, Type.LASTFM]: items = Lp().tracks.get_charts_ids(genre_ids) elif genre_ids and genre_ids[0] == Type.ITUNES: items = Lp().albums.get_charts_ids(genre_ids) elif artist_ids and artist_ids[0] == Type.CHARTS: items = Lp().albums.get_charts_ids(genre_ids) else: if is_compilation or\ Lp().settings.get_value('show-compilations'): items = Lp().albums.get_compilation_ids(genre_ids) if not is_compilation: items += Lp().albums.get_ids([], genre_ids) return items
def __get_albums(self): """ Get albums @return album ids as [int] """ if self.__track.album.artist_ids[0] == Type.COMPILATIONS: albums = [self.__track.album.id] else: albums = Lp().artists.get_albums(self.__track.album.artist_ids) # Charts album playing if Lp().player.current_track.album.id not in albums: albums.append(Lp().player.current_track.album.id) return albums
def get_party_ids(self): """ Return party ids @return [ids as int] """ party_settings = Lp().settings.get_value("party-ids") ids = [] genre_ids = Lp().genres.get_ids() genre_ids.append(Type.POPULARS) genre_ids.append(Type.RECENTS) for setting in party_settings: if isinstance(setting, int) and setting in genre_ids: ids.append(setting) return ids
def get_party_ids(self): """ Return party ids @return [ids as int] """ party_settings = Lp().settings.get_value('party-ids') ids = [] genre_ids = Lp().genres.get_ids() genre_ids.append(Type.POPULARS) genre_ids.append(Type.RECENTS) for setting in party_settings: if isinstance(setting, int) and\ setting in genre_ids: ids.append(setting) return ids
def _add_artist(self, scanner, artist_id, album_id): """ Add artist to artist list @param scanner as CollectionScanner @param artist id as int @param album id as int """ artist_name = Lp().artists.get_name(artist_id) if self._show_genres: genre_ids = Lp().albums.get_genre_ids(album_id) genre_ids.append(Type.ALL) if self._list_one.get_selected_id() in genre_ids: self._list_two.add_value((artist_id, artist_name)) else: self._list_one.add_value((artist_id, artist_name))
def _party_switch_state(self, widget, state, genre_id): """ Update party ids when use change a switch in dialog @param widget as unused, state as widget state, genre id as int """ ids = Lp().player.get_party_ids() if state: try: ids.append(genre_id) except: pass else: try: ids.remove(genre_id) except: pass Lp().settings.set_value('party-ids', GLib.Variant('ai', ids))
def __on_switch_state_set(self, widget, state, genre_id): """ Update party ids when use change a switch in dialog @param widget as Gtk.Switch @param state as bool, genre id as int """ ids = Lp().player.get_party_ids() if state: try: ids.append(genre_id) except: pass else: try: ids.remove(genre_id) except: pass Lp().settings.set_value("party-ids", GLib.Variant("ai", ids)) Lp().player.set_party_ids() Lp().player.set_next()
def load(): track_ids = [] for playlist_id in playlist_ids: if playlist_id == Type.POPULARS: tracks = Lp().tracks.get_rated() for track in Lp().tracks.get_populars(): tracks.append(track) elif playlist_id == Type.RECENTS: tracks = Lp().tracks.get_recently_listened_to() elif playlist_id == Type.NEVER: tracks = Lp().tracks.get_never_listened_to() elif playlist_id == Type.RANDOMS: tracks = Lp().tracks.get_randoms() elif playlist_id == Type.LOVED: tracks = Lp().playlists.get_track_ids_sorted(playlist_id) else: tracks = Lp().playlists.get_track_ids(playlist_id) for track_id in tracks: if track_id not in track_ids: track_ids.append(track_id) return track_ids
def _playlistid(self, cmd_args): """ Send informations about current playlist @param playlistid @param args as str @return msg as str """ msg = "" try: track_id = int(self._get_args(cmd_args)) msg += self._string_for_track_id(track_id) except: currents = Lp().playlists.get_tracks_ids(Type.MPD) if Lp().player.is_party(): currents.insert(0, Lp().player.current_track.id) if Lp().player.prev_track.id is not None: currents.insert(0, Lp().player.prev_track.id) if Lp().player.next_track.id is not None: currents.append(Lp().player.next_track.id) for track_id in currents: msg += self._string_for_track_id(track_id) return msg
def _playlistinfo(self, cmd_args): """ Send informations about current playlist @syntax playlistinfo [[pos]|[start:end]] @param playlistinfo @param args as str @return msg as str """ msg = "" try: arg = self._get_args(cmd_args)[0] except: arg = None start = end = pos = None if arg is not None: # Check for a range try: splited = arg.split(':') start = int(splited[0]) end = int(splited[1]) except: start = end = None pos = int(arg) currents = Lp().playlists.get_tracks_ids(Type.MPD) if Lp().player.is_party(): currents.insert(0, Lp().player.current_track.id) if Lp().player.prev_track.id is not None: currents.insert(0, Lp().player.prev_track.id) if Lp().player.next_track.id is not None: currents.append(Lp().player.next_track.id) i = 0 for track_id in currents: if (start is not None and start <= i <= end) or\ (pos is not None and pos == i) or\ (start == end == pos is None): msg += self._string_for_track_id(track_id) i += 1 return msg
def __on_artist_updated(self, scanner, artist_id, album_id, add): """ Add artist to artist list @param scanner as CollectionScanner @param artist id as int @param album id as int @param add as bool """ artist_name = Lp().artists.get_name(artist_id) if self.__show_genres: genre_ids = Lp().albums.get_genre_ids(album_id) genre_ids.append(Type.ALL) for i in self.__list_one.get_selected_ids(): if i in genre_ids: if add: self.__list_two.add_value((artist_id, artist_name)) else: self.__list_two.remove_value(artist_id) else: if add: self.__list_one.add_value((artist_id, artist_name)) else: self.__list_one.remove_value(artist_id)
class Player(BinPlayer, QueuePlayer, UserPlaylistPlayer, RadioPlayer, LinearPlayer, ShufflePlayer, ExternalsPlayer): """ Player object used to manage playback and playlists """ def __init__(self): """ Init player """ BinPlayer.__init__(self) QueuePlayer.__init__(self) LinearPlayer.__init__(self) ShufflePlayer.__init__(self) UserPlaylistPlayer.__init__(self) RadioPlayer.__init__(self) ExternalsPlayer.__init__(self) self.update_crossfading() def prev(self): """ Play previous track """ if self.prev_track.id is not None: self.load(self.prev_track, False) def next(self): """ Play next track """ if self.next_track.id is not None: self.load(self.next_track, False) def load(self, track, notify=True): """ Stop current track, load track id and play it @param track as Track @param notify as bool """ if track.id == Type.RADIOS: if not Lp().scanner.is_locked(): Lp().window.pulse(False) Lp().window.pulse(True) RadioPlayer.load(self, track) else: BinPlayer.load(self, track, notify) def play_album(self, album): """ Play album @param album as Album """ # Empty user playlist self._user_playlist = [] Lp().player.load(album.tracks[0]) if not Lp().player.is_party(): self._albums = [album.id] self.context.genre_ids = [] def set_albums(self, track_id, artist_ids, genre_ids): """ Set album list (for next/prev) @param track id as int @param artist id as int @param genre id as int """ # Invalid track if track_id is None: return album = Track(track_id).album self._albums = [] ShufflePlayer.reset_history(self) # We are not playing a user playlist anymore self._user_playlist = [] self._user_playlist_id = None # We are in all artists if (genre_ids and genre_ids[0] == Type.ALL) or\ (artist_ids and artist_ids[0] == Type.ALL): self._albums = Lp().albums.get_compilations() self._albums += Lp().albums.get_ids() # We are in populars view, add popular albums elif genre_ids and genre_ids[0] == Type.POPULARS: if self._shuffle in [Shuffle.TRACKS_ARTIST, Shuffle.ALBUMS_ARTIST]: self._albums = [] self.next_track = Track() for album_id in Lp().albums.get_populars(): if Lp().albums.get_artist_id(album_id) == \ album.artist_id: self._albums.append(album_id) else: self._albums = Lp().albums.get_populars() # We are in recents view, add recent albums elif genre_ids and genre_ids[0] == Type.RECENTS: self._albums = Lp().albums.get_recents() # We are in randoms view, add random albums elif genre_ids and genre_ids[0] == Type.RANDOMS: self._albums = Lp().albums.get_cached_randoms() # We are in compilation view without genre elif genre_ids and genre_ids[0] == Type.COMPILATIONS: self._albums = Lp().albums.get_compilations() # Random tracks/albums for artist elif self._shuffle in [Shuffle.TRACKS_ARTIST, Shuffle.ALBUMS_ARTIST]: self._albums = Lp().albums.get_ids([album.artist_id], genre_ids) # Add all albums for genre else: if not artist_ids: self._albums = Lp().albums.get_compilations(genre_ids) self._albums += Lp().albums.get_ids(artist_ids, genre_ids) album.set_genre(genre_ids) if track_id in album.tracks_ids: self.context.artist_ids = artist_ids self.context.genre_ids = genre_ids # Shuffle album list if needed self._shuffle_albums() else: # Error self.stop() def clear_albums(self): """ Clear all albums """ self._albums = [] def get_current_artist(self): """ Get current artist @return artist as string """ artist_id = self.current_track.album_artist_id if artist_id == Type.COMPILATIONS: artist = self.current_track.artist else: artist = self.current_track.album_artist return artist def restore_state(self): """ Restore player state """ track_id = Lp().settings.get_value('track-id').get_int32() if Lp().settings.get_value('save-state') and track_id > 0: path = Lp().tracks.get_path(track_id) if path != "": self._load_track(Track(track_id)) self.set_albums(track_id, [Type.ALL], [Type.ALL]) self.set_next() self.set_prev() self.emit('current-changed') else: print("Player::restore_state(): track missing") def set_party(self, party): """ Set party mode on if party is True Play a new random track if not already playing @param party as bool """ ShufflePlayer.set_party(self, party) self.set_next() self.set_prev() self.update_crossfading() def set_prev(self): """ Set previous track """ # Look at externals self.prev_track = ExternalsPlayer.prev(self) # Look at radio if self.prev_track.id is None: self.prev_track = RadioPlayer.prev(self) # Look at user playlist then if self.prev_track.id is None: self.prev_track = UserPlaylistPlayer.prev(self) # Look at shuffle if self.prev_track.id is None: self.prev_track = ShufflePlayer.prev(self) # Get a linear track then if self.prev_track.id is None: self.prev_track = LinearPlayer.prev(self) self.emit('prev-changed') def set_next(self): """ Play next track @param sql as sqlite cursor """ # Look at externals self.next_track = ExternalsPlayer.next(self) # Look at radio if self.next_track.id is None: self.next_track = RadioPlayer.next(self) # Look first at user queue if self.next_track.id is None: self.next_track = QueuePlayer.next(self) if self.next_track.id is not None: self.context.next_track = LinearPlayer.next(self) # Look at user playlist then if self.next_track.id is None: self.next_track = UserPlaylistPlayer.next(self) # Get a random album/track then if self.next_track.id is None: self.next_track = ShufflePlayer.next(self) # Get a linear track then if self.next_track.id is None: if self.context.next_track is not None: self.next_track = self.context.next_track self.context.next_track = None else: self.next_track = LinearPlayer.next(self) self.emit('next-changed') def update_crossfading(self): """ Calculate if crossfading is needed """ mix = Lp().settings.get_value('mix') party_mix = Lp().settings.get_value('party-mix') self._crossfading = (mix and not party_mix) or\ (party_mix and self._is_party) ####################### # PRIVATE # ####################### def _on_stream_start(self, bus, message): """ On stream start, set next and previous track """ if not Lp().scanner.is_locked(): Lp().window.pulse(False) if self.current_track.id >= 0: ShufflePlayer._on_stream_start(self, bus, message) if self._queue and self.current_track.id == self._queue[0]: self._queue.pop(0) self.emit("queue-changed") self.set_next() self.set_prev() BinPlayer._on_stream_start(self, bus, message)
class Player(BinPlayer, QueuePlayer, UserPlaylistPlayer, RadioPlayer, LinearPlayer, ShufflePlayer, ExternalsPlayer): """ Player object used to manage playback and playlists """ def __init__(self): """ Create all objects """ BinPlayer.__init__(self) QueuePlayer.__init__(self) LinearPlayer.__init__(self) ShufflePlayer.__init__(self) UserPlaylistPlayer.__init__(self) RadioPlayer.__init__(self) ExternalsPlayer.__init__(self) def prev(self): """ Play previous track """ if self.prev_track.id is not None: self.load(self.prev_track, False) def next(self): """ Play next track """ if self.next_track.id is not None: self.load(self.next_track, False) def load(self, track, notify=True): """ Stop current track, load track id and play it @param track as Track @param notify as bool """ if track.id == Type.RADIOS: if not Lp().scanner.is_locked(): Lp().window.pulse(False) Lp().window.pulse(True) RadioPlayer.load(self, track) else: BinPlayer.load(self, track, notify) def play_album(self, album): """ Play album @param album as Album """ # Empty user playlist self._user_playlist = [] Lp().player.load(album.tracks[0]) if not Lp().player.is_party(): self._albums = [album.id] self.context.genre_ids = [] def set_albums(self, track_id, artist_ids, genre_ids): """ Set album list (for next/prev) @param track id as int @param artist id as int @param genre id as int """ # Invalid track if track_id is None: return album = Track(track_id).album self._albums = [] ShufflePlayer.reset_history(self) # We are not playing a user playlist anymore self._user_playlist = [] self._user_playlist_id = None # We are in all artists if (genre_ids and genre_ids[0] == Type.ALL) or\ (artist_ids and artist_ids[0] == Type.ALL): self._albums = Lp().albums.get_compilations() self._albums += Lp().albums.get_ids() # We are in populars view, add popular albums elif genre_ids and genre_ids[0] == Type.POPULARS: if self._shuffle in [Shuffle.TRACKS_ARTIST, Shuffle.ALBUMS_ARTIST]: self._albums = [] for album_id in Lp().albums.get_populars(): if Lp().albums.get_artist_id(album_id) in artist_ids: self._albums.append(album_id) else: self._albums = Lp().albums.get_populars() # We are in recents view, add recent albums elif genre_ids and genre_ids[0] == Type.RECENTS: self._albums = Lp().albums.get_recents() # We are in randoms view, add random albums elif genre_ids and genre_ids[0] == Type.RANDOMS: self._albums = Lp().albums.get_cached_randoms() # We are in compilation view without genre elif genre_ids and genre_ids[0] == Type.COMPILATIONS: self._albums = Lp().albums.get_compilations() # Random tracks/albums for artist elif self._shuffle in [Shuffle.TRACKS_ARTIST, Shuffle.ALBUMS_ARTIST]: self._albums = Lp().albums.get_ids([album.artist_id], genre_ids) # Add all albums for genre else: if not artist_ids: self._albums = Lp().albums.get_compilations(genre_ids) self._albums += Lp().albums.get_ids(artist_ids, genre_ids) album.set_genre(genre_ids) if track_id in album.tracks_ids: self.context.artist_ids = artist_ids self.context.genre_ids = genre_ids # Shuffle album list if needed self._shuffle_albums() else: # Error self.stop() def clear_albums(self): """ Clear all albums """ self._albums = [] def get_current_artist(self): """ Get current artist @return artist as string """ artist_id = self.current_track.album_artist_id if artist_id == Type.COMPILATIONS: artist = self.current_track.artist else: artist = self.current_track.album_artist return artist def restore_state(self): """ Restore player state """ track_id = Lp().settings.get_value('track-id').get_int32() if Lp().settings.get_value('save-state') and track_id > 0: path = Lp().tracks.get_path(track_id) if path != "": self._load_track(Track(track_id)) self.set_albums(track_id, [Type.ALL], [Type.ALL]) self.set_next() self.set_prev() self.emit('current-changed') else: print("Player::restore_state(): track missing") def set_party(self, party): """ Set party mode on if party is True Play a new random track if not already playing @param party as bool """ ShufflePlayer.set_party(self, party) self.set_next() self.set_prev() if self.is_playing(): self.emit('next-changed') def set_prev(self): """ Set previous track """ # Look at externals self.prev_track = ExternalsPlayer.prev(self) # Look at radio if self.prev_track.id is None: self.prev_track = RadioPlayer.prev(self) # Look at user playlist then if self.prev_track.id is None: self.prev_track = UserPlaylistPlayer.prev(self) # Look at shuffle if self.prev_track.id is None: self.prev_track = ShufflePlayer.prev(self) # Get a linear track then if self.prev_track.id is None: self.prev_track = LinearPlayer.prev(self) def set_next(self): """ Play next track @param sql as sqlite cursor """ # Look at externals self.next_track = ExternalsPlayer.next(self) # Look at radio if self.next_track.id is None: self.next_track = RadioPlayer.next(self) # Look first at user queue if self.next_track.id is None: self.next_track = QueuePlayer.next(self) if self.next_track.id is not None: self.context.next_track = LinearPlayer.next(self) # Look at user playlist then if self.next_track.id is None: self.next_track = UserPlaylistPlayer.next(self) # Get a random album/track then if self.next_track.id is None: self.next_track = ShufflePlayer.next(self) # Get a linear track then if self.next_track.id is None: if self.context.next_track is not None: self.next_track = self.context.next_track self.context.next_track = None else: self.next_track = LinearPlayer.next(self) self.emit('next-changed') ####################### # PRIVATE # ####################### def _on_stream_start(self, bus, message): """ On stream start, set next and previous track """ if not Lp().scanner.is_locked(): Lp().window.pulse(False) if self.current_track.id >= 0: ShufflePlayer._on_stream_start(self, bus, message) if self._queue and self.current_track.id == self._queue[0]: self._queue.pop(0) self.emit("queue-changed") self.set_next() self.set_prev() BinPlayer._on_stream_start(self, bus, message)