Files
lintunes/lintunes/seed_playlists.py
T
trav 549c5bf94f v0.25.0: New Tracks, a soft emboss, date added pinned
Groundwork for Cassette (friend library sharing) that stands on its own:

- A brand-new library (fresh data dir, or a fresh iTunes import) starts
  with a "New Tracks" smart playlist: added in the last 3 months, newest
  first. Fixed persistent id, so two machines seeding one unsynced share
  merge into a single playlist.
- Every non-flat button, the sidebar Library button and the transport
  boxes get a very slight top-lit gradient computed from the live palette,
  with the chosen color kept exactly at its midpoint.
- Tests pin that individual imports stamp date added = now even for an
  old file, and that the iTunes migration keeps the XML's dates.
2026-09-28 20:56:28 -07:00

46 lines
1.8 KiB
Python

"""Playlists a brand-new library starts with.
Seeded once, when a library is born: a fresh empty data dir (``run_gui``) or a
fresh iTunes import. An existing library never gains one, and a seeded playlist
is an ordinary smart playlist afterwards — rename it, edit it, delete it.
The persistent id is **fixed**, not random: two machines that each start a new
library in the same (not yet synced) share both seed it, and the conflict merge
then sees one playlist with two copies instead of two playlists both called
"New Tracks".
"""
from lintunes.models import Playlist, PlaylistType
from lintunes.models.playlist import PlaylistSettings
from lintunes.smart import SmartCriteria, SmartGroup, SmartRule
NEW_TRACKS_NAME = "New Tracks"
NEW_TRACKS_PID = "4E4557545241434B" # "NEWTRACK" in hex
def new_tracks_playlist() -> Playlist:
"""Smart playlist of everything added in the last three months, newest
first."""
criteria = SmartCriteria(root=SmartGroup(conjunction="all", children=[
SmartRule(field="date_added", operator="in_last", value=3,
unit="months"),
]))
return Playlist(
name=NEW_TRACKS_NAME,
persistent_id=NEW_TRACKS_PID,
playlist_type=PlaylistType.SMART,
smart_criteria=criteria,
settings=PlaylistSettings(sort_column="date_added",
sort_ascending=False),
)
def seed_new_library(playlists: dict) -> list[Playlist]:
"""Add the seed playlists to ``playlists`` (persistent id → Playlist)
unless a playlist with that id is already there. Returns what was added."""
added = []
for playlist in (new_tracks_playlist(),):
if playlist.persistent_id not in playlists:
playlists[playlist.persistent_id] = playlist
added.append(playlist)
return added