# Path: htpc/proxy.py
# def get_image(url, height=None, width=None, opacity=100, auth=None, headers=None):
#     """ Load image form cache if possible, else download. Resize if needed """
#     opacity = float(opacity)
#     logger = logging.getLogger('htpc.proxy')
# 
#     # Create image directory if it doesnt exist
#     imgdir = os.path.join(htpc.DATADIR, 'images/')
#     if not os.path.exists(imgdir):
#         logger.debug("Creating image directory at " + imgdir)
#         os.makedirs(imgdir)
# 
#     # Create a hash of the path to use as filename
#     imghash = hashlib.md5(url).hexdigest()
# 
#     # Set filename and path
#     image = os.path.join(imgdir, imghash)
# 
#     # If there is no local copy of the original
#     if not os.path.isfile(image):
#         logger.debug("No local image found for " + image + ". Downloading")
#         download_image(url, image, auth, headers)
# 
#     # Check if resize is needed
#     if (height and width) or (opacity < 100):
# 
#         if PIL:
#             # Set filename for resized file
#             resized = image + '_w' + width + '_h' + height + '_o' + str(opacity)
# 
#             # If there is no local resized copy
#             if not os.path.isfile(resized):
#                 resize_image(image, height, width, opacity, resized)
# 
#             # Serve the resized file
#             image = resized
#         else:
#             logger.error("Can't resize when PIL is missing on system!")
#             if (opacity < 100):
#                 image = os.path.join(htpc.RUNDIR, 'interfaces/default/img/fff_20.png')
# 
#     # Load file from disk
#     imagetype = imghdr.what(image)
#     if imagetype is not None:
#         return serve_file(path=image, content_type='image/' + imagetype)


import cherrypy
import htpc
import json
import logging
import hashlib
from htpc.proxy import get_image
from urllib2 import urlopen
from cherrypy.lib.auth2 import require
#!/usr/bin/env python
# -*- coding: utf-8 -*-



class Couchpotato:
    def __init__(self):
        self.logger = logging.getLogger('modules.couchpotato')
        htpc.MODULES.append({
            'name': 'CouchPotato',
            'id': 'couchpotato',
            'test': htpc.WEBDIR + 'couchpotato/getapikey',
            'fields': [
                {'type': 'bool', 'label': 'Enable', 'name': 'couchpotato_enable'},
                {'type': 'text', 'label': 'Menu name', 'name': 'couchpotato_name'},
                {'type': 'text', 'label': 'Username', 'name': 'couchpotato_username'},
                {'type': 'password', 'label': 'Password', 'name': 'couchpotato_password'},
                {'type': 'text', 'label': 'IP / Host *', 'name': 'couchpotato_host'},
                {'type': 'text', 'label': 'Port', 'placeholder':'5050', 'name': 'couchpotato_port'},
                {'type': 'text', 'label': 'Basepath', 'placeholder':'/couchpotato', 'name': 'couchpotato_basepath'},
                {'type': 'text', 'label': 'API key', 'desc': 'Press test get apikey', 'name': 'couchpotato_apikey'},
                {'type': 'bool', 'label': 'Use SSL', 'name': 'couchpotato_ssl'}
        ]})

    @cherrypy.expose()
    @require()
    def index(self):
        return htpc.LOOKUP.get_template('couchpotato.html').render(scriptname='couchpotato')


# Path: htpc/proxy.py
# def get_image(url, height=None, width=None, opacity=100, auth=None, headers=None):
#     """ Load image form cache if possible, else download. Resize if needed """
#     opacity = float(opacity)
#     logger = logging.getLogger('htpc.proxy')
# 
#     # Create image directory if it doesnt exist
#     imgdir = os.path.join(htpc.DATADIR, 'images/')
#     if not os.path.exists(imgdir):
#         logger.debug("Creating image directory at " + imgdir)
#         os.makedirs(imgdir)
# 
#     # Create a hash of the path to use as filename
#     imghash = hashlib.md5(url).hexdigest()
# 
#     # Set filename and path
#     image = os.path.join(imgdir, imghash)
# 
#     # If there is no local copy of the original
#     if not os.path.isfile(image):
#         logger.debug("No local image found for " + image + ". Downloading")
#         download_image(url, image, auth, headers)
# 
#     # Check if resize is needed
#     if (height and width) or (opacity < 100):
# 
#         if PIL:
#             # Set filename for resized file
#             resized = image + '_w' + width + '_h' + height + '_o' + str(opacity)
# 
#             # If there is no local resized copy
#             if not os.path.isfile(resized):
#                 resize_image(image, height, width, opacity, resized)
# 
#             # Serve the resized file
#             image = resized
#         else:
#             logger.error("Can't resize when PIL is missing on system!")
#             if (opacity < 100):
#                 image = os.path.join(htpc.RUNDIR, 'interfaces/default/img/fff_20.png')
# 
#     # Load file from disk
#     imagetype = imghdr.what(image)
#     if imagetype is not None:
#         return serve_file(path=image, content_type='image/' + imagetype)


# Path: modules/couchpotato.py
import cherrypy
import htpc
import json
import logging
import hashlib
from htpc.proxy import get_image
from urllib2 import urlopen
from cherrypy.lib.auth2 import require

#!/usr/bin/env python
# -*- coding: utf-8 -*-



class Couchpotato:
    def __init__(self):
        self.logger = logging.getLogger('modules.couchpotato')
        htpc.MODULES.append({
            'name': 'CouchPotato',
            'id': 'couchpotato',
            'test': htpc.WEBDIR + 'couchpotato/getapikey',
            'fields': [
                {'type': 'bool', 'label': 'Enable', 'name': 'couchpotato_enable'},
                {'type': 'text', 'label': 'Menu name', 'name': 'couchpotato_name'},
                {'type': 'text', 'label': 'Username', 'name': 'couchpotato_username'},
                {'type': 'password', 'label': 'Password', 'name': 'couchpotato_password'},
                {'type': 'text', 'label': 'IP / Host *', 'name': 'couchpotato_host'},
                {'type': 'text', 'label': 'Port', 'placeholder':'5050', 'name': 'couchpotato_port'},
                {'type': 'text', 'label': 'Basepath', 'placeholder':'/couchpotato', 'name': 'couchpotato_basepath'},
                {'type': 'text', 'label': 'API key', 'desc': 'Press test get apikey', 'name': 'couchpotato_apikey'},
                {'type': 'bool', 'label': 'Use SSL', 'name': 'couchpotato_ssl'}
        ]})

    @cherrypy.expose()
    @require()
    def index(self):
        return htpc.LOOKUP.get_template('couchpotato.html').render(scriptname='couchpotato')


    @cherrypy.expose()