From 7ce8a4fc4556b6441d404ca097a24e48f7873f2d Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 16 Sep 2012 13:21:01 +0200 Subject: [PATCH 1/6] Show proper date in update info --- couchpotato/static/scripts/page/about.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/static/scripts/page/about.js b/couchpotato/static/scripts/page/about.js index 8ac38ba6..d155800f 100644 --- a/couchpotato/static/scripts/page/about.js +++ b/couchpotato/static/scripts/page/about.js @@ -116,7 +116,7 @@ var AboutSettingTab = new Class({ if(!json) return; var self = this; var date = new Date(json.version.date * 1000); - self.version_text.set('text', json.version.hash + ' ('+date.toUTCString()+')'); + self.version_text.set('text', json.version.hash + (json.version.date ? ' ('+date.toLocaleString()+')' : '')); self.updater_type.set('text', json.version.type); } From 4be8d02cbb80a0b62778371006f5a2023fccca5b Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 16 Sep 2012 17:47:14 +0200 Subject: [PATCH 2/6] Added CP search & info provider --- .../providers/movie/couchpotatoapi/main.py | 55 ++++++++++++++++--- .../core/providers/movie/themoviedb/main.py | 4 +- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/couchpotato/core/providers/movie/couchpotatoapi/main.py b/couchpotato/core/providers/movie/couchpotatoapi/main.py index d1c13380..ed574a24 100644 --- a/couchpotato/core/providers/movie/couchpotatoapi/main.py +++ b/couchpotato/core/providers/movie/couchpotatoapi/main.py @@ -1,10 +1,12 @@ from couchpotato import get_session from couchpotato.core.event import addEvent, fireEvent +from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.request import jsonified, getParams from couchpotato.core.logger import CPLog from couchpotato.core.providers.movie.base import MovieProvider from couchpotato.core.settings.model import Movie from flask.helpers import json +import traceback log = CPLog(__name__) @@ -12,28 +14,57 @@ log = CPLog(__name__) class CouchPotatoApi(MovieProvider): api_url = 'http://couchpota.to/api/%s/' + urls = { + 'search': 'https://couchpota.to/api/search/%s/', + 'info': 'https://couchpota.to/api/info/%s/', + 'eta': 'https://couchpota.to/api/eta/%s/', + } http_time_between_calls = 0 + api_version = 1 def __init__(self): #addApiView('movie.suggest', self.suggestView) - addEvent('movie.info', self.getInfo) + addEvent('movie.info', self.getInfo, priority = 1) + addEvent('movie.search', self.search, priority = 1) addEvent('movie.release_date', self.getReleaseDate) + def search(self, q, limit = 12): + + cache_key = 'cpapi.cache.%s' % q + cached = self.getCache(cache_key, self.urls['search'] % tryUrlencode(q), timeout = 3) + + if cached: + try: + movies = json.loads(cached) + return movies + except: + log.error('Failed parsing search results: %s', traceback.format_exc()) + + return [] + def getInfo(self, identifier = None): - return { - 'release_date': self.getReleaseDate(identifier) - } + + if not identifier: + return + + cache_key = 'cpapi.cache.info.%s' % identifier + cached = self.getCache(cache_key, self.urls['info'] % identifier, timeout = 3) + + if cached: + try: + movie = json.loads(cached) + return movie + except: + log.error('Failed parsing info results: %s', traceback.format_exc()) + + return {} def getReleaseDate(self, identifier = None): if identifier is None: return {} try: - headers = { - 'X-CP-Version': fireEvent('app.version', single = True), - 'X-CP-API': 1, - } - data = self.urlopen((self.api_url % ('eta')) + (identifier + '/'), headers = headers) + data = self.urlopen((self.api_url % ('eta')) + (identifier + '/'), headers = self.getRequestHeaders()) dates = json.loads(data) log.debug('Found ETA for %s: %s', (identifier, dates)) return dates @@ -71,3 +102,9 @@ class CouchPotatoApi(MovieProvider): 'count': len(suggestions), 'suggestions': suggestions }) + + def getRequestHeaders(self): + return { + 'X-CP-Version': fireEvent('app.version', single = True), + 'X-CP-API': self.api_version, + } diff --git a/couchpotato/core/providers/movie/themoviedb/main.py b/couchpotato/core/providers/movie/themoviedb/main.py index 9f9fe4fe..8b15a5c4 100644 --- a/couchpotato/core/providers/movie/themoviedb/main.py +++ b/couchpotato/core/providers/movie/themoviedb/main.py @@ -11,8 +11,8 @@ class TheMovieDb(MovieProvider): def __init__(self): addEvent('movie.by_hash', self.byHash) - addEvent('movie.search', self.search, priority = 1) - addEvent('movie.info', self.getInfo, priority = 1) + addEvent('movie.search', self.search, priority = 2) + addEvent('movie.info', self.getInfo, priority = 2) addEvent('movie.info_by_tmdb', self.getInfoByTMDBId) # Use base wrapper From ef7fc62c66e797f96ffba44c6958ad86edc15252 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 16 Sep 2012 19:25:53 +0200 Subject: [PATCH 3/6] Download fanart en bigger poster when needed --- couchpotato/core/plugins/library/main.py | 10 ++++++---- couchpotato/core/providers/metadata/base.py | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/plugins/library/main.py b/couchpotato/core/plugins/library/main.py index d24dfca6..ae142299 100644 --- a/couchpotato/core/plugins/library/main.py +++ b/couchpotato/core/plugins/library/main.py @@ -111,18 +111,20 @@ class LibraryPlugin(Plugin): # Files images = info.get('images', []) - for type in images: - for image in images[type]: - if not isinstance(image, str): + for image_type in ['poster']: + for image in images.get(image_type, []): + if not isinstance(image, (str, unicode)): continue file_path = fireEvent('file.download', url = image, single = True) if file_path: - file_obj = fireEvent('file.add', path = file_path, type_tuple = ('image', type), single = True) + file_obj = fireEvent('file.add', path = file_path, type_tuple = ('image', image_type), single = True) try: file_obj = db.query(File).filter_by(id = file_obj.get('id')).one() library.files.append(file_obj) db.commit() + + break except: log.debug('Failed to attach to library: %s', traceback.format_exc()) diff --git a/couchpotato/core/providers/metadata/base.py b/couchpotato/core/providers/metadata/base.py index a10f9c82..cf2e303f 100644 --- a/couchpotato/core/providers/metadata/base.py +++ b/couchpotato/core/providers/metadata/base.py @@ -74,9 +74,18 @@ class MetaDataBase(Plugin): if file_type.get('identifier') == wanted_file_type: break + # See if it is in current files for cur_file in data['library'].get('files', []): if cur_file.get('type_id') is file_type.get('id') and os.path.isfile(cur_file.get('path')): return cur_file.get('path') + # Download using existing info + try: + images = data['library']['info']['images'][wanted_file_type] + file_path = fireEvent('file.download', url = images[0], single = True) + return file_path + except: + pass + def getFanart(self, movie_info = {}, data = {}): return self.getThumbnail(movie_info = movie_info, data = data, wanted_file_type = 'backdrop_original') From ce3efd3a3c941b5aab26cd19fb670daa361e1f56 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 16 Sep 2012 20:02:15 +0200 Subject: [PATCH 4/6] Cleanup cache on startup --- couchpotato/core/plugins/file/main.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/couchpotato/core/plugins/file/main.py b/couchpotato/core/plugins/file/main.py index 5f381198..40427e44 100644 --- a/couchpotato/core/plugins/file/main.py +++ b/couchpotato/core/plugins/file/main.py @@ -8,6 +8,7 @@ from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import FileType, File from couchpotato.environment import Env import os.path +import time import traceback log = CPLog(__name__) @@ -28,6 +29,25 @@ class FileManager(Plugin): 'return': {'type': 'file'} }) + addEvent('app.load', self.cleanup) + + def cleanup(self): + + # Wait a bit after starting before cleanup + time.sleep(3) + log.debug('Cleaning up unused files') + + try: + db = get_session() + for root, dirs, walk_files in os.walk(Env.get('cache_dir')): + for filename in walk_files: + file_path = os.path.join(root, filename) + f = db.query(File).filter(File.path == toUnicode(file_path)).first() + if not f: + os.remove(file_path) + except: + log.error('Failed removing unused file: %s', traceback.format_exc()) + def showCacheFile(self, filename = ''): cache_dir = Env.get('cache_dir') From 8fb24bb101bc7443440bca9f956c1c486c728573 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 16 Sep 2012 20:20:47 +0200 Subject: [PATCH 5/6] Couldn't test Synoindex. fix #814 --- couchpotato/core/notifications/synoindex/main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/notifications/synoindex/main.py b/couchpotato/core/notifications/synoindex/main.py index 93d6cdbd..89c54de7 100644 --- a/couchpotato/core/notifications/synoindex/main.py +++ b/couchpotato/core/notifications/synoindex/main.py @@ -1,4 +1,5 @@ from couchpotato.core.event import addEvent +from couchpotato.core.helpers.request import jsonified from couchpotato.core.logger import CPLog from couchpotato.core.notifications.base import Notification import subprocess @@ -9,13 +10,14 @@ log = CPLog(__name__) class Synoindex(Notification): def __init__(self): + super(Synoindex, self).__init__() addEvent('renamer.after', self.addToLibrary) def addToLibrary(self, group = {}): if self.isDisabled(): return - command = ['/usr/syno/bin/synoindex', '-A', group.get('destination_dir')] - log.info(u'Executing synoindex command: %s ', command) + command = ['/usr/syno/bin/synoindex', '-A', group.get('destination_dir', '')] + log.info('Executing synoindex command: %s ', command) try: p = subprocess.Popen(command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) out = p.communicate() @@ -26,3 +28,7 @@ class Synoindex(Notification): return False return True + + def test(self): + success = self.addToLibrary() + return jsonified({'success': success}) From 20f81d06c06ef8c47ec644557f35a501b3d47624 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 16 Sep 2012 20:44:10 +0200 Subject: [PATCH 6/6] Send headers with CPAPI --- couchpotato/core/providers/movie/couchpotatoapi/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/providers/movie/couchpotatoapi/main.py b/couchpotato/core/providers/movie/couchpotatoapi/main.py index ed574a24..0ada5c9f 100644 --- a/couchpotato/core/providers/movie/couchpotatoapi/main.py +++ b/couchpotato/core/providers/movie/couchpotatoapi/main.py @@ -32,7 +32,7 @@ class CouchPotatoApi(MovieProvider): def search(self, q, limit = 12): cache_key = 'cpapi.cache.%s' % q - cached = self.getCache(cache_key, self.urls['search'] % tryUrlencode(q), timeout = 3) + cached = self.getCache(cache_key, self.urls['search'] % tryUrlencode(q), timeout = 3, headers = self.getRequestHeaders()) if cached: try: @@ -49,7 +49,7 @@ class CouchPotatoApi(MovieProvider): return cache_key = 'cpapi.cache.info.%s' % identifier - cached = self.getCache(cache_key, self.urls['info'] % identifier, timeout = 3) + cached = self.getCache(cache_key, self.urls['info'] % identifier, timeout = 3, headers = self.getRequestHeaders()) if cached: try: