fix(mover): rename the folder on relocate so audiobookshelf keeps the item and its cover
Build image / image (push) Successful in 52s
Build image / image (push) Successful in 52s
This commit is contained in:
1 parent
b51d5754e0
commit
5f4b3cb564
5 files changed
+95
No files matched your search
@@ -753,6 +753,8 @@ def test_relocate_after_fixing_the_series(client):
|
||||
# a cover dropped next to the audio must survive the move
|
||||
(Path(dest) / "cover.jpg").write_bytes(b"")
|
||||
|
||||
inode = Path(dest).stat().st_ino
|
||||
|
||||
client.put(f"/api/requests/{req_id}", json={
|
||||
"library_id": lib_id, "title": "Philosopher's Stone",
|
||||
"series": "Harry Potter", "volume": 1,
|
||||
@@ -761,6 +763,8 @@ def test_relocate_after_fixing_the_series(client):
|
||||
assert res["ok"] and res["moved"]
|
||||
new = root / "Harry Potter" / "Philosopher's Stone"
|
||||
assert Path(res["dest"]) == new
|
||||
# a renamed folder, not a new one: Audiobookshelf keeps the item and its cover
|
||||
assert new.stat().st_ino == inode
|
||||
assert sorted(p.name for p in new.iterdir()) == [
|
||||
"Philosopher's Stone - Part 01.mp3", "Philosopher's Stone - Part 02.mp3", "cover.jpg",
|
||||
]
|
||||
@@ -769,6 +773,45 @@ def test_relocate_after_fixing_the_series(client):
|
||||
"imported_path"] == str(new)
|
||||
|
||||
|
||||
|
||||
def test_the_folder_series_replaces_the_requests_on_import(client):
|
||||
"""Hardcover counts "Tote Augen" as Will Trent 3, the German release as Georgia 1."""
|
||||
root = client.tmp_path / "library" / "german"
|
||||
lib_id = client.post("/api/libraries", json={
|
||||
"name": "german", "media_type": "audiobook", "root_path": str(root),
|
||||
"folder_template": "{Series}/{Volume} - {Title}", "file_template": "{Title}",
|
||||
}).json()["id"]
|
||||
req_id = client.post("/api/requests", json={
|
||||
"library_id": lib_id, "title": "Tote Augen", "authors": "Karin Slaughter",
|
||||
"series": "Will Trent", "volume": 3,
|
||||
}).json()["id"]
|
||||
|
||||
def import_folder(name, **override):
|
||||
src = client.downloads / name
|
||||
src.mkdir()
|
||||
(src / "01.mp3").write_bytes(b"")
|
||||
return client.post("/api/import", json={"items": [{
|
||||
"path": str(src), "is_dir": True, "files": [str(src / "01.mp3")],
|
||||
"request_id": req_id, **override,
|
||||
}]}).json()["results"][0]
|
||||
|
||||
# a failed import must not leave the folder's series behind
|
||||
(root / "Georgia" / "01 - Tote Augen").mkdir(parents=True)
|
||||
(root / "Georgia" / "01 - Tote Augen" / "Tote Augen.mp3").write_bytes(b"")
|
||||
failed = import_folder("broken", series="Georgia", volume=1)
|
||||
assert not failed["ok"]
|
||||
req = client.get("/api/requests", params={"status": "missing"}).json()[0]
|
||||
assert (req["series"], req["volume"]) == ("Will Trent", 3)
|
||||
shutil.rmtree(root / "Georgia")
|
||||
|
||||
result = import_folder("Karin Slaughter - Georgia 01 - Tote Augen",
|
||||
series="Georgia", volume=1)
|
||||
assert result["ok"], result
|
||||
assert Path(result["dest"]).parent == root / "Georgia" / "01 - Tote Augen"
|
||||
req = client.get("/api/requests", params={"status": "imported"}).json()[0]
|
||||
assert (req["series"], req["volume"]) == ("Georgia", 1)
|
||||
|
||||
|
||||
def test_relocate_is_a_no_op_when_nothing_changed(client):
|
||||
root = client.tmp_path / "library" / "l"
|
||||
lib_id = client.post("/api/libraries", json={
|
||||
|
||||
Reference in new issue
Block a user