[packages/griffith] download posters, as griffith does not accept urls
glen
glen at pld-linux.org
Tue Jul 28 21:11:32 CEST 2015
commit 0a532283ecc175ec5f4300658ba09dee1af53420
Author: Elan Ruusamäe <glen at delfi.ee>
Date: Tue Jul 28 21:51:23 2015 +0300
download posters, as griffith does not accept urls
Kodi.py | 38 ++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/Kodi.py b/Kodi.py
index 5728c5a..3aa56f1 100644
--- a/Kodi.py
+++ b/Kodi.py
@@ -24,12 +24,9 @@ __revision__ = '$Id: $'
from plugins.imp import ImportPlugin as IP
import os
import gutils
-import string
-from xml.dom import minidom, Node
from lxml import etree
-import zipfile
-from shutil import rmtree
-from tempfile import mkdtemp
+import tempfile
+from urllib2 import urlopen, URLError, HTTPError
import logging
log = logging.getLogger("Griffith")
@@ -54,6 +51,7 @@ class ImportPlugin(IP):
xml = None
items = None
itemindex = 0
+ poster_file = None
# used by get_movie_details method
# griffith field => kodi field
@@ -109,6 +107,9 @@ class ImportPlugin(IP):
self.fileversion = None
self.items = None
self.itemindex = 0
+ if self.poster_file:
+ os.unlink(self.poster_file)
+ self.poster_file = None
def destroy(self):
"""close all resources"""
@@ -198,9 +199,34 @@ class ImportPlugin(IP):
# take first <thumb aspect="poster"> element
posters = item.xpath('thumb[@aspect="poster"]')
if posters:
- details['image'] = posters[0].get('preview')
+ self.poster_file = self.grab_url(posters[0].get('preview'), prefix = 'poster_', suffix = '.jpg')
+ details['image'] = self.poster_file
# increment for next iteration
self.itemindex = self.itemindex + 1
return details
+
+ # grab url, return temp filename with remote file contents
+ # XXX could not figure out how to use griffith own downloader with ui interaction, etc
+ # XXX: grabbing urls while processing import xml blocks the ui
+ def grab_url(self, url, prefix = None, suffix=None):
+ log.debug("Downloading: %s" % url)
+ (fd, local_file) = tempfile.mkstemp(suffix=suffix, prefix=prefix)
+ try:
+ f = urlopen(url)
+ os.write(fd, f.read())
+ os.close(fd)
+
+ except HTTPError, e:
+ log.error("HTTP Error: %s: %s" % (e.code, url))
+ return None
+ except URLError, e:
+ log.error("URL Error: %s: %s" % (e.reason, url))
+ return None
+ else:
+ return local_file
+
+ # we get here with an exception, cleanup and return None
+ os.unlink(local_file)
+ return None
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/griffith.git/commitdiff/2c3ca387ce67309451041fb9960aa7b787a36807
More information about the pld-cvs-commit
mailing list