aboutsummaryrefslogtreecommitdiffhomepage
path: root/custom_libs/subliminal_patch/subtitle.py
diff options
context:
space:
mode:
Diffstat (limited to 'custom_libs/subliminal_patch/subtitle.py')
-rw-r--r--custom_libs/subliminal_patch/subtitle.py40
1 files changed, 29 insertions, 11 deletions
diff --git a/custom_libs/subliminal_patch/subtitle.py b/custom_libs/subliminal_patch/subtitle.py
index 529e99019..c19acd1ec 100644
--- a/custom_libs/subliminal_patch/subtitle.py
+++ b/custom_libs/subliminal_patch/subtitle.py
@@ -13,7 +13,7 @@ import pysrt
import pysubs2
from bs4 import UnicodeDammit
from pysubs2 import SSAStyle
-from pysubs2.subrip import parse_tags, MAX_REPRESENTABLE_TIME
+from pysubs2.formats.subrip import parse_tags, MAX_REPRESENTABLE_TIME
from pysubs2.time import ms_to_times
from subzero.modification import SubtitleModifications
from subzero.language import Language
@@ -62,7 +62,7 @@ class Subtitle(Subtitle_):
_guessed_encoding = None
_is_valid = False
use_original_format = False
- format = "srt" # default format is srt
+ # format = "srt" # default format is srt
def __init__(self, language, hearing_impaired=False, page_link=None, encoding=None, mods=None, original_format=False):
# set subtitle language to hi if it's hearing_impaired
@@ -74,6 +74,21 @@ class Subtitle(Subtitle_):
self.mods = mods
self._is_valid = False
self.use_original_format = original_format
+ self._og_format = None
+
+ @property
+ def format(self):
+ if self.use_original_format and self._og_format is not None:
+ logger.debug("Original format requested [%s]", self._og_format)
+ return self._og_format
+
+ logger.debug("Will assume srt format")
+ return "srt"
+
+ # Compatibility
+ @format.setter
+ def format(self, val):
+ self._og_format = val
def __repr__(self):
r_info = str(self.release_info or "").replace("\n", " | ").strip()
@@ -292,11 +307,13 @@ class Subtitle(Subtitle_):
logger.info("Got FPS from MicroDVD subtitle: %s", subs.fps)
else:
logger.info("Got format: %s", subs.format)
- if self.use_original_format:
- self.format = subs.format
- self._is_valid = True
- logger.debug("Using original format")
- return True
+ self._og_format = subs.format
+ self._is_valid = True
+ # if self.use_original_format:
+ # self.format = subs.format
+ # self._is_valid = True
+ # logger.debug("Using original format")
+ return True
except pysubs2.UnknownFPSError:
# if parsing failed, use frame rate from provider
@@ -340,7 +357,7 @@ class Subtitle(Subtitle_):
fragment = fragment.replace(r"\n", u"\n")
fragment = fragment.replace(r"\N", u"\n")
if sty.drawing:
- raise pysubs2.ContentNotUsable
+ return None
if format == "srt":
if sty.italic:
@@ -373,9 +390,10 @@ class Subtitle(Subtitle_):
for i, line in enumerate(visible_lines, 1):
start = ms_to_timestamp(line.start, mssep=mssep)
end = ms_to_timestamp(line.end, mssep=mssep)
- try:
- text = prepare_text(line.text, sub.styles.get(line.style, SSAStyle.DEFAULT_STYLE))
- except pysubs2.ContentNotUsable:
+
+ text = prepare_text(line.text, sub.styles.get(line.style, SSAStyle.DEFAULT_STYLE))
+
+ if text is None:
continue
out.append(u"%d\n" % i)