From 9f6e4cc2fad0d11407e91fba16038c5e72577795 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 8 Oct 2014 20:46:11 +0200 Subject: [PATCH 1/3] Remove NotifyMyWP --- couchpotato/core/notifications/notifymywp.py | 68 ---------- libs/pynmwp/__init__.py | 134 ------------------- 2 files changed, 202 deletions(-) delete mode 100644 couchpotato/core/notifications/notifymywp.py delete mode 100644 libs/pynmwp/__init__.py diff --git a/couchpotato/core/notifications/notifymywp.py b/couchpotato/core/notifications/notifymywp.py deleted file mode 100644 index 262fd8d1..00000000 --- a/couchpotato/core/notifications/notifymywp.py +++ /dev/null @@ -1,68 +0,0 @@ -from couchpotato.core.helpers.variable import splitString -from couchpotato.core.logger import CPLog -from couchpotato.core.notifications.base import Notification -from pynmwp import PyNMWP -import six - -log = CPLog(__name__) - -autoload = 'NotifyMyWP' - - -class NotifyMyWP(Notification): - - def notify(self, message = '', data = None, listener = None): - if not data: data = {} - - keys = splitString(self.conf('api_key')) - p = PyNMWP(keys, self.conf('dev_key')) - - response = p.push(application = self.default_title, event = message, description = message, priority = self.conf('priority'), batch_mode = len(keys) > 1) - - for key in keys: - if not response[key]['Code'] == six.u('200'): - log.error('Could not send notification to NotifyMyWindowsPhone (%s). %s', (key, response[key]['message'])) - return False - - return response - - -config = [{ - 'name': 'notifymywp', - 'groups': [ - { - 'tab': 'notifications', - 'list': 'notification_providers', - 'name': 'notifymywp', - 'label': 'Windows Phone', - 'options': [ - { - 'name': 'enabled', - 'default': 0, - 'type': 'enabler', - }, - { - 'name': 'api_key', - 'description': 'Multiple keys seperated by a comma. Maximum of 5.' - }, - { - 'name': 'dev_key', - 'advanced': True, - }, - { - 'name': 'priority', - 'default': 0, - 'type': 'dropdown', - 'values': [('Very Low', -2), ('Moderate', -1), ('Normal', 0), ('High', 1), ('Emergency', 2)], - }, - { - 'name': 'on_snatch', - 'default': 0, - 'type': 'bool', - 'advanced': True, - 'description': 'Also send message when movie is snatched.', - }, - ], - } - ], -}] diff --git a/libs/pynmwp/__init__.py b/libs/pynmwp/__init__.py deleted file mode 100644 index de724b9d..00000000 --- a/libs/pynmwp/__init__.py +++ /dev/null @@ -1,134 +0,0 @@ -from xml.dom.minidom import parseString -from httplib import HTTPSConnection -from urllib import urlencode - -__version__ = "0.1" - -API_SERVER = 'notifymywindowsphone.com' -ADD_PATH = '/publicapi/notify' - -USER_AGENT = "PyNMWP/v%s" % __version__ - -def uniq_preserve(seq): # Dave Kirby - # Order preserving - seen = set() - return [x for x in seq if x not in seen and not seen.add(x)] - -def uniq(seq): - # Not order preserving - return {}.fromkeys(seq).keys() - -class PyNMWP(object): - """PyNMWP(apikey=[], developerkey=None) -takes 2 optional arguments: - - (opt) apykey: might me a string containing 1 key or an array of keys - - (opt) developerkey: where you can store your developer key -""" - - def __init__(self, apikey = [], developerkey = None): - self._developerkey = None - self.developerkey(developerkey) - if apikey: - if type(apikey) == str: - apikey = [apikey] - self._apikey = uniq(apikey) - - def addkey(self, key): - "Add a key (register ?)" - if type(key) == str: - if not key in self._apikey: - self._apikey.append(key) - elif type(key) == list: - for k in key: - if not k in self._apikey: - self._apikey.append(k) - - def delkey(self, key): - "Removes a key (unregister ?)" - if type(key) == str: - if key in self._apikey: - self._apikey.remove(key) - elif type(key) == list: - for k in key: - if key in self._apikey: - self._apikey.remove(k) - - def developerkey(self, developerkey): - "Sets the developer key (and check it has the good length)" - if type(developerkey) == str and len(developerkey) == 48: - self._developerkey = developerkey - - def push(self, application = "", event = "", description = "", url = "", priority = 0, batch_mode = False): - """Pushes a message on the registered API keys. -takes 5 arguments: - - (req) application: application name [256] - - (req) event: event name [1000] - - (req) description: description [10000] - - (opt) url: url [512] - - (opt) priority: from -2 (lowest) to 2 (highest) (def:0) - - (opt) batch_mode: call API 5 by 5 (def:False) - -Warning: using batch_mode will return error only if all API keys are bad - cf: http://nma.usk.bz/api.php -""" - datas = { - 'application': application[:256].encode('utf8'), - 'event': event[:1024].encode('utf8'), - 'description': description[:10000].encode('utf8'), - 'priority': priority - } - - if url: - datas['url'] = url[:512] - - if self._developerkey: - datas['developerkey'] = self._developerkey - - results = {} - - if not batch_mode: - for key in self._apikey: - datas['apikey'] = key - res = self.callapi('POST', ADD_PATH, datas) - results[key] = res - else: - for i in range(0, len(self._apikey), 5): - datas['apikey'] = ",".join(self._apikey[i:i + 5]) - res = self.callapi('POST', ADD_PATH, datas) - results[datas['apikey']] = res - return results - - def callapi(self, method, path, args): - headers = { 'User-Agent': USER_AGENT } - if method == "POST": - headers['Content-type'] = "application/x-www-form-urlencoded" - http_handler = HTTPSConnection(API_SERVER) - http_handler.request(method, path, urlencode(args), headers) - resp = http_handler.getresponse() - - try: - res = self._parse_reponse(resp.read()) - except Exception, e: - res = {'type': "pynmwperror", - 'code': 600, - 'message': str(e) - } - pass - - return res - - def _parse_reponse(self, response): - root = parseString(response).firstChild - for elem in root.childNodes: - if elem.nodeType == elem.TEXT_NODE: continue - if elem.tagName == 'success': - res = dict(elem.attributes.items()) - res['message'] = "" - res['type'] = elem.tagName - return res - if elem.tagName == 'error': - res = dict(elem.attributes.items()) - res['message'] = elem.firstChild.nodeValue - res['type'] = elem.tagName - return res - From 259e2bc61ced9d8a65e1c64bb35f6747a2e77375 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 8 Oct 2014 21:58:34 +0200 Subject: [PATCH 2/3] Don't skip unpacking on manage scan --- couchpotato/core/plugins/manage.py | 2 +- couchpotato/core/plugins/scanner.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/plugins/manage.py b/couchpotato/core/plugins/manage.py index 75c550bf..b0e1239c 100755 --- a/couchpotato/core/plugins/manage.py +++ b/couchpotato/core/plugins/manage.py @@ -123,7 +123,7 @@ class Manage(Plugin): fireEvent('notify.frontend', type = 'manage.update', data = True, message = 'Scanning for movies in "%s"' % folder) onFound = self.createAddToLibrary(folder, added_identifiers) - fireEvent('scanner.scan', folder = folder, simple = True, newer_than = last_update if not full else 0, on_found = onFound, single = True) + fireEvent('scanner.scan', folder = folder, simple = True, newer_than = last_update if not full else 0, check_file_date = False, on_found = onFound, single = True) # Break if CP wants to shut down if self.shuttingDown(): diff --git a/couchpotato/core/plugins/scanner.py b/couchpotato/core/plugins/scanner.py index a7a5e88e..aca9e641 100644 --- a/couchpotato/core/plugins/scanner.py +++ b/couchpotato/core/plugins/scanner.py @@ -131,7 +131,7 @@ class Scanner(Plugin): addEvent('scanner.name_year', self.getReleaseNameYear) addEvent('scanner.partnumber', self.getPartNumber) - def scan(self, folder = None, files = None, release_download = None, simple = False, newer_than = 0, return_ignored = True, on_found = None): + def scan(self, folder = None, files = None, release_download = None, simple = False, newer_than = 0, return_ignored = True, check_file_date = True, on_found = None): folder = sp(folder) @@ -145,7 +145,6 @@ class Scanner(Plugin): # Scan all files of the folder if no files are set if not files: - check_file_date = True try: files = [] for root, dirs, walk_files in os.walk(folder, followlinks=True): From 3c12a2c4bf8d25491b210d91bcfbe2b3ca349233 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 8 Oct 2014 22:35:56 +0200 Subject: [PATCH 3/3] Don't restatus movies to active when scanning manage section --- couchpotato/core/media/_base/media/main.py | 4 ++-- couchpotato/core/plugins/manage.py | 4 ++-- couchpotato/core/plugins/release/main.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/media/_base/media/main.py b/couchpotato/core/media/_base/media/main.py index aa1ee382..bd42b9d0 100755 --- a/couchpotato/core/media/_base/media/main.py +++ b/couchpotato/core/media/_base/media/main.py @@ -491,7 +491,7 @@ class MediaPlugin(MediaBase): } }) - def restatus(self, media_id, tag_recent = True): + def restatus(self, media_id, tag_recent = True, allowed_restatus = None): try: db = get_db() @@ -526,7 +526,7 @@ class MediaPlugin(MediaBase): m['status'] = previous_status # Only update when status has changed - if previous_status != m['status']: + if previous_status != m['status'] and (not allowed_restatus or m['status'] in allowed_restatus): db.update(m) # Tag media as recent diff --git a/couchpotato/core/plugins/manage.py b/couchpotato/core/plugins/manage.py index b0e1239c..3c22ee3d 100755 --- a/couchpotato/core/plugins/manage.py +++ b/couchpotato/core/plugins/manage.py @@ -218,8 +218,8 @@ class Manage(Plugin): if group['media'] and group['identifier']: added_identifiers.append(group['identifier']) - # Add it to release and update the info - fireEvent('release.add', group = group, update_info = False) + # Add it to release and update the info (only allow media restatus to done, not to active) + fireEvent('release.add', group = group, update_info = False, allowed_restatus = ['done']) fireEvent('movie.update', identifier = group['identifier'], on_complete = self.createAfterUpdate(folder, group['identifier'])) return addToLibrary diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index 815cb404..a937eee2 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -129,7 +129,7 @@ class Release(Plugin): if 'recent' in media.get('tags', []): fireEvent('media.untag', media.get('_id'), 'recent', single = True) - def add(self, group, update_info = True, update_id = None): + def add(self, group, update_info = True, update_id = None, allowed_restatus = None): try: db = get_db() @@ -187,7 +187,7 @@ class Release(Plugin): release['files'] = dict((k, [toUnicode(x) for x in v]) for k, v in group['files'].items() if v) db.update(release) - fireEvent('media.restatus', media['_id'], single = True) + fireEvent('media.restatus', media['_id'], allowed_restatus = allowed_restatus, single = True) return True except: