My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
HowToMakeProviderInPython  
How to create python scripts for foo_grabber_python
Featured, Phase-Deploy
Updated Feb 4, 2010 by ColdNeve...@gmail.com

Introduction

This 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 Start

First, 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.

handles

a 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 here

handle

A wrapper for metadb_handle object .

Format(str)

Format a titleformat script to plain text.

Param Purpose
str titleformat script
return titleformatted string

status

A wrapper for threaded_process_status object.

Advance()

Advance progress and update text in status window, add one percent each call.

abort

A wrapper for status_callback object.

Aborting()

Return True if "Abort" button is pressed.

Helper Modules

These 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.

Html2Text

As its name convert html text to plain text, example:

from Html2Text import ConvertHtmlToText

print ConvertHtmlToText(html_text_here)

LevenshteinDistance

Python implemention for Levenshteion Distance, used for fuzzy string match.

usage:

from LevenshteinDistance import LevenshteinDistance

i = LevenshteinDistance(str1, str2)
pt = i / len(str2)

Lucky

Helper 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

Sign in to add a comment
Powered by Google Project Hosting