Skip to content

Commit

Permalink
Improve test guessit component (#10357)
Browse files Browse the repository at this point in the history
* Improve test guessit component

* flake

* update snapshot
  • Loading branch information
p0psicles authored Feb 18, 2022
1 parent c797b83 commit 501ce89
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 deletions.
34 changes: 31 additions & 3 deletions medusa/server/api/v2/guessit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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))
42 changes: 40 additions & 2 deletions themes-default/slim/src/components/helpers/test-guessit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,36 @@
<pre>{{JSON.stringify(guessitResult, undefined, 4)}}</pre>
</div>
</div>
<div v-if="error" class="row">
<div class="col-lg-12">
<div class="error">{{error}}</div>
</div>
</div>

<div v-if="show" class="row">
<div class="col-lg-12 matched-show">
<div>Matched to show:</div>
<div><app-link :href="`home/displayShow?showslug=${show.id.slug}`">{{show.title}}</app-link></div>
</div>
</div>
<button class="btn-medusa config_submitter" @click.prevent="testReleaseName">Test Release Name</button>
</div>
</template>
<script>
import { api } from '../../api';
import AppLink from './app-link.vue';
export default {
name: 'test-guessit',
components: {
AppLink
},
data() {
return {
releaseName: '',
guessitResult: {}
guessitResult: {},
show: null,
error: null
};
},
methods: {
Expand All @@ -41,7 +59,9 @@ export default {
const { releaseName } = this;
try {
const { data } = await api.get('guessit', { params: { release: releaseName } });
this.guessitResult = data;
this.guessitResult = data.guess;
this.show = data.show;
this.error = data.error;
} catch (error) {
console.log('Woops');
}
Expand All @@ -53,4 +73,22 @@ export default {
pre {
word-wrap: break-word;
}
.error {
width: 100%;
padding: 0.5rem;
background-color: red;
font-weight: 700;
border-radius: 2px;
margin-bottom: 2rem;
}
.matched-show {
display: flex;
margin-bottom: 2rem;
}
.matched-show > div {
margin-right: 2rem;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -4004,6 +4004,10 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
</div>
</div>
<!---->
<!---->
<button
class="btn-medusa config_submitter"
>
Expand Down
6 changes: 3 additions & 3 deletions themes/dark/assets/js/medusa-runtime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 501ce89

Please sign in to comment.