Skip to content

Commit

Permalink
sub.ass now returns as bytes
Browse files Browse the repository at this point in the history
I was getting some UnicodeDecoding errors while I was processing some input. Since ffmpeg docs do not promise char* ass contains UTF-8 strings, I thought it was better to have @Property ass return bytes instead of str.
  • Loading branch information
WyattBlue committed Mar 14, 2024
1 parent 9e4bb69 commit c6f80a3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion av/subtitles/subtitle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class TextSubtitle(Subtitle):

class AssSubtitle(Subtitle):
type: Literal[b"ass"]
ass: str
ass: bytes
8 changes: 7 additions & 1 deletion av/subtitles/subtitle.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from cpython cimport PyBuffer_FillInfo


cdef extern from "Python.h":
bytes PyBytes_FromString(char*)


cdef class SubtitleProxy:
def __dealloc__(self):
lib.avsubtitle_free(&self.struct)
Expand Down Expand Up @@ -153,4 +157,6 @@ cdef class AssSubtitle(Subtitle):

@property
def ass(self):
return self.ptr.ass
if self.ptr.ass is not NULL:
return PyBytes_FromString(self.ptr.ass)
return b""
2 changes: 1 addition & 1 deletion tests/test_subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_movtext(self):
sub = subset[0]
self.assertIsInstance(sub, AssSubtitle)
self.assertEqual(sub.type, b"ass")
self.assertEqual(sub.ass, "0,0,Default,,0,0,0,,- Test 1.\\N- Test 2.")
self.assertEqual(sub.ass, b"0,0,Default,,0,0,0,,- Test 1.\\N- Test 2.")

def test_vobsub(self):
path = fate_suite("sub/vobsub.sub")
Expand Down

0 comments on commit c6f80a3

Please sign in to comment.