forked from DRMTalks/devine
Override Subtitle download method to convert fTTML/fVTT to TTML/VTT
We want to force convert these Subtitle formats to their respective normal formats as the way they download are not actually usable as-is. As in, even if the user wanted to keep the original Subtitle format, these formats wouldn't be usable as-is.
This commit is contained in:
parent
f978f7f404
commit
08c497da0a
|
@ -4,11 +4,13 @@ import re
|
|||
import subprocess
|
||||
from collections import defaultdict
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterable, Optional
|
||||
from typing import Any, Callable, Iterable, Optional
|
||||
|
||||
import pycaption
|
||||
import requests
|
||||
from construct import Container
|
||||
from pycaption import Caption, CaptionList, CaptionNode, WebVTTReader
|
||||
from pycaption.geometry import Layout
|
||||
|
@ -144,6 +146,16 @@ class Subtitle(Track):
|
|||
track_name += flag
|
||||
return track_name or None
|
||||
|
||||
def download(self, session: requests.Session, prepare_drm: Callable, progress: partial) -> None:
|
||||
super().download(session, prepare_drm, progress)
|
||||
if not self.path:
|
||||
return
|
||||
|
||||
if self.codec == Subtitle.Codec.fTTML:
|
||||
self.convert(Subtitle.Codec.TimedTextMarkupLang)
|
||||
elif self.codec == Subtitle.Codec.fVTT:
|
||||
self.convert(Subtitle.Codec.WebVTT)
|
||||
|
||||
def convert(self, codec: Subtitle.Codec) -> Path:
|
||||
"""
|
||||
Convert this Subtitle to another Format.
|
||||
|
|
Loading…
Reference in New Issue