diff --git a/couchpotato/core/media/movie/_base/main.py b/couchpotato/core/media/movie/_base/main.py index 6c4298c..ec05305 100755 --- a/couchpotato/core/media/movie/_base/main.py +++ b/couchpotato/core/media/movie/_base/main.py @@ -87,11 +87,21 @@ class MovieBase(MovieTypeBase): # Set default title def_title = self.getDefaultTitle(info) - # Default profile and category + # Default profile default_profile = {} if (not params.get('profile_id') and status != 'done') or params.get('ignore_previous', False): default_profile = fireEvent('profile.default', single = True) + + # Set category cat_id = params.get('category_id') + if cat_id == '-1': + cat_id = None + elif (cat_id is None or len(cat_id) == 0) and (status != 'done' or params.get('ignore_previous', False)): + default_category = fireEvent('category.default', single = True) + if default_category is not None: + cat_id = default_category.get('_id') + else: + cat_id = None try: db = get_db() @@ -105,7 +115,7 @@ class MovieBase(MovieTypeBase): }, 'status': status if status else 'active', 'profile_id': params.get('profile_id') or default_profile.get('_id'), - 'category_id': cat_id if cat_id is not None and len(cat_id) > 0 and cat_id != '-1' else None, + 'category_id': cat_id, } # Update movie info diff --git a/couchpotato/core/plugins/category/main.py b/couchpotato/core/plugins/category/main.py index 4abc94c..0c7a68b 100644 --- a/couchpotato/core/plugins/category/main.py +++ b/couchpotato/core/plugins/category/main.py @@ -32,6 +32,7 @@ class CategoryPlugin(Plugin): }) addEvent('category.all', self.all) + addEvent('category.default', self.default) def allView(self, **kwargs): @@ -47,6 +48,10 @@ class CategoryPlugin(Plugin): return [x['doc'] for x in categories] + def default(self): + db = get_db() + return list(db.all('category', limit = 1, with_doc = True))[0]['doc'] + def save(self, **kwargs): try: