@@ -221,13 +221,32 @@ def set_datetime(self, datetime: Datetime, asset: Optional[Asset] = None) -> Non
221
221
else :
222
222
asset .extra_fields ["datetime" ] = datetime_to_str (datetime )
223
223
224
- def get_assets (self ) -> Dict [str , Asset ]:
224
+ def get_assets (
225
+ self ,
226
+ media_type : Optional [Union [str , pystac .MediaType ]] = None ,
227
+ role : Optional [str ] = None ,
228
+ ) -> Dict [str , Asset ]:
225
229
"""Get this item's assets.
226
230
231
+ Args:
232
+ media_type: If set, filter the assets such that only those with a
233
+ matching ``media_type`` are returned.
234
+ role: If set, filter the assets such that only those with a matching
235
+ ``role`` are returned.
236
+
227
237
Returns:
228
- Dict[str, Asset]: A copy of the dictionary of this item's assets.
238
+ Dict[str, Asset]: A dictionary of assets that match ``media_type``
239
+ and/or ``role`` if set or else all of this item's assets.
229
240
"""
230
- return dict (self .assets .items ())
241
+ if media_type is None and role is None :
242
+ return dict (self .assets .items ())
243
+ assets = dict ()
244
+ for key , asset in self .assets .items ():
245
+ if (media_type is None or asset .media_type == media_type ) and (
246
+ role is None or asset .has_role (role )
247
+ ):
248
+ assets [key ] = asset
249
+ return assets
231
250
232
251
def add_asset (self , key : str , asset : Asset ) -> None :
233
252
"""Adds an Asset to this item.
0 commit comments