Open on the Feed, and refresh it without hammering yt-dlp

The tab order was Watch, Search, Feed, Browse, Downloads, and the app opened
on Watch -- which is where the other tabs send you, not somewhere you start.
It is now Feed, Search, Browse, Downloads, Watch, with icons. Routing is
unaffected: _tab_index_of resolves by widget identity, not position.

Refresh-on-open needed care rather than a call in showEvent. A local refresh
is one yt-dlp subprocess per subscribed channel, serially, so it is braked
four ways: only channels not seen for feed.auto_refresh_on_open_minutes (30,
0 to disable), at most eight per visit, once per interval per session, and
after a delay so it does not race the tab transition or first-run setup. The
cached feed is already on screen throughout. That is a new config key rather
than the dead auto_refresh_minutes, because existing configs store that as 0
and would have read as opting out of a feature that did not exist yet.

SmoothTabWidget gained the currentChanged signal, icons and a corner slot it
never had. Its set_current_index needed a re-entrancy flag, not just an index
check: setting the tab bar's index emits its currentChanged straight back into
the same method, and at that point the stack has not moved, so every switch
fired the activation hook twice.

The grid was cleared and rebuilt after every channel finished -- flicker, lost
scroll position and every thumbnail re-read from disk each time. merge_entries
keeps existing cards. While there, _relayout was re-adding cards the layout
already owned, so layout items accumulated on every Load more, and the resize
check compared against columnCount(), which never shrinks, so it relaid out on
every resize event.

Smaller things this exposed: feed errors were written into the label the next
success overwrote, so failures were invisible; switching to account mode left
the local videos on screen; cancel() had no callers, so a refresh outlived the
tab and the window; Browse's Subscribe never said Unsubscribe though it
toggles; "Play all" queued one page while claiming otherwise; and the feed
sorted publish times against wall-clock fetch times in one COALESCE, so the
last-refreshed channel floated to the top.

Feed is the first thing seen now, so an empty one says what to do about it
instead of showing a bare grid.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-09 01:11:40 +02:00
parent 27933dd495
commit 79a6f26c2f
9 changed files with 453 additions and 80 deletions
+22 -1
View File
@@ -27,6 +27,7 @@ from PySide6.QtWidgets import (
from .ytsage_gui_cards import VideoCardGrid
from ..core.ytsage_client import YtdlpWorker
from ..utils.ytsage_library_manager import LibraryManager
from ..utils.ytsage_localization import _
from ..utils.ytsage_logger import logger
@@ -239,6 +240,9 @@ class BrowsePage(QWidget):
}
if self._channel_meta.get("title"):
self.title_label.setText(self._channel_meta["title"])
# Now that the real channel id is known, the button can say whether
# this channel is already followed.
self.refresh_subscribe_state()
def _on_meta_finished(self) -> None:
if self._meta_worker is not None:
@@ -250,13 +254,30 @@ class BrowsePage(QWidget):
if not meta.get("title"):
meta["title"] = self.title_label.text()
self.subscribeRequested.emit(meta)
# The handler toggles, so reflect the new state here. Previously the
# button always read "Subscribe" whichever way it had just gone, and
# the only feedback was a status line on a different tab.
self.refresh_subscribe_state()
def refresh_subscribe_state(self) -> None:
"""Make the button say what pressing it will now do."""
channel_id = self._channel_meta.get("channel_id") or self._channel_meta.get("url") or self._current_url
subscribed = bool(channel_id) and LibraryManager.is_subscribed(str(channel_id))
self.subscribe_btn.setText(_("browse.unsubscribe") if subscribed else _("browse.subscribe"))
self.subscribe_btn.setToolTip(
_("browse.unsubscribe_tooltip") if subscribed else _("browse.subscribe_tooltip")
)
def _on_play_all(self) -> None:
for entry in [c.entry for c in self.playlist_section.grid._cards]:
cards = list(self.playlist_section.grid._cards)
for entry in [c.entry for c in cards]:
e = dict(entry)
if not e.get("url") and e.get("id"):
e["url"] = f"https://www.youtube.com/watch?v={e['id']}"
self._router.queueVideo.emit(e)
# "Play all" queues what has been loaded, which is one page unless the
# user pressed Load more. Say so rather than implying the whole list.
self.playlist_section.status_label.setText(_("browse.queued_loaded", count=len(cards)))
def _on_download_playlist(self) -> None:
if self._current_url: