Skip to content

Commit 09951ec

Browse files
author
Jackson
committed
Moved regex to read file
1 parent 4238b0a commit 09951ec

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/classes/json_data.py

+5
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,17 @@ def read_from_file(self, file_path, path_mode="ignore"):
153153
contents = f.read()
154154
if not contents:
155155
raise RuntimeError("Couldn't load {} file, no data.".format(self.data_type))
156+
157+
if os.path.splitext(file_path) and os.path.splitext(file_path)[1] == '.osp':
158+
# Repair lost quotes on json keys
159+
contents = re.sub('(\n\s*)(\w*):', r'\1"\2":', contents)
156160

157161
# Scan for and correct possible OpenShot 2.5.0 corruption
158162
if self.damage_re.search(contents) and self.version_re.search(contents):
159163
# File contains corruptions, backup and repair
160164
self.make_repair_backup(file_path, contents)
161165

166+
162167
# Repair lost slashes, then fix all corrupted escapes
163168
contents = self.slash_repair_re.sub(r'\1/\2', contents)
164169
contents, subs_count = self.damage_re.subn(r'\\u\1', contents)

src/classes/project_data.py

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

348348
try:
349-
self.quote_json_keys(file_path)
350349
# Attempt to load v2.X project file
351350
project_data = self.read_from_file(file_path, path_mode="absolute")
352351

@@ -721,21 +720,6 @@ def upgrade_project_data_structures(self):
721720
if self._data.get("id") == "T0":
722721
self._data["id"] = self.generate_id()
723722

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-
739723
def save(self, file_path, move_temp_files=True, make_paths_relative=True):
740724
""" Save project file to disk """
741725
import openshot

0 commit comments

Comments
 (0)