33
33
import os
34
34
import re
35
35
36
+ from classes .assets import get_assets_path
36
37
from classes .logger import log
37
38
from classes import info
38
39
@@ -162,15 +163,19 @@ def replace_string_to_absolute(self, match):
162
163
163
164
# Find absolute path of file (if needed)
164
165
utf_path = json .loads ('"%s"' % path , encoding = "utf-8" ) # parse bytestring into unicode string
165
- if "@transitions" not in utf_path :
166
- # Convert path to the correct relative path (based on the existing folder)
167
- new_path = os .path .abspath (os .path .join (path_context .get ("existing_project_folder" , "" ), utf_path ))
166
+ if "@transitions" in utf_path :
167
+ new_path = path .replace ("@transitions" , os .path .join (info .PATH , "transitions" ))
168
+ new_path = json .dumps (new_path ) # Escape backslashes
169
+ return '"%s": %s' % (key , new_path )
170
+
171
+ elif "@assets" in utf_path :
172
+ new_path = path .replace ("@assets" , path_context ["new_project_assets" ])
168
173
new_path = json .dumps (new_path ) # Escape backslashes
169
174
return '"%s": %s' % (key , new_path )
170
175
171
- # Determine if @transitions path is found
172
176
else :
173
- new_path = path .replace ("@transitions" , os .path .join (info .PATH , "transitions" ))
177
+ # Convert path to the correct relative path
178
+ new_path = os .path .abspath (os .path .join (path_context .get ("new_project_folder" , "" ), utf_path ))
174
179
new_path = json .dumps (new_path ) # Escape backslashes
175
180
return '"%s": %s' % (key , new_path )
176
181
@@ -180,6 +185,8 @@ def convert_paths_to_absolute(self, file_path, data):
180
185
# Get project folder
181
186
path_context ["new_project_folder" ] = os .path .dirname (file_path )
182
187
path_context ["existing_project_folder" ] = os .path .dirname (file_path )
188
+ path_context ["new_project_assets" ] = get_assets_path (file_path , create_paths = False )
189
+ path_context ["existing_project_assets" ] = get_assets_path (file_path , create_paths = False )
183
190
184
191
# Optimized regex replacement
185
192
data = re .sub (path_regex , self .replace_string_to_absolute , data )
@@ -213,6 +220,16 @@ def replace_string_to_relative(self, match):
213
220
new_path = json .dumps (new_path ) # Escape backslashes
214
221
return '"%s": %s' % (key , new_path )
215
222
223
+ # Determine if @assets path is found
224
+ elif path_context ["new_project_assets" ] in folder_path :
225
+ # Yes, this is an OpenShot transitions
226
+ folder_path = folder_path .replace (path_context ["new_project_assets" ], "@assets" )
227
+
228
+ # Convert path to @transitions/ path
229
+ new_path = os .path .join (folder_path , file_path ).replace ("\\ " , "/" )
230
+ new_path = json .dumps (new_path ) # Escape backslashes
231
+ return '"%s": %s' % (key , new_path )
232
+
216
233
# Find absolute path of file (if needed)
217
234
else :
218
235
# Convert path to the correct relative path (based on the existing folder)
@@ -232,9 +249,12 @@ def convert_paths_to_relative(self, file_path, previous_path, data):
232
249
try :
233
250
# Get project folder
234
251
path_context ["new_project_folder" ] = os .path .dirname (file_path )
252
+ path_context ["new_project_assets" ] = get_assets_path (file_path , create_paths = False )
235
253
path_context ["existing_project_folder" ] = os .path .dirname (file_path )
236
- if previous_path :
254
+ path_context ["existing_project_assets" ] = get_assets_path (file_path , create_paths = False )
255
+ if previous_path and file_path != previous_path :
237
256
path_context ["existing_project_folder" ] = os .path .dirname (previous_path )
257
+ path_context ["existing_project_assets" ] = get_assets_path (previous_path , create_paths = False )
238
258
239
259
# Optimized regex replacement
240
260
data = re .sub (path_regex , self .replace_string_to_relative , data )
0 commit comments