Skip to content

Commit

Permalink
Added the ability to override resizing the images served up from the …
Browse files Browse the repository at this point in the history
…cache if PIL is installed.

Add `--noresize` to command line argument so that the user could disable the use of PIL on resizing the poster/banner cached images. (ex: they need PIL for another python app but don't want PIL to be used for sb..)
Corrected the etree import so it mimics how tvdb_api does (will try cElementTree first then fall back to the slower non-C ElementTree)
  • Loading branch information
thezoggy committed Nov 26, 2012
1 parent 6795a92 commit adb4ea2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 6 additions & 2 deletions SickBeard.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def main():
threading.currentThread().name = "MAIN"

try:
opts, args = getopt.getopt(sys.argv[1:], "qfdp::", ['quiet', 'forceupdate', 'daemon', 'port=', 'pidfile=', 'nolaunch', 'config=', 'datadir=']) # @UnusedVariable
opts, args = getopt.getopt(sys.argv[1:], "qfdp::", ['quiet', 'forceupdate', 'port=', 'daemon', 'noresize', 'pidfile=', 'nolaunch', 'config=', 'datadir=']) # @UnusedVariable
except getopt.GetoptError:
print "Available Options: --quiet, --forceupdate, --port, --daemon, --pidfile, --config, --datadir"
print "Available Options: --quiet, --forceupdate, --port, --daemon, --noresize, --pidfile, --nolaunch, --config, --datadir"
sys.exit()

forceUpdate = False
Expand Down Expand Up @@ -198,6 +198,10 @@ def main():
consoleLogging = False
sickbeard.DAEMON = True

# Prevent resizing of the banner/posters even if PIL is installed
if o in ('--noresize',):
sickbeard.NO_RESIZE = True

# Specify folder to load the config file from
if o in ('--config',):
sickbeard.CONFIG_FILE = os.path.abspath(a)
Expand Down
1 change: 1 addition & 0 deletions sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
PIDFILE = ''

DAEMON = None
NO_RESIZE = False

backlogSearchScheduler = None
currentSearchScheduler = None
Expand Down
18 changes: 12 additions & 6 deletions sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
except ImportError:
from lib import simplejson as json

import xml.etree.cElementTree as etree
try:
import xml.etree.cElementTree as etree
except ImportError:
import xml.etree.ElementTree as etree

from sickbeard import browser

Expand Down Expand Up @@ -2690,7 +2693,7 @@ def get_messages(self):

return json.dumps(messages)


class WebInterface:

@cherrypy.expose
Expand All @@ -2716,14 +2719,17 @@ def showPoster(self, show=None, which=None):
return cherrypy.lib.static.serve_file(default_image_path, content_type="image/png")

cache_obj = image_cache.ImageCache()

if which == 'poster':
image_file_name = cache_obj.poster_path(showObj.tvdbid)
# this is for 'banner' but also the default case
else:
image_file_name = cache_obj.banner_path(showObj.tvdbid)

if ek.ek(os.path.isfile, image_file_name):
# use startup argument to prevent using PIL even if installed
if sickbeard.NO_RESIZE:
return cherrypy.lib.static.serve_file(image_file_name, content_type="image/jpeg")
try:
from PIL import Image
from cStringIO import StringIO
Expand All @@ -2740,10 +2746,10 @@ def showPoster(self, show=None, which=None):
else:
return cherrypy.lib.static.serve_file(image_file_name, content_type="image/jpeg")
im = im.resize(size, Image.ANTIALIAS)
buffer = StringIO()
im.save(buffer, 'JPEG', quality=85)
imgbuffer = StringIO()
im.save(imgbuffer, 'JPEG', quality=85)
cherrypy.response.headers['Content-Type'] = 'image/jpeg'
return buffer.getvalue()
return imgbuffer.getvalue()
else:
return cherrypy.lib.static.serve_file(default_image_path, content_type="image/png")

Expand Down

0 comments on commit adb4ea2

Please sign in to comment.