@@ -149,24 +149,6 @@ def resolve(self,url,**kwargs):
149149
150150 return None
151151
152- class PluginResolver (object ):
153- def resolve (self ,url ,** kwargs ):
154- plugins = {}
155- path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'plugins' )
156- sys .path .insert (0 , path )
157- for plugin_file in os .listdir (path ):
158- filename , extension = os .path .splitext (plugin_file )
159- if extension == '.py' and filename != '__init__' :
160- mod = __import__ (filename )
161- plugins [filename ] = mod .Plugin ()
162- sys .path .pop (0 )
163-
164- for plugin in plugins .values ():
165- image = plugin .get_image (url )
166- if image :
167- return image
168- return None
169-
170152class WebpageResolver (object ):
171153 def __init__ (self ,** kwargs ):
172154 self .load_images = kwargs .get ('load_images' ,True )
@@ -261,12 +243,35 @@ def _score(self,image):
261243
262244 return score
263245
246+ def plugin_resolve (self ,url ,soup ,** kwargs ):
247+ plugins = {}
248+ path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'plugins' )
249+ sys .path .insert (0 , path )
250+ for plugin_file in os .listdir (path ):
251+ filename , extension = os .path .splitext (plugin_file )
252+ if extension == '.py' and filename != '__init__' :
253+ mod = __import__ (filename )
254+ plugins [filename ] = mod .Plugin ()
255+ sys .path .pop (0 )
256+
257+ for plugin in plugins .values ():
258+ image = plugin .get_image (url ,soup )
259+ if image :
260+ return image
261+ return None
262+
263+
264264 def resolve (self ,url ,** kwargs ):
265265 logger .debug ('Resolving as a webpage ' + str (url ))
266-
267266 ir = ImageResolver ()
268267 content = ir .fetch (url )
269268 soup = BeautifulSoup (content ,self .parser )
269+
270+ plugin_image = self .plugin_resolve (url ,soup )
271+
272+ if plugin_image :
273+ return plugin_image
274+
270275 images = soup .find_all ('img' )
271276
272277 candidates = []
0 commit comments