feat(Subtitle): Convert from fTTML->TTML & fVTT->WebVTT post-download

This commit is contained in:
rlaphoenix 2024-03-02 15:25:30 +00:00
parent cae47017dc
commit 77976c7e74
1 changed files with 17 additions and 0 deletions

View File

@ -4,11 +4,13 @@ import re
import subprocess import subprocess
from collections import defaultdict from collections import defaultdict
from enum import Enum from enum import Enum
from functools import partial
from io import BytesIO from io import BytesIO
from pathlib import Path from pathlib import Path
from typing import Any, Callable, Iterable, Optional from typing import Any, Callable, Iterable, Optional
import pycaption import pycaption
import requests
from construct import Container from construct import Container
from pycaption import Caption, CaptionList, CaptionNode, WebVTTReader from pycaption import Caption, CaptionList, CaptionNode, WebVTTReader
from pycaption.geometry import Layout from pycaption.geometry import Layout
@ -147,6 +149,21 @@ class Subtitle(Track):
track_name += flag track_name += flag
return track_name or None return track_name or None
def download(
self,
session: requests.Session,
prepare_drm: partial,
progress: Optional[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: def convert(self, codec: Subtitle.Codec) -> Path:
""" """
Convert this Subtitle to another Format. Convert this Subtitle to another Format.