File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,11 +131,31 @@ def filter_downloads(
131131 download_folders = asset .get ("downloadFolders" , {})
132132 default_folder = download_folders .get ("default" , {})
133133 filetype_categories = default_folder .get ("downloadFiletypeCategories" , {})
134- zip_category = filetype_categories .get ("zip" , {})
135- download_list = zip_category .get ("downloads" , [])
134+
135+ if isinstance (filetype_categories , dict ):
136+ zip_category = filetype_categories .get ("zip" , {})
137+ elif isinstance (filetype_categories , list ):
138+ zip_category = next (
139+ (
140+ category
141+ for category in filetype_categories
142+ if isinstance (category , dict ) and category .get ("title" ) == "zip"
143+ ),
144+ {},
145+ )
146+ else :
147+ zip_category = {}
148+
149+ download_list = (
150+ zip_category .get ("downloads" , []) if isinstance (zip_category , dict ) else []
151+ )
152+ if not isinstance (download_list , list ):
153+ continue
136154
137155 # Find matching download.
138156 for download in download_list :
157+ if not isinstance (download , dict ):
158+ continue
139159 if download .get ("attribute" ) == target_attribute :
140160 downloads .append (
141161 MaterialDownload (
Original file line number Diff line number Diff line change 1+ from scripts .download_ambientcg import filter_downloads
2+
3+
4+ def test_filter_downloads_skips_empty_filetype_category_lists () -> None :
5+ downloads = filter_downloads (
6+ assets = [
7+ {
8+ "assetId" : "Ground102" ,
9+ "downloadFolders" : {
10+ "default" : {
11+ "downloadFiletypeCategories" : [],
12+ },
13+ },
14+ },
15+ {
16+ "assetId" : "Wood095" ,
17+ "downloadFolders" : {
18+ "default" : {
19+ "downloadFiletypeCategories" : {
20+ "zip" : {
21+ "downloads" : [
22+ {
23+ "attribute" : "2K-PNG" ,
24+ "downloadLink" : (
25+ "https://ambientcg.com/get?"
26+ "file=Wood095_2K-PNG.zip"
27+ ),
28+ "fileName" : "Wood095_2K-PNG.zip" ,
29+ "size" : 34016478 ,
30+ },
31+ ],
32+ },
33+ },
34+ },
35+ },
36+ },
37+ ],
38+ resolution = "2K" ,
39+ file_format = "PNG" ,
40+ )
41+
42+ assert len (downloads ) == 1
43+ assert downloads [0 ].asset_id == "Wood095"
44+ assert downloads [0 ].file_name == "Wood095_2K-PNG.zip"
45+
46+
47+ def test_filter_downloads_handles_list_filetype_categories () -> None :
48+ downloads = filter_downloads (
49+ assets = [
50+ {
51+ "assetId" : "Rock064" ,
52+ "downloadFolders" : {
53+ "default" : {
54+ "downloadFiletypeCategories" : [
55+ {
56+ "title" : "zip" ,
57+ "downloads" : [
58+ {
59+ "attribute" : "2K-JPG" ,
60+ "downloadLink" : (
61+ "https://ambientcg.com/get?"
62+ "file=Rock064_2K-JPG.zip"
63+ ),
64+ "fileName" : "Rock064_2K-JPG.zip" ,
65+ "size" : 28438777 ,
66+ },
67+ ],
68+ },
69+ ],
70+ },
71+ },
72+ },
73+ ],
74+ resolution = "2K" ,
75+ file_format = "JPG" ,
76+ )
77+
78+ assert len (downloads ) == 1
79+ assert downloads [0 ].asset_id == "Rock064"
80+ assert downloads [0 ].file_name == "Rock064_2K-JPG.zip"
You can’t perform that action at this time.
0 commit comments