Skip to content

Commit 8c39d14

Browse files
committed
Simplify the profile creation and equality checking (in context menu) to use the C++/Swig operator
1 parent 58f50fe commit 8c39d14

File tree

1 file changed

+9
-37
lines changed

1 file changed

+9
-37
lines changed

src/classes/query.py

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -261,43 +261,16 @@ def relative_path(self):
261261

262262
def profile(self):
263263
""" Get the profile of the file """
264-
# Create Profile object for current file
265-
d = self.data
266-
267-
# Calculate accurate DAR
268-
pixel_ratio = openshot.Fraction(d.get("pixel_ratio", {}))
269-
display_ratio = openshot.Fraction(d.get("display_ratio", {}))
270-
if display_ratio.num == 1 and display_ratio.den == 1:
271-
# Some audio / image files have inaccurate DAR - calculate from size
272-
display_ratio = openshot.Fraction(round(d.get("width", 1) * pixel_ratio.ToFloat()),
273-
round(d.get("height", 1) * pixel_ratio.ToFloat()))
274-
display_ratio.Reduce()
275-
276-
profile_dict = {
277-
"display_ratio":
278-
{
279-
"den": display_ratio.den,
280-
"num": display_ratio.num,
281-
},
282-
"fps":
283-
{
284-
"den": d.get("fps", {}).get("den", 1),
285-
"num": d.get("fps", {}).get("num", 1),
286-
},
287-
"height": d.get("height", 1),
288-
"progressive": not d.get("interlaced_frame", False),
289-
"pixel_format": d.get("pixel_format", None),
290-
"pixel_ratio":
291-
{
292-
"den": d.get("pixel_ratio", {}).get("den", 1),
293-
"num": d.get("pixel_ratio", {}).get("num", 1),
294-
},
295-
"width": d.get("width", 1)
296-
}
264+
# Load file Json into Profile object
297265
file_profile = openshot.Profile()
298-
file_profile.SetJson(json.dumps(profile_dict))
266+
file_profile.SetJson(json.dumps(self.data))
299267

300-
# Load all possible profiles
268+
if file_profile.info.display_ratio.num == 1 and file_profile.info.display_ratio.den == 1:
269+
# Some audio / image files have inaccurate DAR - calculate from size and pixel ratio
270+
file_profile.info.display_ratio = openshot.Fraction(round(file_profile.info.width * file_profile.info.pixel_ratio.ToFloat()), file_profile.info.height)
271+
file_profile.info.display_ratio.Reduce()
272+
273+
# Iterate through all possible profiles
301274
for profile_folder in [info.USER_PROFILES_PATH, info.PROFILES_PATH]:
302275
for file in reversed(sorted(os.listdir(profile_folder))):
303276
profile_path = os.path.join(profile_folder, file)
@@ -306,8 +279,7 @@ def profile(self):
306279
try:
307280
# Load Profile
308281
profile = openshot.Profile(profile_path)
309-
print(profile.Key(), file_profile.Key())
310-
if profile.Key() == file_profile.Key():
282+
if profile == file_profile:
311283
return profile
312284
except RuntimeError as e:
313285
pass

0 commit comments

Comments
 (0)