|
1 |
| -""" |
| 1 | +""" |
2 | 2 | @file
|
3 | 3 | @brief This file can easily query Clips, Files, and other project data
|
4 | 4 | @author Jonathan Thomas <[email protected]>
|
5 |
| - |
| 5 | +
|
6 | 6 | @section LICENSE
|
7 |
| - |
| 7 | +
|
8 | 8 | Copyright (c) 2008-2018 OpenShot Studios, LLC
|
9 | 9 | (http://www.openshotstudios.com). This file is part of
|
10 | 10 | OpenShot Video Editor (http://www.openshot.org), an open-source project
|
11 | 11 | dedicated to delivering high quality video editing and animation solutions
|
12 | 12 | to the world.
|
13 |
| - |
| 13 | +
|
14 | 14 | OpenShot Video Editor is free software: you can redistribute it and/or modify
|
15 | 15 | it under the terms of the GNU General Public License as published by
|
16 | 16 | the Free Software Foundation, either version 3 of the License, or
|
17 | 17 | (at your option) any later version.
|
18 |
| - |
| 18 | +
|
19 | 19 | OpenShot Video Editor is distributed in the hope that it will be useful,
|
20 | 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 | 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 | 22 | GNU General Public License for more details.
|
23 |
| - |
| 23 | +
|
24 | 24 | You should have received a copy of the GNU General Public License
|
25 | 25 | along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
26 | 26 | """
|
|
32 | 32 | from classes.app import get_app
|
33 | 33 |
|
34 | 34 |
|
35 |
| - |
36 | 35 | # Get project data reference
|
37 | 36 | app = get_app()
|
38 | 37 | project = app.project
|
@@ -97,33 +96,42 @@ def filter(OBJECT_TYPE, **kwargs):
|
97 | 96 |
|
98 | 97 | # Get a list of all objects of this type
|
99 | 98 | parent = project.get(OBJECT_TYPE.object_key)
|
| 99 | + |
| 100 | + if not parent: |
| 101 | + return [] |
| 102 | + |
100 | 103 | matching_objects = []
|
101 | 104 |
|
102 | 105 | # Loop through all children objects
|
103 |
| - if parent: |
104 |
| - for child in parent: |
105 |
| - |
106 |
| - # Loop through all kwargs (and look for matches) |
107 |
| - match = True |
108 |
| - for key, value in kwargs.items(): |
109 |
| - # Equals |
110 |
| - if key in child and not child[key] == value: |
| 106 | + for child in parent: |
| 107 | + |
| 108 | + # Protect against non-iterable/subscriptables |
| 109 | + if not child: |
| 110 | + continue |
| 111 | + |
| 112 | + # Loop through all kwargs (and look for matches) |
| 113 | + match = True |
| 114 | + for key, value in kwargs.items(): |
| 115 | + |
| 116 | + # Equals |
| 117 | + if key in child and not child[key] == value: |
| 118 | + match = False |
| 119 | + break |
| 120 | + |
| 121 | + # Intersection Position |
| 122 | + if key == "intersect": |
| 123 | + if (child.get("position", 0) > value or |
| 124 | + child.get("position", 0) + (child.get("end", 0) - child.get("start", 0)) < value): |
111 | 125 | match = False
|
112 |
| - break |
113 |
| - # Intersection Position |
114 |
| - elif key == "intersect": |
115 |
| - if child.get("position", 0) > value or \ |
116 |
| - child.get("position", 0) + (child.get("end", 0) - child.get("start", 0)) < value: |
117 |
| - match = False |
118 |
| - |
119 |
| - # Add matched record |
120 |
| - if match: |
121 |
| - object = OBJECT_TYPE() |
122 |
| - object.id = child["id"] |
123 |
| - object.key = [OBJECT_TYPE.object_name, {"id": object.id}] |
124 |
| - object.data = copy.deepcopy(child) # copy of object |
125 |
| - object.type = "update" |
126 |
| - matching_objects.append(object) |
| 126 | + |
| 127 | + # Add matched record |
| 128 | + if match: |
| 129 | + object = OBJECT_TYPE() |
| 130 | + object.id = child["id"] |
| 131 | + object.key = [OBJECT_TYPE.object_name, {"id": object.id}] |
| 132 | + object.data = copy.deepcopy(child) # copy of object |
| 133 | + object.type = "update" |
| 134 | + matching_objects.append(object) |
127 | 135 |
|
128 | 136 | # Return matching objects
|
129 | 137 | return matching_objects
|
|
0 commit comments