fix(downloads): disambiguate the media path by asset id (C-3.1)
A MediaAsset is unique on (source_kind, source_ref, format_sig), so the same video in
two formats is two assets — but rel_path keyed only on video_id, so they computed the
same path: the second download silently overwrote the first, and deleting either
removed the shared file. rel_path now takes an optional asset_id and appends "_a{id}"
(which Plex ignores — the .nfo sidecar carries the metadata); the worker passes the
asset id. Only affects NEW downloads (existing assets keep their stored rel_path).
Covered by a new test (two ids → two paths; omitted → the plain name, unchanged).
This commit is contained in:
@@ -54,6 +54,16 @@ class TestRelPath:
|
||||
out = rel_path(meta, "mp4")
|
||||
assert "Season_0/" in out and "0000-00-00" in out
|
||||
|
||||
def test_asset_id_disambiguates_two_formats_of_the_same_video(self):
|
||||
# Same video, two assets (e.g. 1080p vs 720p) must NOT collide on one path.
|
||||
a = rel_path(self.meta, "mp4", asset_id=5)
|
||||
b = rel_path(self.meta, "mp4", asset_id=6)
|
||||
assert a != b
|
||||
assert a.endswith("_[abc123]_a5.mp4") and b.endswith("_[abc123]_a6.mp4")
|
||||
# Omitting it keeps the plain name (unchanged for callers/tests that don't pass one).
|
||||
assert rel_path(self.meta, "mp4", layout="flat") == "Cool_Clip_[abc123].mp4"
|
||||
assert rel_path(self.meta, "mp4", layout="flat", asset_id=7) == "Cool_Clip_[abc123]_a7.mp4"
|
||||
|
||||
|
||||
class TestDownloadFilename:
|
||||
def test_appends_the_container_extension(self):
|
||||
|
||||
Reference in New Issue
Block a user