2727
2828from bpy .types import Operator
2929from ...utils .lol import utils as utils
30- from ... import bl_info
31-
32- blc_ver = '.' .join ([str (_ ) for _ in bl_info ["version" ]])
33- useragent = f"BlendLuxCore/{ blc_ver } " # user agent for urllib request to LOL
34-
35-
30+ from ...utils import get_addon_preferences
3631
3732class LOLUpdateTOC (Operator ):
3833 bl_idname = 'scene.luxcore_ol_update_toc'
@@ -50,41 +45,45 @@ def execute(self, context):
5045 scene = context .scene
5146 ui_props = scene .luxcoreOL .ui
5247
53- name = 'bl_ext.user_default.' + basename (dirname (dirname (dirname (__file__ ))))
54- user_preferences = context .preferences .addons [name ].preferences
48+ user_preferences = get_addon_preferences (context )
49+ LOL_HOST_URL = user_preferences .lol_host
50+ LOL_VERSION = user_preferences .lol_version
51+ LOL_HTTP_HOST = user_preferences .lol_http_host
52+ LOL_USERAGENT = user_preferences .lol_useragent
53+
5554
5655 filepath = join (user_preferences .global_dir , 'assets_model_blendermarket.json' )
57- urlstr = utils . LOL_HOST_URL + "/" + utils . LOL_VERSION + "/assets_model_blendermarket.json"
56+ urlstr = LOL_HOST_URL + "/" + LOL_VERSION + "/assets_model_blendermarket.json"
5857
5958 req = urllib .request .Request (
60- urlstr , data = None , headers = {'User-Agent' : useragent }
59+ urlstr , headers = {'User-Agent' : LOL_USERAGENT , 'Host' : LOL_HTTP_HOST }
6160 )
62- with urllib .request .urlopen (req , timeout = 60 ) as request :
63- assets = json .load (request )
61+ with urllib .request .urlopen (req , timeout = 60 ) as response :
62+ assets = json .load (response )
6463
6564 with open (filepath , 'w' ) as file :
6665 file .write (json .dumps (assets , indent = 2 ))
6766
6867 filepath = join (user_preferences .global_dir , 'assets_model.json' )
69- urlstr = utils . LOL_HOST_URL + "/" + utils . LOL_VERSION + "/assets_model.json"
68+ urlstr = LOL_HOST_URL + "/" + LOL_VERSION + "/assets_model.json"
7069
7170 req = urllib .request .Request (
72- urlstr , data = None , headers = {'User-Agent' : useragent }
71+ urlstr , headers = {'User-Agent' : LOL_USERAGENT , 'Host' : LOL_HTTP_HOST }
7372 )
74- with urllib .request .urlopen (req , timeout = 60 ) as request :
75- assets = json .load (request )
73+ with urllib .request .urlopen (req , timeout = 60 ) as response :
74+ assets = json .load (response )
7675
7776 with open (filepath , 'w' ) as file :
7877 file .write (json .dumps (assets , indent = 2 ))
7978
8079 filepath = join (user_preferences .global_dir , 'assets_material.json' )
81- urlstr = utils . LOL_HOST_URL + "/" + utils . LOL_VERSION + "/assets_material.json"
80+ urlstr = LOL_HOST_URL + "/" + LOL_VERSION + "/assets_material.json"
8281
8382 req = urllib .request .Request (
84- urlstr , data = None , headers = {'User-Agent' : useragent }
83+ urlstr , headers = {'User-Agent' : LOL_USERAGENT , 'Host' : LOL_HTTP_HOST }
8584 )
86- with urllib .request .urlopen (req , timeout = 60 ) as request :
87- assets = json .load (request )
85+ with urllib .request .urlopen (req , timeout = 60 ) as response :
86+ assets = json .load (response )
8887
8988 with open (filepath , 'w' ) as file :
9089 file .write (json .dumps (assets , indent = 2 ))
0 commit comments