Skip to content

Commit

Permalink
Feature/debug guessit (#10504)
Browse files Browse the repository at this point in the history
* Add log message or guessit parsing

* Remove adding a guessit result to cache. As this is done later.

* comments

* Improve guessit test tool

* Shouldn't overwrite the __dict__ method.

* Fix flake and Jest tests
  • Loading branch information
p0psicles authored Apr 18, 2022
1 parent c286b8c commit c5e1bd6
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 22 deletions.
6 changes: 4 additions & 2 deletions medusa/name_parser/guessit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def guessit(name, options=None, cached=True):
if cached:
result = guessit_cache.get_or_invalidate(name, final_options)
if not result:
log.debug('New guessit parse for item {name}', {'name': name})
result = default_api.guessit(name, options=final_options)
guessit_cache.add(name, result)
# We don't want to cache at this point. As this is a bare guessit result.
# Meaning we haven't been able to calculate any season scene exception at this point.

result['parsing_time'] = time() - start_time
return result
Expand Down Expand Up @@ -141,7 +143,7 @@ def get_or_invalidate(self, name, obj):
self.invalidation_object = obj

if self.invalidation_object == obj:
log.debug('Using guessit cache item for {name}', {'name': name})
log.debug('Trying guessit cache for item {name}', {'name': name})
return self.get(name)

log.debug('GuessIt cache was cleared due to invalidation object change: previous={previous} new={new}',
Expand Down
8 changes: 8 additions & 0 deletions medusa/name_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ def __str__(self):
total_time=self.total_time))
return helpers.canonical_name(obj, fmt='{key}: {value}', separator=', ')

def to_dict(self):
"""Return an dict representation."""
return OrderedDict(self.guess, **dict(season=self.season_number,
episode=self.episode_numbers,
absolute_episode=self.ab_episode_numbers,
quality=common.Quality.qualityStrings[self.quality],
total_time=self.total_time))

# Python 2 compatibility
__unicode__ = __str__

Expand Down
7 changes: 6 additions & 1 deletion medusa/server/api/v2/guessit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from medusa.logger.adapters.style import CustomBraceAdapter
from medusa.name_parser.guessit_parser import guessit
from medusa.name_parser.parser import InvalidNameException, InvalidShowException, NameParser
from medusa.name_parser.rules import default_api
from medusa.server.api.v2.base import BaseRequestHandler


Expand Down Expand Up @@ -52,7 +53,11 @@ def get(self):
{'release': release})
result['error'] = str(error)

result['guess'] = guessit(release, cached=False)
if parse_result:
result['parse'] = parse_result.to_dict()
else:
result['parse'] = guessit(release, cached=False)
result['vanillaGuessit'] = default_api.guessit(release)
result['show'] = show

return self._ok(data=dict(result))
36 changes: 25 additions & 11 deletions themes-default/slim/src/components/helpers/test-guessit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,46 @@
<div class="row">
<div class="col-lg-12">
<p>Guessit is a library used for parsing release names. As a minimum Medusa requires a show title, season and episode (if not parsed as a season pack).</p>
<p>You can fill in your release name and click the `Test Release Name` button, to get the guessit response.</p>
<p>You can fill in your release name and click the `Test Release Name` button, to get the parse result.</p>
<p>Medusa uses guessit to "guess" a show title, season, episode and other information. It then uses other known info, like scene exception, season exceptions and scene numbering to enrich the result.</p>
</div>
</div>
<div class="row">
<div class="col-lg-2">
<span>Release name:</span>
<h4>Release name:</h4>
</div>
<div class="col-lg-10">
<input type="text" class="form-control input-sm" v-model="releaseName">
</div>
</div>

<div v-if="show" class="row">
<div class="col-lg-12 matched-show">
<span style="margin-right: 0.4rem">Matched to show:</span>
<span><app-link :href="`home/displayShow?showslug=${show.id.slug}`">{{show.title}}</app-link></span>
</div>
</div>

<div class="row">
<div class="col-lg-12">
<pre>{{JSON.stringify(guessitResult, undefined, 4)}}</pre>
<h4>Enriched parsed result</h4>
<pre>{{JSON.stringify(parse, undefined, 4)}}</pre>
</div>
</div>
<div v-if="error" class="row">

<div class="row">
<div class="col-lg-12">
<div class="error">{{error}}</div>
<h4>Guessit result</h4>
<pre>{{JSON.stringify(guessit, undefined, 4)}}</pre>
</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 v-if="error" class="row">
<div class="col-lg-12">
<div class="error">{{error}}</div>
</div>
</div>

<button class="btn-medusa config_submitter" @click.prevent="testReleaseName">Test Release Name</button>
</div>
</template>
Expand All @@ -46,7 +58,8 @@ export default {
data() {
return {
releaseName: '',
guessitResult: {},
parse: {},
guessit: {},
show: null,
error: null
};
Expand All @@ -64,7 +77,8 @@ export default {
const { releaseName } = this;
try {
const { data } = await this.client.api.get('guessit', { params: { release: releaseName } });
this.guessitResult = data.guess;
this.parse = data.parse;
this.guessit = data.vanillaGuessit;
this.show = data.show;
this.error = data.error;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3966,7 +3966,11 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
</p>
<p>
You can fill in your release name and click the \`Test Release Name\` button, to get the guessit response.
You can fill in your release name and click the \`Test Release Name\` button, to get the parse result.
</p>
<p>
Medusa uses guessit to "guess" a show title, season, episode and other information. It then uses other known info, like scene exception, season exceptions and scene numbering to enrich the result.
</p>
</div>
</div>
Expand All @@ -3977,9 +3981,9 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
<div
class="col-lg-2"
>
<span>
<h4>
Release name:
</span>
</h4>
</div>
<div
Expand All @@ -3992,19 +3996,39 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
</div>
</div>
<!---->
<div
class="row"
>
<div
class="col-lg-12"
>
<h4>
Enriched parsed result
</h4>
<pre>
{}
</pre>
</div>
</div>
<!---->
<div
class="row"
>
<div
class="col-lg-12"
>
<h4>
Guessit result
</h4>
<pre>
{}
</pre>
</div>
</div>
<!---->
Expand Down
Loading

0 comments on commit c5e1bd6

Please sign in to comment.