From 68181a6f4b03ff8cbc5688ae9cec41c07abf2f11 Mon Sep 17 00:00:00 2001 From: p0psicles Date: Thu, 17 Feb 2022 21:27:36 +0100 Subject: [PATCH 1/3] Improve test guessit component --- medusa/server/api/v2/guessit.py | 34 +++++++++++++-- .../src/components/helpers/test-guessit.vue | 42 ++++++++++++++++++- themes/dark/assets/js/medusa-runtime.js | 6 +-- themes/light/assets/js/medusa-runtime.js | 6 +-- 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/medusa/server/api/v2/guessit.py b/medusa/server/api/v2/guessit.py index 5ac2b6ba72..bf645bcce8 100644 --- a/medusa/server/api/v2/guessit.py +++ b/medusa/server/api/v2/guessit.py @@ -3,8 +3,16 @@ from __future__ import unicode_literals import guessit +import logging from medusa.server.api.v2.base import BaseRequestHandler +from medusa.name_parser.parser import InvalidNameException, InvalidShowException, NameParser + +from medusa.logger.adapters.style import CustomBraceAdapter + + +log = CustomBraceAdapter(logging.getLogger(__name__)) +log.logger.addHandler(logging.NullHandler()) class GuessitHandler(BaseRequestHandler): @@ -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}}
+
+