Skip to content

Commit

Permalink
Using guessit information to enhance quality detection when Unknown. …
Browse files Browse the repository at this point in the history
…Small enhancement on size detection
  • Loading branch information
ratoaq2 committed Jul 16, 2016
1 parent 6d952d9 commit 941fdbb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
50 changes: 50 additions & 0 deletions sickbeard/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,56 @@ def statusFromName(name, assume=True, anime=False):
quality = Quality.assumeQuality(name)
return Quality.compositeStatus(DOWNLOADED, quality)

guessit_map = {
'720p': {
'HDTV': HDTV,
'WEB-DL': HDWEBDL,
'WEBRip': HDWEBDL,
'BluRay': HDBLURAY,
},
'1080i': RAWHDTV,
'1080p': {
'HDTV': FULLHDTV,
'WEB-DL': FULLHDWEBDL,
'WEBRip': FULLHDWEBDL,
'BluRay': FULLHDBLURAY
},
'4k': {
'HDTV': UHD_4K_TV,
'WEB-DL': UHD_4K_WEBDL,
'WEBRip': UHD_4K_WEBDL,
'BluRay': UHD_4K_BLURAY
}
}

@staticmethod
def from_guessit(guess):
"""
:param guess: guessit dict
:type guess: dict
:return: quality
:rtype: int
"""
screen_size = guess.get('screen_size')
fmt = guess.get('format')

if not screen_size:
return Quality.UNKNOWN

format_map = Quality.guessit_map.get(screen_size)
if not format_map:
return Quality.UNKNOWN

if isinstance(format_map, int):
return format_map

if not fmt:
return Quality.UNKNOWN

quality = format_map.get(fmt)
return quality if quality is not None else Quality.UNKNOWN

DOWNLOADED = None
SNATCHED = None
SNATCHED_PROPER = None
Expand Down
3 changes: 3 additions & 0 deletions sickbeard/name_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _parse_string(self, name): # pylint: disable=too-many-locals, too-many-bran

matches = []
bestResult = None
guess = None

if self.use_guessit:
guess = guessit.guessit(name, dict(show_type=self.show_type))
Expand Down Expand Up @@ -235,6 +236,8 @@ def _parse_string(self, name): # pylint: disable=too-many-locals, too-many-bran

# get quality
bestResult.quality = common.Quality.nameQuality(name, bestResult.show.is_anime)
if bestResult.quality == common.Quality.UNKNOWN and guess is not None:
bestResult.quality = common.Quality.from_guessit(guess)

new_episode_numbers = []
new_season_numbers = []
Expand Down
5 changes: 4 additions & 1 deletion sickbeard/name_parser/rules/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ def size():
:return:
:rtype: Rebulk
"""
def format_size(value):
return re.sub(r'(?<=\d)[\.](?=[^\d])', '', value.upper())

rebulk = Rebulk().regex_defaults(flags=re.IGNORECASE, abbreviations=[dash])
rebulk.defaults(name='size', validator=seps_surround)
rebulk.regex(r'\d+[mgt]b', r'\d+\.\d+[mgt]b', formatter=upper, tags=['release-group-prefix'])
rebulk.regex(r'\d+\.?[mgt]b', r'\d+\.\d+[mgt]b', formatter=format_size, tags=['release-group-prefix'])

return rebulk

Expand Down
11 changes: 11 additions & 0 deletions tests/datasets/tvshows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2720,3 +2720,14 @@
video_codec: h264
release_group: GROUP
type: episode

# Size detection separated with .
? Show.Name.S06E09.720p.HDTV.450.MB.-.iExTV
: title: Show Name
season: 6
episode: 9
screen_size: 720p
format: HDTV
size: 450MB
release_group: iExTV
type: episode

0 comments on commit 941fdbb

Please sign in to comment.