Skip to content

Commit

Permalink
Add custom guessit rule for VHS as movie title
Browse files Browse the repository at this point in the history
Add support for predefined expected release groups
  • Loading branch information
h3llrais3r committed Jan 30, 2019
1 parent 05fca6d commit efc2ee9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
6 changes: 6 additions & 0 deletions autosubliminal/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

from autosubliminal.parsers.guessit import default_api

# Expected release groups
expected_groups = [
'CHD'
]


def guessit(string, options=None):
"""
Expand All @@ -17,6 +22,7 @@ def guessit(string, options=None):
"""
start_time = time()
custom_options = dict(options) if options else dict()
custom_options.update(dict(expected_group=expected_groups))
result = default_api.guessit(string, options=custom_options)
result['parsing_time'] = time() - start_time

Expand Down
64 changes: 63 additions & 1 deletion autosubliminal/parsers/guessit/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,68 @@ def when(self, matches, context):
return to_remove, to_append


class VhsAsMovieTitle(Rule):
"""'VHS' as the movie title.
Example:
guessit -t movie "VHS 2012 BluRay 720p DTS x264-CHD.mkv"
without the rule:
For: VHS 2012 BluRay 720p DTS x264-CHD.mkv
GuessIt found: {
"source": [
"VHS",
"Blu-ray"
],
"year": 2012,
"screen_size": "720p",
"audio_codec": "DTS",
"video_codec": "H.264",
"title": "CHD",
"container": "mkv",
"type": "movie"
}
with the rule:
For: VHS 2012 BluRay 720p DTS x264-CHD.mkv
GuessIt found: {
"title": "VHS",
"year": 2012,
"source": "Blu-ray"
"screen_size": "720p",
"audio_codec": "DTS",
"video_codec": "H.264",
"release_group": "CHD",
"container": "mkv",
"type": "movie"
}
"""

priority = POST_PROCESS
dependency = TypeProcessor # To guess the type before
consequence = RenameMatch('title')

def when(self, matches, context):
"""Evaluate the rule.
:param matches:
:type matches: rebulk.match.Matches
:param context:
:type context: dict
:return:
"""
if not matches.named('type', lambda m: m.value == 'movie'):
return

sources = matches.named('source')
if sources:
title = matches.named('title')
if not title:
for source in sources:
if source.value == 'VHS' and matches.next(source, predicate=lambda match: match.name == 'year'):
return source


def rules():
"""Return all our custom rules to be applied to the guessit api.
Expand All @@ -355,4 +417,4 @@ def rules():
- Only allowed dependency is TypeProcessor because we want to apply rules for certain types only
"""
return Rebulk().rules(RenamePartsToEpisodeNumbers, AppendPartToMovieTile, AppendLineToMovieTitle,
AppendUsToMovieTitle, PrependXxxToMovieTitle)
AppendUsToMovieTitle, PrependXxxToMovieTitle, VhsAsMovieTitle)
12 changes: 12 additions & 0 deletions tests/parsers/test_guessit.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ def test_guessit_prepend_xxx_to_movie_title():
assert guess['video_codec'] == 'H.264'
assert guess['audio_codec'] == 'AAC'
assert guess['release_group'] == 'RARBG'


def test_guessit_vhs_as_movie_title():
guess = guessit('VHS 2012 BluRay 720p DTS x264-CHD.mkv')
assert guess is not None
assert guess['type'] == 'movie'
assert guess['title'] == 'VHS'
assert guess['year'] == 2012
assert guess['source'] == 'Blu-ray'
assert guess['screen_size'] == '720p'
assert guess['video_codec'] == 'H.264'
assert guess['release_group'] == 'CHD'

0 comments on commit efc2ee9

Please sign in to comment.