Skip to content

Commit ae2e801

Browse files
committed
feat: Add title in add_ingredient_file
if no title exists use the filename from the path.
1 parent 8020ba8 commit ae2e801

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

c2pa/c2pa_api/c2pa_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def add_ingredient(self, ingredient, format, stream):
114114

115115
def add_ingredient_file(self, ingredient, path):
116116
format = os.path.splitext(path)[1][1:]
117+
if "title" not in ingredient:
118+
if isinstance(ingredient, str):
119+
ingredient = json.loads(ingredient)
120+
ingredient["title"] = os.path.basename(path)
117121
with open(path, "rb") as file:
118122
return self.add_ingredient(ingredient, format, file)
119123

tests/test_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def getitem(d, key):
5151
]
5252
}
5353

54+
ingredient_def = {
55+
"relationship": "parentOf",
56+
"thumbnail": {
57+
"identifier": "A.jpg",
58+
"format": "image/jpeg"
59+
}
60+
}
61+
5462
def test_v2_read_cloud_manifest():
5563
reader = Reader.from_file("tests/fixtures/cloud.jpg")
5664
manifest = reader.get_active_manifest()
@@ -108,6 +116,8 @@ def sign(data: bytes) -> bytes:
108116
signer = create_signer(sign, SigningAlg.PS256, certs, "http://timestamp.digicert.com")
109117

110118
builder = Builder(manifest_def)
119+
120+
builder.add_ingredient_file(ingredient_def, data_dir + "A.jpg")
111121

112122
builder.add_resource_file("A.jpg", data_dir + "A.jpg")
113123

@@ -132,6 +142,8 @@ def sign(data: bytes) -> bytes:
132142
assert manifest,["format"] == "image/jpeg"
133143
# There should be no validation status errors
134144
assert manifest.get("validation_status") == None
145+
assert manifest["ingredients"][0]["relationship"] == "parentOf"
146+
assert manifest["ingredients"][0]["title"] == "A.jpg"
135147
except Exception as e:
136148
print("Failed to sign manifest store: " + str(e))
137149
exit(1)

0 commit comments

Comments
 (0)