From 69cab4956413985050538614947c29630b089261 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Tue, 25 Jun 2024 15:36:06 -0400 Subject: [PATCH] Make Subtitle an abstract base class --- av/codec/context.pyx | 2 +- av/subtitles/stream.pyx | 3 +++ av/subtitles/subtitle.pyi | 3 +-- av/subtitles/subtitle.pyx | 11 ++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/av/codec/context.pyx b/av/codec/context.pyx index d94a0801..f8c1263c 100644 --- a/av/codec/context.pyx +++ b/av/codec/context.pyx @@ -638,7 +638,7 @@ cdef class CodecContext: def skip_frame(self): """One of :class:`.SkipType`. - Wraps ffmpeg:`AVCodecContext.skip_frame`. + Wraps :ffmpeg:`AVCodecContext.skip_frame`. """ return SkipType._get(self.ptr.skip_frame, create=True) diff --git a/av/subtitles/stream.pyx b/av/subtitles/stream.pyx index 6cf0c2d8..1deed586 100644 --- a/av/subtitles/stream.pyx +++ b/av/subtitles/stream.pyx @@ -1,3 +1,6 @@ cdef class SubtitleStream(Stream): + """ + A :class:`SubtitleStream` can contain many :class:`SubtitleSet` objects accessible via decoding. + """ def __getattr__(self, name): return getattr(self.codec_context, name) diff --git a/av/subtitles/subtitle.pyi b/av/subtitles/subtitle.pyi index cdbe7fb3..2ac9195e 100644 --- a/av/subtitles/subtitle.pyi +++ b/av/subtitles/subtitle.pyi @@ -11,8 +11,7 @@ class SubtitleSet: def __iter__(self) -> Iterator[Subtitle]: ... def __getitem__(self, i: int) -> Subtitle: ... -class Subtitle: - type: Literal[b"none", b"bitmap", b"text", b"ass"] +class Subtitle: ... class BitmapSubtitle(Subtitle): type: Literal[b"bitmap"] diff --git a/av/subtitles/subtitle.pyx b/av/subtitles/subtitle.pyx index e1deca7b..7ced655f 100644 --- a/av/subtitles/subtitle.pyx +++ b/av/subtitles/subtitle.pyx @@ -11,6 +11,9 @@ cdef class SubtitleProxy: cdef class SubtitleSet: + """ + A :class:`SubtitleSet` can contain many :class:`Subtitle` objects. + """ def __cinit__(self, SubtitleProxy proxy): self.proxy = proxy cdef int i @@ -50,9 +53,7 @@ cdef Subtitle build_subtitle(SubtitleSet subtitle, int index): raise ValueError("subtitle rect index out of range") cdef lib.AVSubtitleRect *ptr = subtitle.proxy.struct.rects[index] - if ptr.type == lib.SUBTITLE_NONE: - return Subtitle(subtitle, index) - elif ptr.type == lib.SUBTITLE_BITMAP: + if ptr.type == lib.SUBTITLE_BITMAP: return BitmapSubtitle(subtitle, index) elif ptr.type == lib.SUBTITLE_TEXT: return TextSubtitle(subtitle, index) @@ -63,6 +64,10 @@ cdef Subtitle build_subtitle(SubtitleSet subtitle, int index): cdef class Subtitle: + """ + An abstract base class for each concrete type of subtitle. + Wraps :ffmpeg:`AVSubtitleRect` + """ def __cinit__(self, SubtitleSet subtitle, int index): if index < 0 or index >= subtitle.proxy.struct.num_rects: raise ValueError("subtitle rect index out of range")