def activate_child(self): """ Activated typeahead row """ def reset_party_mode(): if App().player.is_party: App().lookup_action("party").change_state( GLib.Variant("b", False)) try: # Search typeahead child typeahead_child = None for child in self.filtered: style_context = child.get_style_context() if style_context.has_class("typeahead"): typeahead_child = child break if typeahead_child is None: return from lollypop.view_current_albums import CurrentAlbumsView from lollypop.view_playlists import PlaylistsView # Play child without reseting player if isinstance(self, CurrentAlbumsView): if hasattr(typeahead_child, "album"): album = typeahead_child.album if album.tracks: track = album.tracks[0] App().player.load(track) elif hasattr(typeahead_child, "track"): App().player.load(typeahead_child.track) # Play playlist elif isinstance(self, PlaylistsView): reset_party_mode() tracks = [] for album_row in self.view.children: for track in album_row.album.tracks: tracks.append(track) if tracks: albums = tracks_to_albums(tracks) if hasattr(typeahead_child, "album"): if typeahead_child.album.tracks: App().player.play_track_for_albums( typeahead_child.album.tracks[0], albums) elif hasattr(typeahead_child, "track"): App().player.play_track_for_albums( typeahead_child.track, albums) elif hasattr(typeahead_child, "data"): reset_party_mode() typeahead_child.activate() elif hasattr(typeahead_child, "track"): reset_party_mode() track = typeahead_child.track App().player.add_album(track.album) App().player.load(track.album.get_track(track.id)) App().window.container.type_ahead.entry.set_text("") except Exception as e: Logger.error("View::activate_child: %s" % e)
def play_radio_from_populars(self, artist_ids): """ Play a radio from artists popular tracks @param artist_ids as [int] """ track_ids = App().tracks.get_populars(artist_ids, StorageType.ALL, False, 100) shuffle(track_ids) albums = tracks_to_albums([Track(track_id) for track_id in track_ids]) App().player.play_albums(albums)
def play_radio_from_loved(self, artist_ids): """ Play a radio from artists loved tracks @param artist_ids as [int] """ track_ids = App().tracks.get_loved_track_ids(artist_ids, StorageType.ALL) shuffle(track_ids) albums = tracks_to_albums([Track(track_id) for track_id in track_ids]) App().player.play_albums(albums)
def __get_albums(self, playlist_id): """ Get albums for playlist_id @parma playlist_id as int """ if App().playlists.get_smart(playlist_id): request = App().playlists.get_smart_sql(playlist_id) # We need to inject skipped/storage_type storage_type = get_default_storage_type() split = request.split("ORDER BY") split[0] += " AND loved != %s" % Type.NONE split[0] += " AND tracks.storage_type&%s " % storage_type track_ids = App().db.execute("ORDER BY".join(split)) albums = tracks_to_albums( [Track(track_id) for track_id in track_ids]) else: tracks = App().playlists.get_tracks(playlist_id) albums = tracks_to_albums(tracks) return albums
def load(): request = App().playlists.get_smart_sql(self.__playlist_id) # We need to inject skipped/storage_type storage_type = get_default_storage_type() split = request.split("ORDER BY") split[0] += " AND tracks.loved != %s" % Type.NONE split[0] += " AND tracks.storage_type&%s " % storage_type track_ids = App().db.execute("ORDER BY".join(split)) return tracks_to_albums( [Track(track_id) for track_id in track_ids])
def _on_play_button_clicked(self, button): """ Play playlist @param button as Gtk.Button """ tracks = [] for album_row in self.__view.children: for track in album_row.album.tracks: tracks.append(track) if tracks: albums = tracks_to_albums(tracks) App().player.play_track_for_albums(tracks[0], albums)
def play_radio_from_collection(self, artist_ids): """ Play a radio from collection for artist ids @param artist_ids as [int] """ genre_ids = App().artists.get_genre_ids(artist_ids, StorageType.COLLECTION) track_ids = App().tracks.get_randoms(genre_ids, StorageType.COLLECTION, False, 100) albums = tracks_to_albums([Track(track_id) for track_id in track_ids], False) self.play_albums(albums)
def load(): track_ids = [] if self.__playlist_id == Type.LOVED: for track_id in App().tracks.get_loved_track_ids( [], self.storage_type): if track_id not in track_ids: track_ids.append(track_id) else: for track_id in App().playlists.get_track_ids( self.__playlist_id): if track_id not in track_ids: track_ids.append(track_id) return tracks_to_albums( [Track(track_id) for track_id in track_ids])
def populate(self): """ Populate view """ if App().player.queue: tracks = [Track(track_id) for track_id in App().player.queue] albums = tracks_to_albums(tracks) else: albums = App().player.albums if albums: if len(albums) == 1: self.add_reveal_albums(albums) AlbumsListView.populate(self, albums) self.show_placeholder(False) else: self.show_placeholder(True)
def _on_tertiary_press_gesture(self, x, y, event): """ Play artist @param x as int @param y as int @param event as Gdk.Event """ child = self._box.get_child_at_pos(x, y) if child is None or child.artwork is None: return track_ids = [] if child.data > 0 and App().playlists.get_smart(child.data): request = App().playlists.get_smart_sql(child.data) if request is not None: track_ids = App().db.execute(request) else: track_ids = App().playlists.get_track_ids(child.data) tracks = [Track(track_id) for track_id in track_ids] albums = tracks_to_albums(tracks) if albums: App().player.play_album_for_albums(albums[0], albums)
def __scan(self, scan_type, uris): """ Scan music collection for music files @param scan_type as ScanType @param uris as [str] @thread safe """ try: SqlCursor.add(App().db) App().art.clean_rounded() (files, dirs, streams) = self.__get_objects_for_uris(scan_type, uris) if not files: App().notify.send("Lollypop", _("Scan disabled, missing collection")) return if scan_type == ScanType.NEW_FILES: db_uris = App().tracks.get_uris(uris) else: db_uris = App().tracks.get_uris() # Get mtime of all tracks to detect which has to be updated db_mtimes = App().tracks.get_mtimes() # * 2 => Scan + Save self.__progress_total = len(files) * 2 + len(streams) self.__progress_count = 0 self.__progress_fraction = 0 # Min: 1 thread, Max: 5 threads count = max(1, min(5, cpu_count() // 2)) split_files = split_list(files, count) self.__tags = {} self.__pending_new_artist_ids = [] threads = [] for files in split_files: thread = App().task_helper.run(self.__scan_files, files, db_mtimes, scan_type) threads.append(thread) if scan_type == ScanType.EXTERNAL: storage_type = StorageType.EXTERNAL else: storage_type = StorageType.COLLECTION # Start getting files and populating DB self.__items = [] i = 0 while threads: thread = threads[i] if not thread.is_alive(): threads.remove(thread) self.__items += self.__save_in_db(storage_type) if i >= len(threads) - 1: i = 0 else: i += 1 # Add streams to DB, only happening on command line/m3u files self.__items += self.__save_streams_in_db(streams, storage_type) self.__remove_old_tracks(db_uris, scan_type) if scan_type == ScanType.EXTERNAL: albums = tracks_to_albums( [Track(item.track_id) for item in self.__items]) App().player.play_albums(albums) else: self.__add_monitor(dirs) GLib.idle_add(self.__finish, self.__items) self.__tags = {} self.__items = [] self.__pending_new_artist_ids = [] except Exception as e: Logger.warning("CollectionScanner::__scan(): %s", e) SqlCursor.remove(App().db)