forked from trav/lintunes
v0.35.0: a play history for the yearly Wrapped
The play journals keep running totals per track, which is enough for "most played ever" and nothing a Wrapped asks: top songs of this year, minutes listened, which month, what time of day, what got skipped. Those all come from one timestamped line per listen, so LinTunes now keeps that, while Preferences -> General -> "Keep a play history for my yearly Wrapped" is on. history/<machine>/<YYYY-MM>.jsonl, one writer per folder like the journals: local start time with its offset, ms actually heard (Player adds position steps under 1.5 s, so seeks and pauses don't count), how it ended, where it played and from what, and a name/artist/album snapshot that outlives a delete. Under 5 s is noise and never written. andTunes 0.3.0 writes the same lines on the Rabbit when sync says the desktop wants them, and sync copies each month home when the device's copy is longer. "Share this year's play history with friends" puts a trimmed copy (no ids, playlists or devices) in each friend's cassette folder, daily in November and December and monthly otherwise.
This commit is contained in:
@@ -22,6 +22,7 @@ from lintunes.export import exporter
|
||||
from lintunes.fingerprint import TrackIdentifier, fpcalc_available
|
||||
from lintunes.inhibit import INHIBIT_LOGOUT, INHIBIT_SUSPEND, SleepInhibitor
|
||||
from lintunes.player import Player
|
||||
from lintunes.storage import listen_history
|
||||
from lintunes.importers import file_importer
|
||||
from lintunes.gui.album_art_dialog import AlbumArtDialog
|
||||
from lintunes.gui.art_ops import embed_artwork
|
||||
@@ -109,6 +110,9 @@ class MainWindow(QMainWindow):
|
||||
# Context playback started from: "library" or "playlist:<pid>". Scopes
|
||||
# the now-playing speaker icon to where the song is actually playing.
|
||||
self._now_playing_context = ""
|
||||
# The context the *playing* track came from. _now_playing_context
|
||||
# moves to the new one before the old listen is closed.
|
||||
self._listen_context = ""
|
||||
# Friend sharing's menu group and dialogs. Its background service is
|
||||
# started by run_gui (host machine only), never by constructing the
|
||||
# window — tests build windows by the dozen.
|
||||
@@ -271,6 +275,7 @@ class MainWindow(QMainWindow):
|
||||
lambda msg: QMessageBox.warning(self, "Can't play track", msg))
|
||||
self.player.track_missing.connect(self._on_track_missing)
|
||||
self.player.track_changed.connect(self._on_track_changed)
|
||||
self.player.listen_ended.connect(self._on_listen_ended)
|
||||
self.player.playing_changed.connect(self._update_now_playing_icon)
|
||||
self.player.playing_changed.connect(self._on_playing_changed)
|
||||
manager.track_updated.connect(self._on_track_meta_updated)
|
||||
@@ -708,6 +713,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def _on_andtunes_planned(self, plan, free):
|
||||
device = plan.device
|
||||
plan.history = bool(self._prefs.wrapped.get("track_history"))
|
||||
playlists = plan.playlists
|
||||
self._hide_sync_widgets()
|
||||
if plan.needs_ffmpeg and not exporter.web_support.ffmpeg_available():
|
||||
@@ -1812,9 +1818,24 @@ class MainWindow(QMainWindow):
|
||||
if track is None:
|
||||
self.setWindowTitle("LinTunes")
|
||||
else:
|
||||
self._listen_context = self._now_playing_context
|
||||
self.setWindowTitle(f"{track.name} — {track.artist} · LinTunes")
|
||||
self._update_now_playing_icon()
|
||||
|
||||
def _on_listen_ended(self, key, track, started, heard_ms, how):
|
||||
"""One listen for the Wrapped history, if the user keeps one."""
|
||||
if not self._prefs.get("wrapped", {}).get("track_history"):
|
||||
return
|
||||
ctx = self._listen_context
|
||||
if ctx.startswith("followed:"):
|
||||
ctx = "friend:" + ctx.split(":")[2] # followed:cassette:<token>:<pid>
|
||||
self._manager.record_listen(listen_history.entry_for(
|
||||
track, started=started or listen_history.local_now(),
|
||||
heard_ms=heard_ms, how=how,
|
||||
src="desktop" if self.player.is_local else "cast",
|
||||
ctx=ctx, shuffle=self.player.is_shuffle(),
|
||||
track_id=None if isinstance(key, str) else key))
|
||||
|
||||
def _on_track_meta_updated(self, track_id: int):
|
||||
current = self.player.current_track
|
||||
if current is not None and current.track_id == track_id:
|
||||
|
||||
Reference in New Issue
Block a user