Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to cache sickbeard images #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion maraschino/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,13 @@
'value': '0',
'description': 'Show air date',
'type': 'bool',
},
},
{
'key': 'sickbeard_cache_img',
'value': '0',
'description': 'Cache images',
'type': 'bool',
},
]
},
{
Expand Down
39 changes: 37 additions & 2 deletions modules/sickbeard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import urllib2
import base64
import StringIO
import os
import time

from maraschino import app
from maraschino.tools import *
from threading import Thread
import maraschino


def sickbeard_http():
if get_setting_value('sickbeard_https') == '1':
return 'https://'
Expand Down Expand Up @@ -199,7 +201,10 @@ def history(limit):

# returns a link with the path to the required image from SB
def get_pic(tvdb, style='banner'):
return '%s/sickbeard/get_%s/%s' % (maraschino.WEBROOT, style, tvdb)
if get_setting_value('sickbeard_cache_img') == '1':
return cache_sickbeard_image(tvdb, style)
else:
return '%s/sickbeard/get_%s/%s' % (maraschino.WEBROOT, style, tvdb)


@app.route('/sickbeard/get_ep_info/<tvdbid>/<season>/<ep>/')
Expand Down Expand Up @@ -325,6 +330,36 @@ def get_poster(tvdbid):
return send_file(img, mimetype='image/jpeg')


def cache_sickbeard_image(tvdbid, img_type):
cache_dir = os.path.join(maraschino.DATA_DIR, 'cache', 'sickbeard')
create_dir(cache_dir)

file_path = os.path.join(cache_dir, '%s.%s.jpg' % (tvdbid, img_type))

if not os.path.exists(file_path):
image_path = '%s/?cmd=show.get%s&tvdbid=%s' % (sickbeard_url(), img_type, tvdbid)
Thread(target=download_image, args=(image_path, file_path)).start()
maraschino.THREADS.append(len(maraschino.THREADS) + 1)

while maraschino.THREADS:
time.sleep(1)

return sickbeard_image_file(tvdbid, img_type)


def sickbeard_image_file(tvdbid, img_type):
cache_dir = os.path.join(maraschino.DATA_DIR, 'cache', 'sickbeard')

filepath = os.path.join(cache_dir, '%s.%s.jpg' % (tvdbid, img_type))
if os.name == 'nt':
system = 'win'
else:
system = 'unix'
filepath = filepath[1:]

return '%s/cache/image_file/%s/%s' % (maraschino.WEBROOT, system, filepath)


@app.route('/sickbeard/log/<level>/')
def log(level):
params = '/?cmd=logs&min_level=%s' % level
Expand Down