Skip to content

Commit 4238b0a

Browse files
author
Jackson
committed
repair project files with invalid json for paths
1 parent 5468a9a commit 4238b0a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/classes/project_data.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def load(self, file_path, clear_thumbnails=True):
346346
default_project = self._data
347347

348348
try:
349+
self.quote_json_keys(file_path)
349350
# Attempt to load v2.X project file
350351
project_data = self.read_from_file(file_path, path_mode="absolute")
351352

@@ -647,7 +648,7 @@ def read_legacy_project_file(self, file_path):
647648
# Increment track counter
648649
track_counter += 1
649650

650-
except Exception:
651+
except Exception as ex:
651652
# Error parsing legacy contents
652653
msg = "Failed to load legacy project file %(path)s" % {"path": file_path}
653654
log.error(msg, exc_info=1)
@@ -720,6 +721,21 @@ def upgrade_project_data_structures(self):
720721
if self._data.get("id") == "T0":
721722
self._data["id"] = self.generate_id()
722723

724+
# Ensure projects can open
725+
# after PR #4211 introduced a bug
726+
# which wrote certain projects with invalid JSON.
727+
def quote_json_keys(self, file_path):
728+
import re
729+
730+
f = open(file_path)
731+
txt = f.read()
732+
f.close()
733+
newText = re.sub('(\n\s*)(\w*):', r'\1"\2":', txt)
734+
f = open(file_path, 'w')
735+
f.write(newText)
736+
f.close()
737+
return
738+
723739
def save(self, file_path, move_temp_files=True, make_paths_relative=True):
724740
""" Save project file to disk """
725741
import openshot

0 commit comments

Comments
 (0)