mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Improved drag to import dialog
This commit is contained in:
1 parent
bf427a628e
commit
518542c7bb
15 files changed
+180
-35
No files matched your search
@@ -317,6 +317,7 @@ def run(
|
||||
folder_name: str | None = None,
|
||||
reference: bool = False,
|
||||
into_playlist: str | None = None,
|
||||
into_playlist_index: int | None = None,
|
||||
) -> dict:
|
||||
"""Perform the import. Returns a summary dict for the job result.
|
||||
|
||||
@@ -332,7 +333,8 @@ def run(
|
||||
`reference` adds each file WHERE IT IS instead of copying it, so there is no
|
||||
destination and nothing to roll back. `into_playlist` appends every planned
|
||||
track — the new ones and those the destination already held — to one of the
|
||||
destination's playlists before the save, so both land in one commit.
|
||||
destination's playlists before the save, so both land in one commit;
|
||||
`into_playlist_index` inserts them there instead (a drop between rows).
|
||||
|
||||
A destination that PLACES ITS OWN AUDIO (`tracks.places_audio`: a OneLibrary
|
||||
stick) overrides both: `dest.place_audio` names each copy's target, or says
|
||||
@@ -446,9 +448,9 @@ def run(
|
||||
handle.progress(message="Adding to the playlist…")
|
||||
current = dest.playlist_entries(into_playlist) or []
|
||||
have = set(current)
|
||||
dest.set_playlist_entries(
|
||||
into_playlist, current + [i for i in all_ids if i not in have]
|
||||
)
|
||||
fresh = [i for i in all_ids if i not in have]
|
||||
at = len(current) if into_playlist_index is None else max(0, min(len(current), into_playlist_index))
|
||||
dest.set_playlist_entries(into_playlist, current[:at] + fresh + current[at:])
|
||||
|
||||
playlists_made = _rebuild_playlists(
|
||||
source, dest, plan, by_source, folder_name, handle
|
||||
|
||||
@@ -1309,7 +1309,8 @@ def add_entries(playlist_uuid: str, body: AddEntries) -> dict:
|
||||
return {"status": "duplicates", "id": playlist_uuid, "added": 0,
|
||||
"duplicates": len(dupes), "count": len(current)}
|
||||
added = list(body.track_ids) if mode == "add" else [t for t in body.track_ids if t not in have]
|
||||
n = a.set_playlist_entries(playlist_uuid, current + added) if added else len(current)
|
||||
at = len(current) if body.index is None else max(0, min(len(current), body.index))
|
||||
n = a.set_playlist_entries(playlist_uuid, current[:at] + added + current[at:]) if added else len(current)
|
||||
return {"status": "added", "id": playlist_uuid, "added": len(added),
|
||||
"duplicates": len(dupes), "count": n}
|
||||
|
||||
@@ -2572,6 +2573,7 @@ def folder_add(body: FolderAddRequest) -> JobStatus:
|
||||
source, dest, plan, handle,
|
||||
reference=in_place or body.mode == "reference",
|
||||
into_playlist=body.playlist_id,
|
||||
into_playlist_index=body.playlist_index,
|
||||
)
|
||||
# Export sets are Konduktor's own data, not the library's, so they are
|
||||
# updated after the library has been saved rather than inside it.
|
||||
@@ -2658,6 +2660,7 @@ def start_import(body: ImportRequest) -> JobStatus:
|
||||
def work(handle):
|
||||
result = importer.run(
|
||||
source, dest, plan, handle, folder_name=folder_name, into_playlist=body.into_playlist,
|
||||
into_playlist_index=body.into_playlist_index,
|
||||
)
|
||||
# As folder add: an export set is Konduktor's data, updated afterwards.
|
||||
if body.export_id is not None and library is not None:
|
||||
|
||||
@@ -27,6 +27,9 @@ class AddEntries(BaseModel):
|
||||
# where `playlists.duplicates`, else skipped), or "ask" — change nothing and
|
||||
# report how many, so the UI can ask and send again with skip/add.
|
||||
duplicates: Literal["skip", "add", "ask"] = "skip"
|
||||
# Insert at this position among the playlist's CURRENT entries (a drop
|
||||
# between rows); None appends. Clamped to the list.
|
||||
index: int | None = None
|
||||
|
||||
|
||||
class MovePlaylist(BaseModel):
|
||||
@@ -545,6 +548,7 @@ class ImportRequest(BaseModel):
|
||||
# drop): every imported track — and every one the collection already
|
||||
# holds — goes into it, as folder add does.
|
||||
into_playlist: str | None = None
|
||||
into_playlist_index: int | None = None # where in it (see AddEntries.index)
|
||||
export_id: str | None = None
|
||||
|
||||
|
||||
@@ -613,6 +617,7 @@ class FolderAddRequest(BaseModel):
|
||||
mode: Literal["copy", "reference"]
|
||||
destination: str | None = None # required for `copy`
|
||||
playlist_id: str | None = None
|
||||
playlist_index: int | None = None # where in it (see AddEntries.index)
|
||||
export_id: str | None = None
|
||||
|
||||
|
||||
|
||||
@@ -181,7 +181,9 @@ with TestClient(main.app, raise_server_exceptions=False) as c:
|
||||
three_dir = music / "Deeper"
|
||||
c.get("/api/folder/tracks", params={"path": str(three_dir)})
|
||||
dest = Path(tempfile.mkdtemp()) / "Imported"
|
||||
req = {"track_ids": [str(three_dir / "three.flac")], "mode": "copy", "destination": str(dest)}
|
||||
# Dropped between the playlist's rows: inserted there, not appended.
|
||||
req = {"track_ids": [str(three_dir / "three.flac")], "mode": "copy", "destination": str(dest),
|
||||
"playlist_id": playlist, "playlist_index": 1}
|
||||
p = c.post("/api/folder/add/preview", json=req).json()
|
||||
check("the preview sizes the copy", p["total_bytes"] > 0, str(p))
|
||||
job = wait(c, c.post("/api/folder/add", json=req).json())
|
||||
@@ -191,6 +193,8 @@ with TestClient(main.app, raise_server_exceptions=False) as c:
|
||||
check("the entry points at the copy", a.audio_path(copied_id) == dest / "three.flac",
|
||||
str(a.audio_path(copied_id)))
|
||||
check("the original is untouched", (three_dir / "three.flac").is_file())
|
||||
check("it went into the playlist AT the index", a.playlist_entries(playlist) == [added, copied_id, new],
|
||||
str(a.playlist_entries(playlist)))
|
||||
check("copy without a destination is refused",
|
||||
c.post("/api/folder/add", json={"track_ids": [str(one)], "mode": "copy"}).status_code == 400)
|
||||
check("an unscanned file cannot be added",
|
||||
|
||||
@@ -191,6 +191,16 @@ check("'add' adds it again (Traktor can hold a track twice)", r["added"] == 1 an
|
||||
r = client.post(f"/api/playlists/{target}/add",
|
||||
json={"track_ids": track_ids[4:5], "duplicates": "ask"}).json()
|
||||
check("'ask' with nothing duplicated simply adds", r["status"] == "added" and r["added"] == 1)
|
||||
more = [t["id"] for t in client.get("/api/tracks", params={"limit": 50}).json()["items"]
|
||||
if t["id"] not in track_ids][:2]
|
||||
before = [t["id"] for t in client.get(f"/api/playlists/{target}/tracks").json()]
|
||||
r = client.post(f"/api/playlists/{target}/add", json={"track_ids": more[:1], "index": 1}).json()
|
||||
after = [t["id"] for t in client.get(f"/api/playlists/{target}/tracks").json()]
|
||||
check("an index inserts there (a drop between rows)",
|
||||
r["added"] == 1 and after == before[:1] + more[:1] + before[1:])
|
||||
client.post(f"/api/playlists/{target}/add", json={"track_ids": more[1:2], "index": 999})
|
||||
after = [t["id"] for t in client.get(f"/api/playlists/{target}/tracks").json()]
|
||||
check("an index past the end appends", after[-1] == more[1])
|
||||
check("capabilities say Traktor holds duplicates",
|
||||
client.get("/api/capabilities").json()["playlists"]["duplicates"] is True)
|
||||
|
||||
|
||||
@@ -511,7 +511,10 @@ with tempfile.TemporaryDirectory() as d:
|
||||
_raises(lambda: adapter.set_cue_color(cue_track.id, 6, red), NotFound))
|
||||
|
||||
print("== beatgrid edits ==")
|
||||
grid_track = next((t for t in adapter.tracks if t.bpm), None)
|
||||
# Long enough for a marker at 60 s: a grid is stored per beat, only up to
|
||||
# the track's end, and the library's first BPM track became a 1 s Sampler
|
||||
# WAV ("House 1"), where a marker at 60 s simply vanished.
|
||||
grid_track = next((t for t in adapter.tracks if t.bpm and (t.length or 0) >= 90), None)
|
||||
if grid_track:
|
||||
check("a gridded track starts with at least one marker",
|
||||
len(adapter.track_cues(grid_track.id).grid_markers) >= 1)
|
||||
|
||||
@@ -172,9 +172,16 @@ with TestClient(main.app) as c:
|
||||
got = ROOT / "folder-1.m4a"
|
||||
got.write_bytes(r.content)
|
||||
check("…and serves them", r.status_code == 200 and np.array_equal(decode(got), decode(stem, 2)))
|
||||
kinds = {t["id"]: t["media_kind"] for t in listing.json()["tracks"]}
|
||||
check("the listing marks the stem file as a stem track and the MP3 as audio",
|
||||
kinds.get(str(stem)) == "stem" and kinds.get(str(plain)) == "audio", str(kinds))
|
||||
# All three files are HELD, and a held file's row IS the collection track
|
||||
# (decided 2026-10-10): its id and media_kind are the collection's, so the
|
||||
# MP3 whose entry carries <STEMS> lists as a stem track. What the FILE says
|
||||
# is checked on loose files below.
|
||||
body = listing.json()
|
||||
kinds = {t["id"]: t["media_kind"] for t in body["tracks"]}
|
||||
check("held files list as their collection tracks, mapped back to the files",
|
||||
body["files"].get(stem_id) == str(stem) and body["files"].get(tagged_id) == str(tagged), str(body["files"]))
|
||||
check("…with the collection's media kind",
|
||||
kinds.get(tagged_id) == "stem" and kinds.get(plain_id) == "audio", str(kinds))
|
||||
|
||||
print("== adding a stem file to the collection ==")
|
||||
extra_dir = ROOT / "More"
|
||||
@@ -182,7 +189,11 @@ with TestClient(main.app) as c:
|
||||
extra = extra_dir / "Other.stem.m4a"
|
||||
shutil.copy2(stem, extra)
|
||||
extra_plain = make_mp3(extra_dir / "Other.mp3", seed=9)
|
||||
assert c.get("/api/folder/tracks", params={"path": str(extra_dir)}).status_code == 200
|
||||
loose = c.get("/api/folder/tracks", params={"path": str(extra_dir)})
|
||||
assert loose.status_code == 200
|
||||
kinds = {t["id"]: t["media_kind"] for t in loose.json()["tracks"]}
|
||||
check("a LOOSE stem file lists as a stem track (its box), the MP3 beside it as audio",
|
||||
kinds.get(str(extra)) == "stem" and kinds.get(str(extra_plain)) == "audio", str(kinds))
|
||||
pl_id = c.post("/api/playlists", json={"name": "Stem Adds"}).json()["id"]
|
||||
job = c.post("/api/folder/add", json={"track_ids": [str(extra), str(extra_plain)],
|
||||
"mode": "reference", "playlist_id": pl_id}).json()
|
||||
|
||||
Reference in new issue
Block a user