Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimas committed Jan 18, 2025
1 parent e185828 commit f027d40
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
65 changes: 32 additions & 33 deletions open_dubbing/utterance.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,45 +233,44 @@ def update_utterances(self, utterance_master, utterance_update):
for utterance in utterance_master:
id = utterance["id"]

create = id_to_create.get(id, None)
if create:
new_id = self._get_highest_id(utterance_master) + 1
new_utterance = self._create_new_utterance(create, new_id)
if new_utterance:
utterance_new.append(new_utterance)

update = id_to_update_or_delete.get(id, None)
if not update:
utterance_new.append(utterance)
continue

operation = update.get("operation", None)
if not operation:
raise ValueError("No operation field defined")

if operation == "delete":
continue
else:
operation = update.get("operation", None)
if not operation:
raise ValueError("No operation field defined")

if operation != "update":
raise ValueError(f"Invalid operation {operation}")

updateable_fields = [
"speaker_id",
"translated_text",
"speed",
"assigned_voice",
"for_dubbing",
"gender",
"start",
"end",
]
for field in updateable_fields:
value = update.get(field, None)
if not value:
if operation == "delete":
continue

utterance[field] = value
if operation != "update":
raise ValueError(f"Invalid operation {operation}")

updateable_fields = [
"speaker_id",
"translated_text",
"speed",
"assigned_voice",
"for_dubbing",
"gender",
"start",
"end",
]
for field in updateable_fields:
value = update.get(field, None)
if not value:
continue

utterance[field] = value

utterance_new.append(utterance)
utterance_new.append(utterance)

create = id_to_create.get(id, None)
if create:
new_id = self._get_highest_id(utterance_master) + 1
new_utterance = self._create_new_utterance(create, new_id)
if new_utterance:
utterance_new.append(new_utterance)

return utterance_new
5 changes: 3 additions & 2 deletions tests/utterance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ def test_update_utterances_operation_create(self):
new_utterances = utterance.update_utterances(master, create_utterances)
print(f"new_utterances: {new_utterances}")
assert len(new_utterances) == 3
assert new_utterances[0]["id"] == 3
assert new_utterances[1]["id"] == 1
assert new_utterances[0]["id"] == 1
assert new_utterances[1]["id"] == 3
assert new_utterances[2]["id"] == 2

def test_update_utterances_operation_delete(self):

Expand Down

0 comments on commit f027d40

Please sign in to comment.