forked from trav/lintunes
v0.58.0: the library search filters the sidebar's playlists
- Typing in the library search now also narrows the playlist list to names containing every word; folders stay when they or something inside match, open while filtering, and clearing puts back the folders you had open. - AirPlay: an unreadable /info reply no longer fails the stream (pyatv died on shairport-sync's).
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.57.0"
|
||||
__version__ = "0.58.0"
|
||||
|
||||
@@ -224,6 +224,19 @@ def _install_compat():
|
||||
|
||||
rtsp.RtspSession.announce = announce
|
||||
|
||||
# GET /info is optional, and pyatv treats an unparseable answer as fatal:
|
||||
# shairport-sync's classic build answers it with a body that isn't a
|
||||
# plist, so every stream failed before it began.
|
||||
real_info = rtsp.RtspSession.info
|
||||
|
||||
async def info(self):
|
||||
try:
|
||||
return await real_info(self)
|
||||
except Exception: # noqa: BLE001 — /info is only a hint
|
||||
return {}
|
||||
|
||||
rtsp.RtspSession.info = info
|
||||
|
||||
real_send = airplayv1.AirPlayV1.send_audio_packet
|
||||
|
||||
async def send_audio_packet(self, transport, rtp_header, audio):
|
||||
|
||||
@@ -161,10 +161,11 @@ def alac_verbatim(pcm: bytes) -> bytes:
|
||||
|
||||
|
||||
_SAMPLE_FORMATS = {2: "s16be", 4: "s32be"}
|
||||
_SAMPLE_FORMATS_LE = {2: "s16le", 4: "s32le"}
|
||||
|
||||
|
||||
def ffmpeg_command(path: str, start_ms: int, sample_rate: int, channels: int,
|
||||
sample_size: int) -> list[str]:
|
||||
sample_size: int, big_endian: bool = True) -> list[str]:
|
||||
"""Decode `path` from `start_ms` to raw PCM on stdout, in the shape the
|
||||
receiver asked for.
|
||||
|
||||
@@ -172,8 +173,9 @@ def ffmpeg_command(path: str, start_ms: int, sample_rate: int, channels: int,
|
||||
sending (audio_source._to_audio_samples), so asking ffmpeg for BE is the
|
||||
same bytes on the wire. `-ss` before `-i` is an input seek, which is
|
||||
sample-accurate for audio and instant even deep into a long file.
|
||||
cliairplay (cli.py) reads little-endian, hence `big_endian=False`.
|
||||
"""
|
||||
fmt = _SAMPLE_FORMATS.get(sample_size)
|
||||
fmt = (_SAMPLE_FORMATS if big_endian else _SAMPLE_FORMATS_LE).get(sample_size)
|
||||
if fmt is None:
|
||||
raise ValueError(f"unsupported sample size {sample_size}")
|
||||
command = ["ffmpeg", "-nostdin", "-hide_banner", "-loglevel", "error"]
|
||||
|
||||
@@ -179,6 +179,9 @@ class LibraryView(TableSettingsMixin, QWidget):
|
||||
play_requested = pyqtSignal(list, int)
|
||||
info_requested = pyqtSignal(list)
|
||||
show_in_playlist_requested = pyqtSignal(int, str) # track_id, playlist pid
|
||||
# The search box's text, case-folded, after the debounce ("" when cleared):
|
||||
# MainWindow filters the sidebar's playlists by it too.
|
||||
search_changed = pyqtSignal(str)
|
||||
|
||||
def __init__(self, manager, parent=None):
|
||||
super().__init__(parent)
|
||||
@@ -337,6 +340,7 @@ class LibraryView(TableSettingsMixin, QWidget):
|
||||
self._search.blockSignals(False)
|
||||
self._search_text = ""
|
||||
self._search_tracks = self._all_tracks
|
||||
self.search_changed.emit("")
|
||||
for lst in (self._genre_list, self._artist_list, self._album_list):
|
||||
lst.blockSignals(True)
|
||||
lst.setCurrentRow(0) # "All"
|
||||
@@ -370,6 +374,7 @@ class LibraryView(TableSettingsMixin, QWidget):
|
||||
def _apply_search(self):
|
||||
self._search_text = self._search.text().strip().casefold()
|
||||
self._search_tracks = self._compute_search_tracks()
|
||||
self.search_changed.emit(self._search_text)
|
||||
# Rebuild the whole cascade so the genre/artist/album columns reflect
|
||||
# only what the search matched.
|
||||
self._populate_genres()
|
||||
|
||||
@@ -179,6 +179,8 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self._library_view = LibraryView(manager)
|
||||
self._content.addWidget(self._library_view)
|
||||
self._library_view.search_changed.connect(
|
||||
self._sidebar.tree.set_filter)
|
||||
self._playlist_view = PlaylistView(manager)
|
||||
self._content.addWidget(self._playlist_view)
|
||||
self._content.setCurrentWidget(self._library_view)
|
||||
|
||||
+70
-1
@@ -404,6 +404,11 @@ class PlaylistTree(QTreeWidget):
|
||||
# so typing replaces "untitled playlist"; see edit().
|
||||
self._select_all_next_edit = False
|
||||
|
||||
# The library search, as words every shown playlist's name contains;
|
||||
# the folders that were open before it began, to put back after.
|
||||
self._filter_tokens: list[str] = []
|
||||
self._expanded_before_filter: set[str] | None = None
|
||||
|
||||
# Edge auto-scroll during a drag (Qt's built-in autoscroll never runs
|
||||
# because our dragMoveEvent accepts the event itself). Mirrors
|
||||
# track_table's Round 13 machinery.
|
||||
@@ -422,7 +427,7 @@ class PlaylistTree(QTreeWidget):
|
||||
selected_pid = self.current_playlist_id()
|
||||
# Preserve which folders the user has open across rebuilds. On the very
|
||||
# first build this set is empty, so the app opens fully collapsed.
|
||||
expanded = self._expanded_pids()
|
||||
expanded = self._expanded_now_or_before_filter()
|
||||
self.blockSignals(True)
|
||||
self.clear()
|
||||
|
||||
@@ -476,12 +481,76 @@ class PlaylistTree(QTreeWidget):
|
||||
else:
|
||||
self.addTopLevelItem(self._friend_folder(value, expanded))
|
||||
self.blockSignals(False)
|
||||
if self._filter_tokens:
|
||||
self._apply_filter()
|
||||
|
||||
if selected_pid:
|
||||
item = self._find_item(selected_pid)
|
||||
if item:
|
||||
self.setCurrentItem(item)
|
||||
|
||||
# ---- filtering by the library search ----
|
||||
|
||||
def set_filter(self, text: str):
|
||||
"""Show only playlists whose name has every word of `text` (case-
|
||||
folded substrings, like the song search). A folder shows when its own
|
||||
name matches — with all it holds — or when something inside matches,
|
||||
and opens while the search lasts; clearing it reopens exactly the
|
||||
folders that were open before."""
|
||||
tokens = text.casefold().split()
|
||||
if tokens == self._filter_tokens:
|
||||
return
|
||||
if tokens and not self._filter_tokens:
|
||||
self._expanded_before_filter = self._expanded_pids()
|
||||
self._filter_tokens = tokens
|
||||
if tokens:
|
||||
self._apply_filter()
|
||||
return
|
||||
expanded = self._expanded_before_filter or set()
|
||||
self._expanded_before_filter = None
|
||||
stack = [self.topLevelItem(i) for i in range(self.topLevelItemCount())]
|
||||
while stack:
|
||||
item = stack.pop()
|
||||
item.setHidden(False)
|
||||
if item.childCount():
|
||||
item.setExpanded(item.data(0, PID_ROLE) in expanded)
|
||||
stack.extend(item.child(i) for i in range(item.childCount()))
|
||||
current = self.currentItem()
|
||||
if current is not None:
|
||||
self.scrollToItem(current)
|
||||
|
||||
def _apply_filter(self):
|
||||
def matches(item) -> bool:
|
||||
name = item.text(0).casefold()
|
||||
return all(token in name for token in self._filter_tokens)
|
||||
|
||||
def show_all(item):
|
||||
item.setHidden(False)
|
||||
for i in range(item.childCount()):
|
||||
show_all(item.child(i))
|
||||
|
||||
def visit(item) -> bool:
|
||||
if matches(item):
|
||||
show_all(item)
|
||||
return True
|
||||
shown = False
|
||||
for i in range(item.childCount()):
|
||||
shown = visit(item.child(i)) or shown
|
||||
item.setHidden(not shown)
|
||||
if shown:
|
||||
item.setExpanded(True)
|
||||
return shown
|
||||
|
||||
for i in range(self.topLevelItemCount()):
|
||||
visit(self.topLevelItem(i))
|
||||
|
||||
def _expanded_now_or_before_filter(self) -> set[str]:
|
||||
"""While filtering, the tree's open folders are the filter's doing;
|
||||
what a rebuild should keep is what the user had open."""
|
||||
if self._expanded_before_filter is not None:
|
||||
return set(self._expanded_before_filter)
|
||||
return self._expanded_pids()
|
||||
|
||||
def _add_mine(self, pid, children, expanded, add_level):
|
||||
"""One of my top-level playlists/folders (and a folder's contents),
|
||||
when the top level is being interleaved with followed ones."""
|
||||
|
||||
Reference in New Issue
Block a user