mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 11:19:18 +01:00
2b22dfaaee
add cover size tooltip (see issue #1704) cover search window is now a grid and not a long list with vertical scrollbar
62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
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',
|
|
# only larger sizes
|
|
'imgsz' : 'large|xlarge'
|
|
}
|
|
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()
|