Googlae Images cover provider script

This commit is contained in:
Paweł Bara 2011-04-02 13:47:51 +00:00
parent 032b5f7e48
commit 6d5e004758
5 changed files with 74 additions and 0 deletions

View File

@ -7,5 +7,6 @@ function(install_script_files scriptname)
endfunction(install_script_files)
add_subdirectory(digitallyimported-radio)
add_subdirectory(google-covers)
add_subdirectory(remove-duplicates)
add_subdirectory(invalidate-deleted)

View File

@ -0,0 +1,5 @@
install_script_files(google-covers
google_covers.py
icon.jpg
script.ini
)

View File

@ -0,0 +1,59 @@
import clementine
from PyQt4.QtCore import QString, QUrl
from PyQt4.QtNetwork import QNetworkRequest
from simplejson import loads
import urllib
class GoogleImagesCoversScript(clementine.CoverProvider):
def __init__(self):
clementine.CoverProvider.__init__(self, "Google Images")
self.api_url = 'https://ajax.googleapis.com/ajax/services/search/images?{0}'
self.api_args = {
'v' : '1.0',
# at most five results
'rsz' : '5'
}
self.network = clementine.NetworkAccessManager(self)
self.queries = {}
# register in the repository of cover providers
clementine.cover_providers.AddCoverProvider(self)
def SendRequest(self, query):
url = self.GetQueryURL(query)
reply = self.network.get(QNetworkRequest(url))
self.queries[reply] = query
return reply
def ParseReply(self, reply):
results = loads(str(reply.readAll()))
parsed = []
if 'Error' in results:
return parsed
query = self.queries.pop(reply)
for result in results['responseData']['results']:
current = clementine.CoverSearchResult()
current.description = query
current.image_url = QString(result['url'])
parsed.append(current)
return parsed
def GetQueryURL(self, query):
current_args = self.api_args.copy()
current_args['q'] = query
return QUrl(self.api_url.format(urllib.urlencode(current_args)))
script = GoogleImagesCoversScript()

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -0,0 +1,9 @@
[Script]
name=Google Images cover provider
description=Thanks to this script Clementine will be able to download covers from Google Images for you.
author=Pawel Bara <keirangtp ( at ) gmail.com>
url=http://www.clementine-player.org
icon=icon.jpg
language=python
script_file=google_covers.py