From b9d701f4e8ad886161a707d9b06d75e642437300 Mon Sep 17 00:00:00 2001 From: bwq Date: Thu, 5 Jul 2012 19:25:34 +0200 Subject: [PATCH 1/2] Added support for the XBMC Pneumatic plug-in. This downloads the nzb and creates an accompanying .strm file. --- .../core/downloaders/pneumatic/__init__.py | 37 ++++++++++++ .../core/downloaders/pneumatic/main.py | 57 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 couchpotato/core/downloaders/pneumatic/__init__.py create mode 100644 couchpotato/core/downloaders/pneumatic/main.py diff --git a/couchpotato/core/downloaders/pneumatic/__init__.py b/couchpotato/core/downloaders/pneumatic/__init__.py new file mode 100644 index 00000000..dedcde19 --- /dev/null +++ b/couchpotato/core/downloaders/pneumatic/__init__.py @@ -0,0 +1,37 @@ +from .main import Pneumatic + +def start(): + return Pneumatic() + +config = [{ + 'name': 'pneumatic', + 'order': 30, + 'groups': [ + { + 'tab': 'downloaders', + 'name': 'pneumatic', + 'label': 'Pneumatic', + 'description': 'Download the .strm file to a specific folder.', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + }, + { + 'name': 'directory', + 'type': 'directory', + 'description': 'Directory where the .strm file is saved to.', + }, + { + 'name': 'manual', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Disable this downloader for automated searches, but use it when I manually send a release.', + }, + ], + } + ], +}] diff --git a/couchpotato/core/downloaders/pneumatic/main.py b/couchpotato/core/downloaders/pneumatic/main.py new file mode 100644 index 00000000..6477889e --- /dev/null +++ b/couchpotato/core/downloaders/pneumatic/main.py @@ -0,0 +1,57 @@ +from __future__ import with_statement +from couchpotato.core.downloaders.base import Downloader +from couchpotato.core.logger import CPLog +import os +import traceback +import sys + +log = CPLog(__name__) + +class Pneumatic(Downloader): + + type = ['nzb'] + strm_syntax = 'plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb=%s&nzbname=%s' + + def download(self, data = {}, movie = {}, manual = False, filedata = None): + if self.isDisabled(manual) or (not self.isCorrectType(data.get('type'))): + return + + directory = self.conf('directory') + if not directory or not os.path.isdir(directory): + log.error('No directory set for .strm downloads.', data.get('type')) + else: + try: + if not filedata or len(filedata) < 50: + log.error('No nzb available!') + return False + + fullPath = os.path.join(directory, self.createFileName(data, filedata, movie)) + + try: + if not os.path.isfile(fullPath): + log.info('Downloading %s to %s.', (data.get('type'), fullPath)) + with open(fullPath, 'wb') as f: + f.write(filedata) + + nzb_name = self.createNzbName(data, movie) + strm_path = os.path.join(directory, nzb_name) + + strm_file = open(strm_path + '.strm', 'wb') + strmContent = self.strm_syntax % (fullPath, nzb_name) + strm_file.write(strmContent) + strm_file.close() + + return True + + else: + log.info('File %s already exists.', fullPath) + return True + + except: + log.error('Failed to download .strm', traceback.format_exc()) + pass + + except: + log.info('Failed to download file %s: %s', (data.get('name'), traceback.format_exc())) + return False + return False From fdb7855348e36bc54058fdd9e3b92d448033431e Mon Sep 17 00:00:00 2001 From: bwq Date: Thu, 5 Jul 2012 22:29:15 +0200 Subject: [PATCH 2/2] Small log fix. --- couchpotato/core/downloaders/pneumatic/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/downloaders/pneumatic/main.py b/couchpotato/core/downloaders/pneumatic/main.py index 6477889e..c518eff4 100644 --- a/couchpotato/core/downloaders/pneumatic/main.py +++ b/couchpotato/core/downloaders/pneumatic/main.py @@ -18,7 +18,7 @@ class Pneumatic(Downloader): directory = self.conf('directory') if not directory or not os.path.isdir(directory): - log.error('No directory set for .strm downloads.', data.get('type')) + log.error('No directory set for .strm downloads.') else: try: if not filedata or len(filedata) < 50: @@ -48,7 +48,7 @@ class Pneumatic(Downloader): return True except: - log.error('Failed to download .strm', traceback.format_exc()) + log.error('Failed to download .strm: %s', traceback.format_exc()) pass except: