diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index 504ddac8..6fa6a915 100644 --- a/couchpotato/core/downloaders/base.py +++ b/couchpotato/core/downloaders/base.py @@ -56,7 +56,7 @@ class Downloader(Plugin): return is_correct def magnetToTorrent(self, magnet_link): - torrent_hash = re.findall('urn:btih:([\w]{32,40})', magnet_link)[0] + torrent_hash = re.findall('urn:btih:([\w]{32,40})', magnet_link)[0].upper() # Convert base 32 to hex if len(torrent_hash) == 32: diff --git a/couchpotato/core/downloaders/sabnzbd/main.py b/couchpotato/core/downloaders/sabnzbd/main.py index abff97d7..0151cc47 100644 --- a/couchpotato/core/downloaders/sabnzbd/main.py +++ b/couchpotato/core/downloaders/sabnzbd/main.py @@ -2,8 +2,8 @@ from couchpotato.core.downloaders.base import Downloader from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.logger import CPLog -import traceback import json +import traceback log = CPLog(__name__) @@ -91,15 +91,19 @@ class Sabnzbd(Downloader): log.error('Failed parsing json status: %s', traceback.format_exc()) return False - for slot in history['queue']['slots']: - log.debug('Found %s in SabNZBd queue, which is %s, with %s left', (slot['filename'], slot['status'], slot['timeleft'])) - if slot['filename'] == nzbname: - return slot['status'].lower() + try: + for slot in history['queue']['slots']: + log.debug('Found %s in SabNZBd queue, which is %s, with %s left', (slot['filename'], slot['status'], slot['timeleft'])) + if slot['filename'] == nzbname: + return slot['status'].lower() + except: + log.debug('No items in queue: %s', (traceback.format_exc())) # Go through history items params = { 'apikey': self.conf('api_key'), 'mode': 'history', + 'limit': 15, 'output': 'json' } url = cleanHost(self.conf('host')) + "api?" + tryUrlencode(params) @@ -117,45 +121,48 @@ class Sabnzbd(Downloader): log.error('Failed parsing history json: %s', traceback.format_exc()) return - for slot in history['history']['slots']: - log.debug('Found %s in SabNZBd history, which has %s', (slot['name'], slot['status'])) - if slot['name'] == nzbname: - # Note: if post process even if failed is on in SabNZBd, it will complete with a fail message - if slot['status'] == 'Failed' or (slot['status'] == 'Completed' and slot['fail_message'].strip()): + try: + for slot in history['history']['slots']: + log.debug('Found %s in SabNZBd history, which has %s', (slot['name'], slot['status'])) + if slot['name'] == nzbname: + # Note: if post process even if failed is on in SabNZBd, it will complete with a fail message + if slot['status'] == 'Failed' or (slot['status'] == 'Completed' and slot['fail_message'].strip()): - # Delete failed download - if self.conf('delete_failed', default = True): + # Delete failed download + if self.conf('delete_failed', default = True): - log.info('%s failed downloading, deleting...', slot['name']) - params = { - 'apikey': self.conf('api_key'), - 'mode': 'history', - 'name': 'delete', - 'del_files': '1', - 'value': slot['nzo_id'] - } - url = cleanHost(self.conf('host')) + "api?" + tryUrlencode(params) + log.info('%s failed downloading, deleting...', slot['name']) + params = { + 'apikey': self.conf('api_key'), + 'mode': 'history', + 'name': 'delete', + 'del_files': '1', + 'value': slot['nzo_id'] + } + url = cleanHost(self.conf('host')) + "api?" + tryUrlencode(params) - try: - sab = self.urlopen(url, timeout = 60, show_error = False) - except: - log.error('Failed deleting: %s', traceback.format_exc()) - return False + try: + sab = self.urlopen(url, timeout = 60, show_error = False) + except: + log.error('Failed deleting: %s', traceback.format_exc()) + return False - result = sab.strip() - if not result: - log.error("SABnzbd didn't return anything.") + result = sab.strip() + if not result: + log.error("SABnzbd didn't return anything.") - log.debug("Result text from SAB: " + result[:40]) - if result == "ok": - log.info('SabNZBd deleted failed release %s successfully.', slot['name']) - elif result == "Missing authentication": - log.error("Incorrect username/password or API?.") - else: - log.error("Unknown error: " + result[:40]) + log.debug("Result text from SAB: " + result[:40]) + if result == "ok": + log.info('SabNZBd deleted failed release %s successfully.', slot['name']) + elif result == "Missing authentication": + log.error("Incorrect username/password or API?.") + else: + log.error("Unknown error: " + result[:40]) - return 'failed' - else: - return slot['status'].lower() + return 'failed' + else: + return slot['status'].lower() + except: + log.debug('No items in history: %s', (traceback.format_exc())) return 'not_found' diff --git a/couchpotato/core/notifications/synoindex/main.py b/couchpotato/core/notifications/synoindex/main.py index 89c54de7..6c4966df 100644 --- a/couchpotato/core/notifications/synoindex/main.py +++ b/couchpotato/core/notifications/synoindex/main.py @@ -2,6 +2,7 @@ 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 os import subprocess log = CPLog(__name__) @@ -9,6 +10,8 @@ log = CPLog(__name__) class Synoindex(Notification): + index_path = '/usr/syno/bin/synoindex' + def __init__(self): super(Synoindex, self).__init__() addEvent('renamer.after', self.addToLibrary) @@ -16,7 +19,7 @@ class Synoindex(Notification): def addToLibrary(self, group = {}): if self.isDisabled(): return - command = ['/usr/syno/bin/synoindex', '-A', group.get('destination_dir', '')] + command = [self.index_path, '-A', group.get('destination_dir')] log.info('Executing synoindex command: %s ', command) try: p = subprocess.Popen(command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) @@ -30,5 +33,4 @@ class Synoindex(Notification): return True def test(self): - success = self.addToLibrary() - return jsonified({'success': success}) + return jsonified({'success': os.path.isfile(self.index_path)}) diff --git a/couchpotato/core/plugins/library/main.py b/couchpotato/core/plugins/library/main.py index ae142299..95dda2ff 100644 --- a/couchpotato/core/plugins/library/main.py +++ b/couchpotato/core/plugins/library/main.py @@ -1,6 +1,7 @@ from couchpotato import get_session from couchpotato.core.event import addEvent, fireEventAsync, fireEvent from couchpotato.core.helpers.encoding import toUnicode, simplifyString +from couchpotato.core.helpers.variable import mergeDicts from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, LibraryTitle, File @@ -138,26 +139,23 @@ class LibraryPlugin(Plugin): library = db.query(Library).filter_by(identifier = identifier).first() if not library.info: - library_dict = self.update(identifier) - dates = library_dict.get('info', {}).get('release_dates') + library_dict = self.update(identifier, force = True) + dates = library_dict.get('info', {}).get('release_date') else: dates = library.info.get('release_date') - if dates and dates.get('expires', 0) < time.time(): + if dates and dates.get('expires', 0) < time.time() or not dates: dates = fireEvent('movie.release_date', identifier = identifier, merge = True) - library.info['release_date'] = dates - library.info = library.info + library.info = mergeDicts(library.info, {'release_date': dates }) db.commit() - dates = library.info.get('release_date', {}) - #db.close() - return dates def simplifyTitle(self, title): title = toUnicode(title) + nr_prefix = '' if title[0] in ascii_letters else '#' title = simplifyString(title) diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index 0bc47681..b22b6265 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -320,17 +320,20 @@ class Scanner(Plugin): # Only process movies newer than x if newer_than and newer_than > 0: + has_new_files = False for cur_file in group['unsorted_files']: file_time = [os.path.getmtime(cur_file), os.path.getctime(cur_file)] - if file_time[0] > time.time() or file_time[1] > time.time(): + if file_time[0] > newer_than or file_time[1] > newer_than: + has_new_files = True break - log.debug('None of the files have changed since %s for %s, skipping.', (time.ctime(newer_than), identifier)) + if not has_new_files: + log.debug('None of the files have changed since %s for %s, skipping.', (time.ctime(newer_than), identifier)) - # Delete the unsorted list - del group['unsorted_files'] + # Delete the unsorted list + del group['unsorted_files'] - continue + continue # Group extra (and easy) files first # images = self.getImages(group['unsorted_files']) diff --git a/couchpotato/core/providers/movie/couchpotatoapi/main.py b/couchpotato/core/providers/movie/couchpotatoapi/main.py index 0ada5c9f..8e890484 100644 --- a/couchpotato/core/providers/movie/couchpotatoapi/main.py +++ b/couchpotato/core/providers/movie/couchpotatoapi/main.py @@ -6,6 +6,7 @@ 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 time import traceback log = CPLog(__name__) @@ -13,11 +14,11 @@ 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/', + 'suggest': 'https://couchpota.to/api/suggest/%s/%s/', } http_time_between_calls = 0 api_version = 1 @@ -64,7 +65,7 @@ class CouchPotatoApi(MovieProvider): if identifier is None: return {} try: - data = self.urlopen((self.api_url % ('eta')) + (identifier + '/'), headers = self.getRequestHeaders()) + data = self.urlopen(self.urls['eta'] % identifier, headers = self.getRequestHeaders()) dates = json.loads(data) log.debug('Found ETA for %s: %s', (identifier, dates)) return dates @@ -75,7 +76,7 @@ class CouchPotatoApi(MovieProvider): def suggest(self, movies = [], ignore = []): try: - data = self.urlopen((self.api_url % ('suggest')) + ','.join(movies) + '/' + ','.join(ignore) + '/') + data = self.urlopen(self.urls['suggest'] % (','.join(movies), ','.join(ignore))) suggestions = json.loads(data) log.info('Found Suggestions for %s', (suggestions)) except Exception, e: @@ -107,4 +108,5 @@ class CouchPotatoApi(MovieProvider): return { 'X-CP-Version': fireEvent('app.version', single = True), 'X-CP-API': self.api_version, + 'X-CP-Time': time.time(), } diff --git a/couchpotato/static/images/couch.png b/couchpotato/static/images/couch.png index 0910c5cb..3bc445e7 100644 Binary files a/couchpotato/static/images/couch.png and b/couchpotato/static/images/couch.png differ diff --git a/couchpotato/static/images/gear.png b/couchpotato/static/images/gear.png index 75d0a68f..f1d63bad 100644 Binary files a/couchpotato/static/images/gear.png and b/couchpotato/static/images/gear.png differ diff --git a/couchpotato/static/images/homescreen.png b/couchpotato/static/images/homescreen.png index d8028a4c..491be66d 100644 Binary files a/couchpotato/static/images/homescreen.png and b/couchpotato/static/images/homescreen.png differ diff --git a/couchpotato/static/images/icon.attention.png b/couchpotato/static/images/icon.attention.png index 9878676c..ff10b976 100644 Binary files a/couchpotato/static/images/icon.attention.png and b/couchpotato/static/images/icon.attention.png differ diff --git a/couchpotato/static/images/icon.check.png b/couchpotato/static/images/icon.check.png index c277e6b4..e99e575f 100644 Binary files a/couchpotato/static/images/icon.check.png and b/couchpotato/static/images/icon.check.png differ diff --git a/couchpotato/static/images/icon.delete.png b/couchpotato/static/images/icon.delete.png index 276ea15f..5fbfe36d 100644 Binary files a/couchpotato/static/images/icon.delete.png and b/couchpotato/static/images/icon.delete.png differ diff --git a/couchpotato/static/images/icon.download.png b/couchpotato/static/images/icon.download.png index ca3d0434..e64e9997 100644 Binary files a/couchpotato/static/images/icon.download.png and b/couchpotato/static/images/icon.download.png differ diff --git a/couchpotato/static/images/icon.edit.png b/couchpotato/static/images/icon.edit.png index 19ff8bd2..9d7aac68 100644 Binary files a/couchpotato/static/images/icon.edit.png and b/couchpotato/static/images/icon.edit.png differ diff --git a/couchpotato/static/images/icon.files.png b/couchpotato/static/images/icon.files.png index 2ed1c6ac..951fea6d 100644 Binary files a/couchpotato/static/images/icon.files.png and b/couchpotato/static/images/icon.files.png differ diff --git a/couchpotato/static/images/icon.folder.gif b/couchpotato/static/images/icon.folder.gif index e19ce53a..9fbb12fb 100644 Binary files a/couchpotato/static/images/icon.folder.gif and b/couchpotato/static/images/icon.folder.gif differ diff --git a/couchpotato/static/images/icon.imdb.png b/couchpotato/static/images/icon.imdb.png index 72fa3408..a9903c49 100644 Binary files a/couchpotato/static/images/icon.imdb.png and b/couchpotato/static/images/icon.imdb.png differ diff --git a/couchpotato/static/images/icon.info.png b/couchpotato/static/images/icon.info.png index 12cd1aef..f61dc868 100644 Binary files a/couchpotato/static/images/icon.info.png and b/couchpotato/static/images/icon.info.png differ diff --git a/couchpotato/static/images/icon.rating.png b/couchpotato/static/images/icon.rating.png index 174a4677..f5e07adf 100644 Binary files a/couchpotato/static/images/icon.rating.png and b/couchpotato/static/images/icon.rating.png differ diff --git a/couchpotato/static/images/icon.refresh.png b/couchpotato/static/images/icon.refresh.png index 257cfee3..906887ed 100644 Binary files a/couchpotato/static/images/icon.refresh.png and b/couchpotato/static/images/icon.refresh.png differ diff --git a/couchpotato/static/images/icon.spinner.gif b/couchpotato/static/images/icon.spinner.gif index 4abd8868..c84d177f 100644 Binary files a/couchpotato/static/images/icon.spinner.gif and b/couchpotato/static/images/icon.spinner.gif differ diff --git a/couchpotato/static/images/icon.trailer.png b/couchpotato/static/images/icon.trailer.png index 6a382dc7..8bdd7171 100644 Binary files a/couchpotato/static/images/icon.trailer.png and b/couchpotato/static/images/icon.trailer.png differ diff --git a/couchpotato/static/images/icon.undo.png b/couchpotato/static/images/icon.undo.png index 07f907dc..71c7ec0a 100644 Binary files a/couchpotato/static/images/icon.undo.png and b/couchpotato/static/images/icon.undo.png differ diff --git a/couchpotato/static/images/imdb_watchlist.png b/couchpotato/static/images/imdb_watchlist.png index fc4158bd..a0250b3e 100644 Binary files a/couchpotato/static/images/imdb_watchlist.png and b/couchpotato/static/images/imdb_watchlist.png differ diff --git a/couchpotato/static/images/right.arrow.png b/couchpotato/static/images/right.arrow.png index 39677d05..399db760 100644 Binary files a/couchpotato/static/images/right.arrow.png and b/couchpotato/static/images/right.arrow.png differ diff --git a/couchpotato/static/images/sprite.png b/couchpotato/static/images/sprite.png index 6af04a7e..5ba4d00e 100644 Binary files a/couchpotato/static/images/sprite.png and b/couchpotato/static/images/sprite.png differ diff --git a/couchpotato/static/images/toTop.gif b/couchpotato/static/images/toTop.gif index cde291a4..110534a2 100644 Binary files a/couchpotato/static/images/toTop.gif and b/couchpotato/static/images/toTop.gif differ