|
HowToMakeProviderInPython
IntroductionThis article introduces how to make a provider in python language for foo_grabber_python extension. Caution: ALL functions which return string should be encoded in UTF-8 Quick StartFirst, you should create a script like this: # Inherited from grabber.LyricProviderBase is a good idea
# Becasue some behavior may change in the near future
from grabber import LyricProviderBase
class Your_Provider_Here(LyricProviderBase):
def GetName(self):
return "Your provider name"
def GetAuthor(self):
return "Authour name"
def GetDescription(self):
return "Your description here"
def GetURL(self):
return "http://put.yoursite.here"
def GetVersion(self):
return "0.1"
def Query(self, handles, status, abort):
result = []
for handle in handles:
# Do your stuff here
return result
# This is required
if __name__ == "__main__":
LyricProviderInstance = Your_Provider_Here()This script should work with foo_grabber_python, however, it make no sense for grabbing lyrics, for grabbing, here's more work to do Dive Into Query(self, handles, status, abort)This method is the most important part of LyricProviderBase, it controls the progress window, get if "Abort" button is pressed by user, return lyrics in list and so on. handlesa list of metadb handle used for titleformating, no properties or method in this variable besides __iter__ and next. So you should have enumerate handles like this: for handle in handles:
# Do some stuff herehandleA wrapper for metadb_handle object . Format(str)Format a titleformat script to plain text.
statusA wrapper for threaded_process_status object. Advance()Advance progress and update text in status window, add one percent each call. abortA wrapper for status_callback object. Aborting()Return True if "Abort" button is pressed. Helper ModulesThese modules are optional, but may be very useful for those who want to implement provider for web pages. Use: import module_name to import specified module. Html2TextAs its name convert html text to plain text, example: from Html2Text import ConvertHtmlToText print ConvertHtmlToText(html_text_here) LevenshteinDistancePython implemention for Levenshteion Distance, used for fuzzy string match. usage: from LevenshteinDistance import LevenshteinDistance i = LevenshteinDistance(str1, str2) pt = i / len(str2) LuckyHelper for returning a urllib.urlopen() object which contains web page using Google "I'm Feeling Lucky" feature. Raises exception of BadLuck when there's no luck... usage: from Lucky import GoogleLuck
o = GoogleLuck("keywords here", "site will go here or just leave it blank")
# Do some stuff for object o
| ||||||