Merge pull request #838 from GermanG/legendasdivx

Legendasdivx: adding scores to subtitles to get best match in archive
pull/848/head
morpheus65535 5 years ago committed by GitHub
commit 0a81f79f49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,6 +15,7 @@ from subliminal_patch.subtitle import Subtitle
from subliminal.video import Episode, Movie from subliminal.video import Episode, Movie
from subliminal.subtitle import SUBTITLE_EXTENSIONS, fix_line_ending,guess_matches from subliminal.subtitle import SUBTITLE_EXTENSIONS, fix_line_ending,guess_matches
from subzero.language import Language from subzero.language import Language
from subliminal_patch.score import get_scores
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -104,7 +105,8 @@ class LegendasdivxSubtitle(Subtitle):
matches.update(['video_codec']) matches.update(['video_codec'])
break break
matches |= guess_matches(video, guessit(self.description)) # running guessit on a huge description may break guessit
# matches |= guess_matches(video, guessit(self.description))
return matches return matches
@ -302,6 +304,8 @@ class LegendasdivxProvider(Provider):
_tmp = list(SUBTITLE_EXTENSIONS) _tmp = list(SUBTITLE_EXTENSIONS)
_tmp.remove('.txt') _tmp.remove('.txt')
_subtitle_extensions = tuple(_tmp) _subtitle_extensions = tuple(_tmp)
_max_score = 0
_scores = get_scores (subtitle.video)
for name in archive.namelist(): for name in archive.namelist():
# discard hidden files # discard hidden files
@ -312,16 +316,26 @@ class LegendasdivxProvider(Provider):
if not name.lower().endswith(_subtitle_extensions): if not name.lower().endswith(_subtitle_extensions):
continue continue
_guess = guessit (name)
if isinstance(subtitle.video, Episode): if isinstance(subtitle.video, Episode):
logger.debug ("guessing %s" % name) logger.debug ("guessing %s" % name)
guess = guessit(name) logger.debug("subtitle S{}E{} video S{}E{}".format(_guess['season'],_guess['episode'],subtitle.video.season,subtitle.video.episode))
logger.debug("subtitle S{}E{} video S{}E{}".format(guess['season'],guess['episode'],subtitle.video.season,subtitle.video.episode))
if subtitle.video.episode != guess['episode'] or subtitle.video.season != guess['season']: if subtitle.video.episode != _guess['episode'] or subtitle.video.season != _guess['season']:
logger.debug('subtitle does not match video, skipping') logger.debug('subtitle does not match video, skipping')
continue continue
logger.debug("returning from archive: %s" % name) matches = set()
return archive.read(name) matches |= guess_matches (subtitle.video, _guess)
logger.debug('srt matches: %s' % matches)
_score = sum ((_scores.get (match, 0) for match in matches))
if _score > _max_score:
_max_name = name
_max_score = _score
logger.debug("new max: {} {}".format(name, _score))
if _max_score > 0:
logger.debug("returning from archive: {} scored {}".format(_max_name, _max_score))
return archive.read(_max_name)
raise ParseResponseError('Can not find the subtitle in the compressed file') raise ParseResponseError('Can not find the subtitle in the compressed file')

Loading…
Cancel
Save