mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 18:22:53 +01:00
Added setting for export playlist root folder toggle
This commit is contained in:
1 parent
2c352b76a1
commit
3385b794e9
12 files changed
+111
-38
No files matched your search
@@ -876,7 +876,7 @@ Two independent apps that talk over HTTP:
|
||||
user), quits (`quit_now`) when nothing is unsaved, else asks Save · Discard
|
||||
· Cancel; the sidecar is killed only at `RunEvent::Exit`, after the answer;
|
||||
browser dev gets `beforeunload`), `SaveBar` (+ "Discard changes…" when
|
||||
dirty, and the settings gear beside it, whose menu opens `ShortcutsDialog` — the shortcut list is written out BY HAND, so a new or changed shortcut in `PrepStrip` / `TrackTable` must be added there too — and `AppSettings` ("Konduktor Settings…": app-level prefs, each with its default in `APP_SETTING_DEFAULTS` and read through `useAppSetting`; today `expandPlaylistFolders`, default off. The Sidebar holds folder open state as per-id overrides of that setting, reset on a new library or a change of the setting, and carried to the new ids when a rename/move changes a folder's path id)), `Toolbar` (search/filters; columns are chosen by right-clicking the table header),
|
||||
dirty, and the settings gear beside it, whose menu opens `ShortcutsDialog` — the shortcut list is written out BY HAND, so a new or changed shortcut in `PrepStrip` / `TrackTable` must be added there too — and `AppSettings` ("Konduktor Settings…": app-level prefs, each with its default in `APP_SETTING_DEFAULTS` and read through `useAppSetting`; today `expandPlaylistFolders` and `exportRootFolder`, both default off — the latter read by the backend at `run_export` and passed down as `ExportPayload.root_folder`. The Sidebar holds folder open state as per-id overrides of that setting, reset on a new library or a change of the setting, and carried to the new ids when a rename/move changes a folder's path id)), `Toolbar` (search/filters; columns are chosen by right-clicking the table header),
|
||||
`TrackTable` (**the one track list** — All Tracks, playlists, exports and
|
||||
devices. TanStack Table + **virtualized** grid; per-row play button,
|
||||
configurable columns, header sorting, inline double-click editing, and
|
||||
@@ -1747,7 +1747,11 @@ that number and nothing else — everything derives from it:
|
||||
**volume-relative** `DIR`, never a host path — so a USB export is portable by
|
||||
construction, and the `.nml` cannot be written until the destination is known.
|
||||
Also settled: loose tracks land in an **"Other" playlist**, playlist folders
|
||||
are preserved, and the export is a **standalone `collection.nml`** the user
|
||||
are preserved — at the exported library's TOP LEVEL by default; the
|
||||
`exportRootFolder` setting (`ExportPayload.root_folder`) nests the whole
|
||||
tree, Other included, in one folder named after the export, in all four
|
||||
writers (decided 2026-10-12: the export is a library of its own, so the
|
||||
wrapper was one more click at the gig), and the export is a **standalone `collection.nml`** the user
|
||||
swaps into a Traktor install — so it needs the full skeleton, verified from the
|
||||
real file: `<NML VERSION="20">`, `<HEAD>`, `<COLLECTION ENTRIES>`,
|
||||
`<SETS ENTRIES="0">`, `<PLAYLISTS>` wrapping a `$ROOT` FOLDER node with a
|
||||
|
||||
@@ -381,7 +381,8 @@ class OneLibraryExporter:
|
||||
# ---- playlists -----------------------------------------------------------
|
||||
|
||||
def _write_playlists(self, con, payload: ExportPayload, by_source: dict) -> None:
|
||||
"""One folder named after the export, with the tree preserved under it.
|
||||
"""The tree preserved — at the top level (parent NULL), or with
|
||||
`payload.root_folder` under one folder named after the export.
|
||||
|
||||
`playlist` is a flat table with `playlist_id_parent`, so folders and
|
||||
playlists are the same row kind told apart by `attribute` (1 = folder).
|
||||
@@ -397,8 +398,8 @@ class OneLibraryExporter:
|
||||
)
|
||||
return next_id[0]
|
||||
|
||||
root = add(payload.name, None, folder=True)
|
||||
folders: dict[tuple[str, ...], int] = {(): root}
|
||||
root = add(payload.name, None, folder=True) if payload.root_folder else None
|
||||
folders: dict[tuple[str, ...], int | None] = {(): root}
|
||||
|
||||
for playlist in payload.playlists:
|
||||
parent = root
|
||||
|
||||
@@ -198,8 +198,9 @@ class RekordboxDeviceExporter:
|
||||
|
||||
@staticmethod
|
||||
def _playlists(payload: ExportPayload, by_source: dict) -> tuple[list[bytes], list[bytes]]:
|
||||
"""The tree under one folder named after the export, as the other
|
||||
targets build it. `sort_order` is a node's position among its siblings."""
|
||||
"""The tree as the other targets build it — at the top level (parent
|
||||
0), or with `payload.root_folder` under one folder named after the
|
||||
export. `sort_order` is a node's position among its siblings."""
|
||||
tree: list[bytes] = []
|
||||
entries: list[bytes] = []
|
||||
next_id = [0]
|
||||
@@ -220,7 +221,7 @@ class RekordboxDeviceExporter:
|
||||
index += 1
|
||||
entries.append(pdb.playlist_entry_row(index, track_id, playlist_id))
|
||||
|
||||
root = add(payload.name, 0, folder=True)
|
||||
root = add(payload.name, 0, folder=True) if payload.root_folder else 0
|
||||
folders: dict[tuple[str, ...], int] = {(): root}
|
||||
for playlist in payload.playlists:
|
||||
parent = root
|
||||
|
||||
@@ -383,7 +383,10 @@ class RekordboxExporter:
|
||||
# ---- playlists ---------------------------------------------------------------
|
||||
|
||||
def _write_playlists(self, db, payload: ExportPayload, rows: dict) -> None:
|
||||
"""The tree, under one folder named after the export."""
|
||||
"""The tree — at the top level, or with `payload.root_folder` under one
|
||||
folder named after the export (None = the top level)."""
|
||||
root = None
|
||||
if payload.root_folder:
|
||||
root = db.create_playlist_folder(payload.name)
|
||||
db.flush()
|
||||
folders: dict[tuple[str, ...], object] = {(): root}
|
||||
|
||||
@@ -106,14 +106,10 @@ class TraktorExporter:
|
||||
return WrittenLibrary(library=library)
|
||||
|
||||
def _write_playlists(self, adapter, payload: ExportPayload, moved: dict) -> None:
|
||||
"""Recreate the tree under one folder named after the export.
|
||||
|
||||
Nested under the export's own name for the same reason import nests a
|
||||
drive's playlists under the drive's name: a collection swapped onto
|
||||
another machine should say where its playlists came from.
|
||||
"""
|
||||
root = adapter.create_folder(payload.name)
|
||||
folders: dict[tuple[str, ...], str] = {(): root}
|
||||
"""Recreate the tree — at the top level, or with `payload.root_folder`
|
||||
under one folder named after the export (None = the top level)."""
|
||||
root = adapter.create_folder(payload.name) if payload.root_folder else None
|
||||
folders: dict[tuple[str, ...], str | None] = {(): root}
|
||||
|
||||
for playlist in payload.playlists:
|
||||
parent = self._folder_for(adapter, folders, tuple(playlist.folders), root)
|
||||
@@ -128,7 +124,7 @@ class TraktorExporter:
|
||||
adapter.set_playlist_entries(node_id, loose)
|
||||
|
||||
@staticmethod
|
||||
def _folder_for(adapter, folders: dict, path: tuple[str, ...], root: str) -> str:
|
||||
def _folder_for(adapter, folders: dict, path: tuple[str, ...], root: str | None) -> str | None:
|
||||
"""Create (once) the folder chain a playlist sits under, and return it."""
|
||||
for depth in range(1, len(path) + 1):
|
||||
branch = path[:depth]
|
||||
|
||||
@@ -94,8 +94,14 @@ class ExportPayload:
|
||||
|
||||
tracks: list[ExportTrack] = field(default_factory=list)
|
||||
playlists: list[ExportPlaylist] = field(default_factory=list)
|
||||
#: The export's name, used for the folder its playlists are nested under.
|
||||
#: The export's name, used for the folder its playlists are nested under
|
||||
#: when `root_folder` is set.
|
||||
name: str = "Export"
|
||||
#: Nest the whole playlist tree (and "Other") in one folder named `name`.
|
||||
#: Off — the default, a Konduktor setting — the playlists sit at the
|
||||
#: library's top level: an export is a library of its own, so a folder
|
||||
#: saying where it came from is one more click at the gig.
|
||||
root_folder: bool = False
|
||||
#: Called by a writer before each slow step (e.g. decoding a track for its
|
||||
#: waveform) with a message for the status bar, and — for a per-track loop —
|
||||
#: `step` of `of`, which drives the progress bar. RAISES when the user has
|
||||
|
||||
@@ -433,9 +433,13 @@ def _folder_paths(adapter) -> dict[str, list[str]]:
|
||||
# ---- running -----------------------------------------------------------------
|
||||
|
||||
|
||||
def run(adapter, export_set, built: ExportPlan, handle: JobHandle) -> dict:
|
||||
def run(adapter, export_set, built: ExportPlan, handle: JobHandle, *,
|
||||
root_folder: bool = False) -> dict:
|
||||
"""Copy what changed, then write every target's library over the audio.
|
||||
|
||||
`root_folder` nests the playlists in a folder named after the export (the
|
||||
"Put exported playlists in a folder" setting); otherwise they sit at the top.
|
||||
|
||||
Rolls back EVERYTHING this run wrote on cancel or on any failure —
|
||||
including the libraries of targets that had already been written when a
|
||||
later one failed. What it KEPT from the previous export stays, and the
|
||||
@@ -545,6 +549,7 @@ def run(adapter, export_set, built: ExportPlan, handle: JobHandle) -> dict:
|
||||
|
||||
payload = ExportPayload(
|
||||
name=export_set.name,
|
||||
root_folder=root_folder,
|
||||
tracks=payload_tracks,
|
||||
playlists=built.playlists,
|
||||
checkpoint=checkpoint,
|
||||
|
||||
@@ -765,7 +765,10 @@ def run_export(set_id: str) -> JobStatus:
|
||||
built = exporter.plan(adapter, found)
|
||||
if built.blocked:
|
||||
raise HTTPException(409, built.blocked)
|
||||
job = JOBS.submit("export", lambda handle: exporter.run(adapter, found, built, handle))
|
||||
# A Konduktor setting, read when the export starts.
|
||||
root_folder = bool(prefs.load_prefs().get("exportRootFolder", False))
|
||||
job = JOBS.submit("export", lambda handle: exporter.run(
|
||||
adapter, found, built, handle, root_folder=root_folder))
|
||||
return JobStatus(**job.as_dict())
|
||||
|
||||
|
||||
|
||||
@@ -177,9 +177,9 @@ check("bpm x100, rating, file type, bitmask as rekordbox writes them",
|
||||
check("the file path is drive-relative", lib.tracks[0]["file_path"] == "/Contents/House/One.wav", lib.tracks[0]["file_path"])
|
||||
check("no computer's masterDbId is claimed", all(t["u3"] == 0 and t["u4"] == 0 for t in lib.tracks))
|
||||
tree = {p["name"]: p for p in lib.playlists}
|
||||
check("the tree: a folder named after the export > House > Peak, plus Other for loose tracks",
|
||||
tree["GIG"]["folder"] and tree["House"]["parent"] == tree["GIG"]["id"]
|
||||
and tree["Peak"]["parent"] == tree["House"]["id"] and tree["Other"]["parent"] == tree["GIG"]["id"])
|
||||
check("the tree: House > Peak, plus Other for loose tracks, at the top level (parent 0)",
|
||||
"GIG" not in tree and tree["House"]["folder"] and tree["House"]["parent"] == 0
|
||||
and tree["Peak"]["parent"] == tree["House"]["id"] and tree["Other"]["parent"] == 0)
|
||||
peak = [e for e in lib.entries if e[2] == tree["Peak"]["id"]]
|
||||
check("playlist entries in order, 1-based", peak == [(1, 1, tree["Peak"]["id"]), (2, 2, tree["Peak"]["id"])], peak)
|
||||
check("every track has an analysis path, and the files exist",
|
||||
@@ -188,6 +188,13 @@ check("artwork rows name the a<n>.jpg files, which exist",
|
||||
all((root / p.lstrip("/")).is_file() for p in lib.artwork.values()) and len(lib.artwork) == 3)
|
||||
check("every file written is reported, so a re-export can clear it",
|
||||
all(p.exists() for p in written.all_paths))
|
||||
import dataclasses # noqa: E402
|
||||
rooted_tree = {p["name"]: p for p in P.read(
|
||||
dev.write(dataclasses.replace(payload, root_folder=True), root).library.read_bytes()).playlists}
|
||||
check("with the root-folder setting: a folder named after the export holds House and Other",
|
||||
rooted_tree["GIG"]["folder"] and rooted_tree["GIG"]["parent"] == 0
|
||||
and rooted_tree["House"]["parent"] == rooted_tree["GIG"]["id"]
|
||||
and rooted_tree["Other"]["parent"] == rooted_tree["GIG"]["id"])
|
||||
|
||||
print("== alongside OneLibrary: one set of analysis files and artwork ==")
|
||||
both = Path(tempfile.mkdtemp())
|
||||
@@ -195,7 +202,6 @@ for t in tracks:
|
||||
dst = both / t.destination.relative_to(root)
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
dst.write_bytes(t.destination.read_bytes())
|
||||
import dataclasses # noqa: E402
|
||||
moved = [dataclasses.replace(t, destination=both / t.destination.relative_to(root)) for t in tracks]
|
||||
both_payload = ExportPayload(name="GIG", tracks=moved, playlists=payload.playlists)
|
||||
ol_written = core_export.for_platform("onelibrary").write(both_payload, both)
|
||||
|
||||
+24
-11
@@ -137,19 +137,20 @@ def walk(nodes, path=()):
|
||||
|
||||
|
||||
walk(back.playlist_tree())
|
||||
check("one folder named after the export", ("GIG",) in tree and tree[("GIG",)].kind == "folder")
|
||||
check("nested folders are preserved", ("GIG", "House") in tree)
|
||||
check("and nest further", ("GIG", "House", "Slow") in tree)
|
||||
# By default the tree sits at the top level: an export is a library of its own.
|
||||
check("no folder named after the export by default", ("GIG",) not in tree)
|
||||
check("nested folders are preserved", ("House",) in tree and tree[("House",)].kind == "folder")
|
||||
check("and nest further", ("House", "Slow") in tree)
|
||||
check("playlists land in their folder",
|
||||
("GIG", "House", "Peak Time") in tree and ("GIG", "House", "Slow", "Warmup") in tree)
|
||||
("House", "Peak Time") in tree and ("House", "Slow", "Warmup") in tree)
|
||||
check("with the right counts",
|
||||
tree[("GIG", "House", "Peak Time")].count == 2
|
||||
and tree[("GIG", "House", "Slow", "Warmup")].count == 1)
|
||||
tree[("House", "Peak Time")].count == 2
|
||||
and tree[("House", "Slow", "Warmup")].count == 1)
|
||||
# A track added individually would otherwise be reachable only by search.
|
||||
check("loose tracks get an 'Other' playlist", ("GIG", "Other") in tree)
|
||||
check("loose tracks get an 'Other' playlist, at the top level", ("Other",) in tree)
|
||||
check("holding exactly the ones no playlist claimed",
|
||||
tree[("GIG", "Other")].count == 1, tree[("GIG", "Other")].count)
|
||||
other_ids = back.playlist_entries(tree[("GIG", "Other")].id)
|
||||
tree[("Other",)].count == 1, tree[("Other",)].count)
|
||||
other_ids = back.playlist_entries(tree[("Other",)].id)
|
||||
check("and it is the right track",
|
||||
back.track(other_ids[0]).title == plain.title)
|
||||
|
||||
@@ -182,7 +183,19 @@ again = exporter.write(payload, dest).library
|
||||
check("the entry count did not double",
|
||||
f'<COLLECTION ENTRIES="{len(chosen)}">' in again.read_text(encoding="utf-8"))
|
||||
check("and the tree did not duplicate",
|
||||
len(TraktorDriver().open(again).playlist_tree()) == 1)
|
||||
len(TraktorDriver().open(again).playlist_tree()) == len(back.playlist_tree()))
|
||||
|
||||
print("== with the root-folder setting: everything under one folder named after the export ==")
|
||||
payload.root_folder = True
|
||||
rooted = TraktorDriver().open(exporter.write(payload, dest).library)
|
||||
tree.clear()
|
||||
walk(rooted.playlist_tree())
|
||||
check("one top-level node: a folder named after the export",
|
||||
[n.name for n in rooted.playlist_tree()] == ["GIG"] and tree[("GIG",)].kind == "folder")
|
||||
check("the tree nests inside it",
|
||||
("GIG", "House", "Peak Time") in tree and ("GIG", "House", "Slow", "Warmup") in tree)
|
||||
check("and so does 'Other'", ("GIG", "Other") in tree and tree[("GIG", "Other")].count == 1)
|
||||
payload.root_folder = False
|
||||
|
||||
# ==============================================================================
|
||||
# Running an export: the copy, the safety rules, and the rollback.
|
||||
@@ -207,7 +220,7 @@ for i, track in enumerate(src.tracks[:4]):
|
||||
seed_items.append(ExportTrack(track=track, destination=audio, cues=src.track_cues(track.id)))
|
||||
exporter_obj = core_export.for_platform("traktor")
|
||||
exporter_obj.write(
|
||||
_Payload(name="Source", tracks=seed_items,
|
||||
_Payload(name="Source", tracks=seed_items, root_folder=True,
|
||||
playlists=[ExportPlaylist(name="Peak Time",
|
||||
track_ids=[src.tracks[0].id, src.tracks[1].id])]),
|
||||
lib_root,
|
||||
|
||||
@@ -173,9 +173,23 @@ for platform, reopen in (
|
||||
|
||||
tree.clear()
|
||||
walk(back.playlist_tree())
|
||||
check("a folder named after the export", ("GIG",) in tree)
|
||||
check("nested folders are preserved", ("GIG", "House") in tree)
|
||||
check("no folder named after the export by default", ("GIG",) not in tree)
|
||||
check("nested folders are preserved, at the top level", ("House",) in tree)
|
||||
check("with the playlist inside",
|
||||
("House", "Peak Time") in tree
|
||||
and tree[("House", "Peak Time")].count == len(chosen))
|
||||
|
||||
print(f"-- {platform}: with the root-folder setting")
|
||||
rooted_root = Path(tempfile.mkdtemp()) / "GIG"
|
||||
rooted_payload = build(rooted_root)
|
||||
rooted_payload.root_folder = True
|
||||
exporter.write(rooted_payload, rooted_root)
|
||||
rooted = reopen(rooted_root)
|
||||
tree.clear()
|
||||
walk(rooted.playlist_tree())
|
||||
check("one top-level node: a folder named after the export",
|
||||
[n.name for n in rooted.playlist_tree()] == ["GIG"])
|
||||
check("the tree nests inside it",
|
||||
("GIG", "House", "Peak Time") in tree
|
||||
and tree[("GIG", "House", "Peak Time")].count == len(chosen))
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import { api } from '../api'
|
||||
/** The prefs this dialog owns, and what each is when never set. */
|
||||
export const APP_SETTING_DEFAULTS = {
|
||||
expandPlaylistFolders: false,
|
||||
/** Read by the backend when an export runs (`main.run_export`). */
|
||||
exportRootFolder: false,
|
||||
}
|
||||
|
||||
type AppSettingKey = keyof typeof APP_SETTING_DEFAULTS
|
||||
@@ -26,6 +28,7 @@ export function useAppSetting<K extends AppSettingKey>(key: K): (typeof APP_SETT
|
||||
export function AppSettings({ onClose }: { onClose: () => void }) {
|
||||
const qc = useQueryClient()
|
||||
const expandFolders = useAppSetting('expandPlaylistFolders')
|
||||
const exportRootFolder = useAppSetting('exportRootFolder')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -74,6 +77,24 @@ export function AppSettings({ onClose }: { onClose: () => void }) {
|
||||
</span>
|
||||
</label>
|
||||
</section>
|
||||
<section className="space-y-2">
|
||||
<h3 className="text-[11px] font-semibold uppercase tracking-wider text-faint">Exports</h3>
|
||||
<label className="flex cursor-pointer items-start gap-2.5">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="mt-0.5"
|
||||
checked={exportRootFolder}
|
||||
onChange={(e) => void set({ exportRootFolder: e.target.checked })}
|
||||
/>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-sm text-text">Put exported playlists in a folder</span>
|
||||
<span className="block text-xs text-faint">
|
||||
Nest an export's playlists in one folder named after the export. Off, they sit at the
|
||||
top level of the exported library. Applies from the next export.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</section>
|
||||
{error && <div className="text-xs text-pink">{error}</div>}
|
||||
</div>
|
||||
<div className="flex justify-end gap-2 border-t border-line px-5 py-3">
|
||||
|
||||
Reference in new issue
Block a user