From b50cf1cf4c82912f14d1d334a6e982e18db071a0 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 8 Mar 2014 10:50:11 +0100 Subject: [PATCH 1/5] Only allow next year for couldbereleased check --- couchpotato/core/media/movie/searcher/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/media/movie/searcher/main.py b/couchpotato/core/media/movie/searcher/main.py index 7ae76a4..1c22e18 100644 --- a/couchpotato/core/media/movie/searcher/main.py +++ b/couchpotato/core/media/movie/searcher/main.py @@ -282,13 +282,15 @@ class MovieSearcher(SearcherBase, MovieTypeBase): now = int(time.time()) now_year = date.today().year + now_month = date.today().month if (year is None or year < now_year - 1) and (not dates or (dates.get('theater', 0) == 0 and dates.get('dvd', 0) == 0)): return True else: # Don't allow movies with years to far in the future - if year is not None and year > now_year + 1: + add_year = 1 if now_month > 10 else 0 # Only allow +1 year if end of the year + if year is not None and year > (now_year + add_year): return False # For movies before 1972 From dc0ea5b3f61a6f6d1492a72b32106af4ad487c12 Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 6 Mar 2014 21:30:59 +0100 Subject: [PATCH 2/5] Use proper sorting --- couchpotato/core/event.py | 9 ++------- couchpotato/core/helpers/variable.py | 13 +++---------- libs/axl/axel.py | 7 +++++-- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/couchpotato/core/event.py b/couchpotato/core/event.py index a36c430..8af2967 100644 --- a/couchpotato/core/event.py +++ b/couchpotato/core/event.py @@ -1,5 +1,5 @@ from axl.axel import Event -from couchpotato.core.helpers.variable import mergeDicts, natcmp +from couchpotato.core.helpers.variable import mergeDicts, natsortKey from couchpotato.core.logger import CPLog import threading import traceback @@ -51,11 +51,6 @@ def addEvent(name, handler, priority = 100): }) -def removeEvent(name, handler): - e = events[name] - e -= handler - - def fireEvent(name, *args, **kwargs): if name not in events: return @@ -106,7 +101,7 @@ def fireEvent(name, *args, **kwargs): result = e(*args, **kwargs) result_keys = result.keys() - result_keys.sort(natcmp) + result_keys.sort(key = natsortKey) if options['single'] and not options['merge']: results = None diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 64cdce2..8be6f29 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -214,16 +214,9 @@ def tryFloat(s): return float(s) except: return 0 - -def natsortKey(s): - return map(tryInt, re.findall(r'(\d+|\D+)', s)) - - -def natcmp(a, b): - a2 = natsortKey(a) - b2 = natsortKey(b) - - return (a2 > b2) - (a2 < b2) +def natsortKey(string_): + """See http://www.codinghorror.com/blog/archives/001018.html""" + return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)] def toIterable(value): diff --git a/libs/axl/axel.py b/libs/axl/axel.py index 46940da..d0f069a 100644 --- a/libs/axl/axel.py +++ b/libs/axl/axel.py @@ -11,7 +11,7 @@ # Source: http://pypi.python.org/pypi/axel # Docs: http://packages.python.org/axel -from couchpotato.core.helpers.variable import natcmp +from couchpotato.core.helpers.variable import natsortKey import Queue import hashlib import sys @@ -158,7 +158,10 @@ class Event(object): t.daemon = True t.start() - for handler in sorted(self.handlers.iterkeys(), cmp = natcmp): + handler_keys = self.handlers.keys() + handler_keys.sort(key = natsortKey) + + for handler in handler_keys: self.queue.put(handler) if self.asynchronous: From c58315e2ee0261886e0ce7d42fde18dc885e0184 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 8 Mar 2014 11:59:12 +0100 Subject: [PATCH 3/5] Use natural sorting --- couchpotato/core/helpers/request.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/helpers/request.py b/couchpotato/core/helpers/request.py index b62ab68..a0baa85 100644 --- a/couchpotato/core/helpers/request.py +++ b/couchpotato/core/helpers/request.py @@ -1,5 +1,5 @@ from couchpotato.core.helpers.encoding import toUnicode -from couchpotato.core.helpers.variable import natcmp +from couchpotato.core.helpers.variable import natsortKey from urllib import unquote import re @@ -8,8 +8,13 @@ def getParams(params): reg = re.compile('^[a-z0-9_\.]+$') + # Sort keys + param_keys = params.keys() + param_keys.sort(key = natsortKey) + temp = {} - for param, value in sorted(params.items()): + for param in param_keys: + value = params[param] nest = re.split("([\[\]]+)", param) if len(nest) > 1: From 3172a4d030e5a7064c403256ac2f5da51a176c2c Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 8 Mar 2014 12:27:06 +0100 Subject: [PATCH 4/5] Check for year in coming soon --- couchpotato/core/plugins/dashboard/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/plugins/dashboard/main.py b/couchpotato/core/plugins/dashboard/main.py index 949d8f5..3367ffb 100644 --- a/couchpotato/core/plugins/dashboard/main.py +++ b/couchpotato/core/plugins/dashboard/main.py @@ -1,3 +1,4 @@ +from datetime import date from couchpotato import get_session from couchpotato.api import addApiView from couchpotato.core.event import fireEvent @@ -65,6 +66,7 @@ class Dashboard(Plugin): active = q.all() movies = [] + now_year = date.today().year if len(active) > 0: @@ -91,8 +93,8 @@ class Dashboard(Plugin): if coming_soon: # Don't list older movies - if ((not late and (not eta.get('dvd') and not eta.get('theater') or eta.get('dvd') and eta.get('dvd') > (now - 2419200))) or - (late and (eta.get('dvd', 0) > 0 or eta.get('theater')) and eta.get('dvd') < (now - 2419200))): + if ((not late and (year >= now_year-1) and (not eta.get('dvd') and not eta.get('theater') or eta.get('dvd') and eta.get('dvd') > (now - 2419200))) or + (late and ((year < now_year-1) or ((eta.get('dvd', 0) > 0 or eta.get('theater')) and eta.get('dvd') < (now - 2419200))))): movie_ids.append(movie_id) if len(movie_ids) >= limit: From 9e471ac38933bcf6d870d503f408cba5f6eb6e87 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 8 Mar 2014 14:05:49 +0100 Subject: [PATCH 5/5] Add "I Just Watched" Reddit to userscripts. fix #2621 --- .../core/providers/userscript/reddit/__init__.py | 7 +++++++ couchpotato/core/providers/userscript/reddit/main.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 couchpotato/core/providers/userscript/reddit/__init__.py create mode 100644 couchpotato/core/providers/userscript/reddit/main.py diff --git a/couchpotato/core/providers/userscript/reddit/__init__.py b/couchpotato/core/providers/userscript/reddit/__init__.py new file mode 100644 index 0000000..a74bbf0 --- /dev/null +++ b/couchpotato/core/providers/userscript/reddit/__init__.py @@ -0,0 +1,7 @@ +from .main import Reddit + + +def start(): + return Reddit() + +config = [] diff --git a/couchpotato/core/providers/userscript/reddit/main.py b/couchpotato/core/providers/userscript/reddit/main.py new file mode 100644 index 0000000..9790f6e --- /dev/null +++ b/couchpotato/core/providers/userscript/reddit/main.py @@ -0,0 +1,17 @@ +from couchpotato import fireEvent +from couchpotato.core.helpers.variable import splitString +from couchpotato.core.providers.userscript.base import UserscriptBase + + +class Reddit(UserscriptBase): + + includes = ['*://www.reddit.com/r/Ijustwatched/comments/*'] + + def getMovie(self, url): + name = splitString(url, '/')[-1] + if name.startswith('ijw_'): + name = name[4:] + + year_name = fireEvent('scanner.name_year', name, single = True) + + return self.search(year_name.get('name'), year_name.get('year'))