From 267933f106438370a9f258392aa2398cb695c369 Mon Sep 17 00:00:00 2001 From: josdion Date: Sat, 25 Apr 2020 16:21:36 +0300 Subject: [PATCH] adding capability for subtitle provider to set frame rate when loading microdvd file --- libs/subliminal_patch/subtitle.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/subliminal_patch/subtitle.py b/libs/subliminal_patch/subtitle.py index ce89e74d3..249fe633f 100644 --- a/libs/subliminal_patch/subtitle.py +++ b/libs/subliminal_patch/subtitle.py @@ -89,6 +89,13 @@ class Subtitle(Subtitle_): def numeric_id(self): raise NotImplemented + def get_fps(self): + """ + :return: frames per second or None if not supported + :rtype: float + """ + return None + def make_picklable(self): """ some subtitle instances might have unpicklable objects stored; clean them up here @@ -264,10 +271,14 @@ class Subtitle(Subtitle_): else: logger.info("Got format: %s", subs.format) except pysubs2.UnknownFPSError: - # if parsing failed, suggest our media file's fps - logger.info("No FPS info in subtitle. Using our own media FPS for the MicroDVD subtitle: %s", - self.plex_media_fps) - subs = pysubs2.SSAFile.from_string(text, fps=self.plex_media_fps) + # if parsing failed, use frame rate from provider + sub_fps = self.get_fps() + if not isinstance(sub_fps, float) or sub_fps < 10.0: + # or use our media file's fps as a fallback + sub_fps = self.plex_media_fps + logger.info("No FPS info in subtitle. Using our own media FPS for the MicroDVD subtitle: %s", + self.plex_media_fps) + subs = pysubs2.SSAFile.from_string(text, fps=sub_fps) unicontent = self.pysubs2_to_unicode(subs) self.content = unicontent.encode(self._guessed_encoding)