1313 "wikidatExtraUrls" :True ,
1414 "awards" : True ,
1515 "otherInfo" : True ,
16- "createTag" : True
17-
16+ "createTag" : True ,
17+ "overwrite" : False
1818}
1919
2020
5656 'P69' :'Educated At' ,
5757 'P102' :'Member of political party' ,
5858 'P551' :'Residence' ,
59- 'P3373' : 'Sibling'
59+ 'P3373' : 'Sibling' ,
60+ 'P26' :'Spouse'
6061}
6162
6263
6364
6465request_wd = requests .Session ()
66+ request_wd .headers .update ({'User-Agent' : 'stash extra performer info (https://github.com/stashapp/CommunityScripts/; ) generic-library/0.0' })
6567
6668wd_properties = {}
6769tags_cache = {}
@@ -70,9 +72,11 @@ def getWDPPropertyLabel(propertyId):
7072 if propertyId not in wd_properties :
7173 property_url = 'https://www.wikidata.org/wiki/Special:EntityData/%s.json' % (propertyId ,)
7274 wd2 = request_wd .get (property_url )
75+ # log.debug(wd2.status_code)
76+ # log.debug(wd2.content)
7377
7478 if wd2 .status_code == 200 :
75- log .debug (wd2 .json ())
79+ # log.debug(wd2.json())
7680# data2 = wd2.json()['entities']
7781 for k ,data2 in wd2 .json ()['entities' ].items ():
7882 if 'en' in data2 ['labels' ]:
@@ -101,8 +105,9 @@ def processWikidata(performer,performer_update,url):
101105 api_url = 'https://www.wikidata.org/wiki/Special:EntityData/%s.json' % (wikidata_id ,)
102106 log .debug ('about to fetch wikidata url: %s for performer %s' % (api_url ,performer ['name' ],))
103107 wd = request_wd .get (api_url )
108+ log .debug (wd .status_code )
104109 if wd .status_code == 200 :
105- # log.debug(wd.json().keys())
110+ log .debug (wd .json ().keys ())
106111
107112 data2 = wd .json ()['entities' ]
108113 data = data2 [next (iter (data2 ))]
@@ -154,33 +159,12 @@ def processWikidata(performer,performer_update,url):
154159 elif prop == 'P1411' :
155160 award ['type' ]= 'nominated'
156161
157-
162+ # Conferred by
158163 if 'P1027' in award ['wd' ]['claims' ].keys ():
159164 award ['conferred_wd' ]= getWDPPropertyLabel (award ['wd' ]['claims' ]['P1027' ][0 ]['mainsnak' ]['datavalue' ]['value' ]['id' ])
160165 award ['conferred' ] = award ['conferred_wd' ]['label' ]
161- if award ['type' ]== 'award received' :
162- if award ['conferred' ] not in award_totals :
163- award_totals [award ['conferred' ]]= 0
164- award_totals [award ['conferred' ]] = award_totals [award ['conferred' ]] + 1
165- if settings ['createTag' ]:
166- performer_update ['tag_names' ].append (
167- '[%s Award Winner]' % (award ['conferred' ],))
168-
169- else :
170- if award ['conferred' ] not in nominated_totals :
171- nominated_totals [award ['conferred' ]]= 0
172- nominated_totals [award ['conferred' ]] = nominated_totals [award ['conferred' ]] + 1
173- if settings ['createTag' ]:
174- performer_update ['tag_names' ].append ('[%s Award Nominated]' % (award ['conferred' ],))
175166 else :
176- if award ['type' ]== 'award received' :
177- if 'unknown' not in nominated_totals :
178- award_totals ['unknown' ] = 0
179- award_totals ['unknown' ] = award_totals ['unknown' ] + 1
180- else :
181- if 'unknown' not in nominated_totals :
182- nominated_totals ['unknown' ]= 0
183- nominated_totals ['unknown' ] = nominated_totals ['unknown' ] + 1
167+ award ['conferred' ] = 'unknown'
184168
185169
186170 # sublcass of, can be award for best scene
@@ -202,34 +186,58 @@ def processWikidata(performer,performer_update,url):
202186 if q == 'P805' :
203187 award ['venue_wd' ] = getWDPPropertyLabel (qv [0 ]['datavalue' ]['value' ]['id' ])
204188 award ['venue' ] = award ['venue_wd' ]['label' ]
205- # Award Rationale
206- if q == 'P6208' :
207- award ['name' ]= qv [0 ]['datavalue' ]['value' ]['text' ]
189+ # P6208: Award Rationale
190+ # P1932: object named as
191+ if q in ('P6208' ,'P6208' ):
192+ award ['name' ]= qv [0 ]['datavalue' ]['value' ]['text' ]
193+ if award .get ('conferred' ,'unknown' )== 'unknown' :
194+ award ['conferred' ]= award ['wd' ]['label' ]
208195
209196
197+ if 'conferred' in award :
198+ if award ['type' ]== 'award received' :
199+ if award ['conferred' ] not in award_totals :
200+ award_totals [award ['conferred' ]]= 0
201+ award_totals [award ['conferred' ]] = award_totals [award ['conferred' ]] + 1
202+ if settings ['createTag' ]:
203+ performer_update ['tag_names' ].append (
204+ '[%s Award Winner]' % (award ['conferred' ],))
205+ else :
206+ if award ['conferred' ] not in nominated_totals :
207+ nominated_totals [award ['conferred' ]]= 0
208+ nominated_totals [award ['conferred' ]] = nominated_totals [award ['conferred' ]] + 1
209+ if settings ['createTag' ]:
210+ performer_update ['tag_names' ].append ('[%s Award Nominated]' % (award ['conferred' ],))
210211
211212 if award :
212213# log.info('award: %s' % (award,))
213214 if 'custom_fields' not in performer_update :
214- performer_update ['custom_fields' ]= {'full' :performer ['custom_fields' ].copy ()}
215+ if settings ["overwrite" ]:
216+ performer_update ['custom_fields' ] = {'full' :{}}
217+ else :
218+ performer_update ['custom_fields' ]= {'full' :performer ['custom_fields' ].copy ()}
215219
216220 award_name = award ['name' ]
217221 award ['award_value' ]= award ['name' ]
218222 if 'venue' in award and 'time' in award :
219223 award ['award_value' ]= '%s - %s: %s' % (award ['time' ], award ['venue' ],award ['name' ],)
220- elif 'time' in award :
221- award ['award_value' ]= '%s: %s' % (award ['time' ],award ['name' ],)
222224 elif 'venue' in award :
223225 award ['award_value' ]= '%s: %s' % (award ['venue' ],award ['name' ],)
224-
226+ elif 'time' in award :
227+ if 'conferred' in award :
228+ if award ['conferred' ] != 'unknown' :
229+ award ['award_value' ] = '%s - %s: %s' % (award ['time' ],award ['conferred' ], award ['name' ],)
230+ else :
231+ award ['award_value' ] = '%s: %s' % (award ['time' ], award ['name' ],)
232+ else :
233+ award ['award_value' ] = '%s: %s' % (award ['time' ], award ['name' ],)
225234
226235 if award ['type' ]== 'award received' :
227236 won_award .append (award )
228237 if award ['type' ]== 'nominated' :
229238 award ['award_value' ]= '%s - Nominated' % award ['award_value' ]
230239 nominated_award .append (award )
231240 if award_name not in performer_update ['custom_fields' ]['full' ]:
232-
233241 performer_update ['custom_fields' ]['full' ][award_name ]= award ['award_value' ]
234242 performer_update ['update' ] = True
235243 else :
@@ -251,40 +259,17 @@ def processWikidata(performer,performer_update,url):
251259 ["%s: %s" % (k , v ,) for k , v in nominated_totals .items ()])
252260 performer_update ['update' ] = True
253261 if won_award :
254- # performer_update['custom_fields']['full']['json_awards'] = json.dumps([x[for x in won_award])
255262 performer_update ['custom_fields' ]['full' ]['Awards Won' ] = ', ' .join (
256263 [x ['award_value' ] for x in won_award ])
257264 if settings ['createTag' ]:
258265 performer_update ['tag_names' ].append ('[Award Winner]' )
259266 performer_update ['update' ] = True
260267 if nominated_award :
261- # performer_update['custom_fields']['full']['json_nominated'] = json.dumps(nominated_award)
262268 performer_update ['custom_fields' ]['full' ]['Awards Nominated' ] = ', ' .join (
263269 [x ['award_value' ] for x in nominated_award ])
264270 if settings ['createTag' ]:
265271 performer_update ['tag_names' ].append ('[Award Nominated]' )
266272 performer_update ['update' ] = True
267- # if settings['createTag']:
268- # if 'P31' in award['wd']['claims']:
269- # for c in award['wd']['claims']['P31']:
270- # log.debug('c %s' % (c,))
271- # # avn Award Q824540
272- # if c['mainsnak']['datavalue']['value']['id']=='Q824540':
273- # log.debug('---------------')
274- # if prop=='P166':
275- # performer_update['tag_names'].append('[AVN Award Winner]')
276- # performer_update['update'] = True
277- # elif prop=='P1411':
278- # performer_update['tag_names'].append('[AVN Award Nominated]')
279- # performer_update['update'] = True
280- #
281- # if settings['createTag']:
282- # if prop=='P166':
283- # performer_update['tag_names'].append('[Award Winner]')
284- # performer_update['update'] = True
285- # elif prop=='P1411':
286- # performer_update['tag_names'].append('[Award Nominated]')
287- # performer_update['update'] = True
288273 if settings ['otherInfo' ]:
289274 for claim , label in wikidata_field_properties .items ():
290275 if claim in data ['claims' ]:
@@ -373,7 +358,7 @@ def processPerformers():
373358
374359if "extraPerformerInfo" in config :
375360 settings .update (config ["extraPerformerInfo" ])
376- log .info ("config: %s " % (settings ,))
361+ log .debug ("config: %s " % (settings ,))
377362
378363
379364if "mode" in json_input ["args" ]:
@@ -385,6 +370,9 @@ def processPerformers():
385370 processPerformer (performer )
386371 else :
387372 processPerformers ()
373+ elif "processAllOverwrite" == PLUGIN_ARGS :
374+ settings ["overwrite" ]= True
375+ processPerformers ()
388376
389377elif "hookContext" in json_input ["args" ]:
390378 id = json_input ["args" ]["hookContext" ]["id" ]
0 commit comments