Googlae Images cover provider script
This commit is contained in:
parent
032b5f7e48
commit
6d5e004758
@ -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)
|
||||
|
5
scripts/google-covers/CMakeLists.txt
Normal file
5
scripts/google-covers/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
install_script_files(google-covers
|
||||
google_covers.py
|
||||
icon.jpg
|
||||
script.ini
|
||||
)
|
59
scripts/google-covers/google_covers.py
Normal file
59
scripts/google-covers/google_covers.py
Normal 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()
|
BIN
scripts/google-covers/icon.jpg
Normal file
BIN
scripts/google-covers/icon.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
9
scripts/google-covers/script.ini
Normal file
9
scripts/google-covers/script.ini
Normal 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
|
Loading…
x
Reference in New Issue
Block a user