diff --git a/medusa/server/api/v2/guessit.py b/medusa/server/api/v2/guessit.py index 5ac2b6ba72..1b5d4eb868 100644 --- a/medusa/server/api/v2/guessit.py +++ b/medusa/server/api/v2/guessit.py @@ -2,11 +2,19 @@ """Request handler for statistics.""" from __future__ import unicode_literals +import logging + import guessit +from medusa.logger.adapters.style import CustomBraceAdapter +from medusa.name_parser.parser import InvalidNameException, InvalidShowException, NameParser from medusa.server.api.v2.base import BaseRequestHandler +log = CustomBraceAdapter(logging.getLogger(__name__)) +log.logger.addHandler(logging.NullHandler()) + + class GuessitHandler(BaseRequestHandler): """Guessit parser request handler.""" @@ -26,6 +34,26 @@ def get(self): if not release: return self._bad_request('Missing release name to guess') - guess = guessit.guessit(release) - - return self._ok(data=dict(guess)) + result = {'error': None} + show = None + + try: + parse_result = NameParser().parse(release) + show = parse_result.series.to_json() + except InvalidNameException as error: + log.debug( + 'Not enough information to parse release name into a valid show. ' + 'improve naming for: {release}', + {'release': release}) + result['error'] = str(error) + except InvalidShowException as error: + log.debug( + 'Could not match the parsed title to a show in your library for: ' + 'Consider adding scene exceptions for {release}', + {'release': release}) + result['error'] = str(error) + + result['guess'] = guessit.guessit(release) + result['show'] = show + + return self._ok(data=dict(result)) diff --git a/themes-default/slim/src/components/helpers/test-guessit.vue b/themes-default/slim/src/components/helpers/test-guessit.vue index d1620569b6..adf5f2390f 100644 --- a/themes-default/slim/src/components/helpers/test-guessit.vue +++ b/themes-default/slim/src/components/helpers/test-guessit.vue @@ -19,18 +19,36 @@
{{JSON.stringify(guessitResult, undefined, 4)}}
+
+
+
{{error}}
+
+
+ +
+
+
Matched to show:
+
{{show.title}}
+
+