From 0d0832582a3a4d50a14d44418761a328d63804fd Mon Sep 17 00:00:00 2001 From: Tom Sitter Date: Thu, 19 Oct 2023 16:57:08 -0400 Subject: [PATCH 1/2] Add buffer_size arg --- pymediainfo/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pymediainfo/__init__.py b/pymediainfo/__init__.py index 840ec18..672998f 100644 --- a/pymediainfo/__init__.py +++ b/pymediainfo/__init__.py @@ -362,6 +362,7 @@ def parse( full: bool = True, legacy_stream_display: bool = False, mediainfo_options: Optional[Dict[str, str]] = None, + buffer_size: Optional[int] = 64 * 1024, output: Optional[str] = None, ) -> Union[str, "MediaInfo"]: """ @@ -392,6 +393,8 @@ def parse( `MediaInfo_Option` function, for example: ``{"Language": "raw"}``. Do not use this parameter when running the method simultaneously from multiple threads, it will trigger a reset of all options which will cause inconsistencies or failures. + :param int buffer_size: size of the buffer used to read the file, in bytes. This is only + used when `filename` is a file-like object. :param str output: custom output format for MediaInfo, corresponds to the CLI's ``--Output`` parameter. Setting this causes the method to return a `str` instead of a :class:`MediaInfo` object. @@ -467,7 +470,7 @@ def parse( raise ValueError("File should be opened in binary mode") lib.MediaInfo_Open_Buffer_Init(handle, file_size, 0) while True: - buffer = filename.read(64 * 1024) + buffer = filename.read(buffer_size) if buffer: # https://github.com/MediaArea/MediaInfoLib/blob/v20.09/Source/MediaInfo/File__Analyze.h#L1429 # 4th bit = finished From c92878eea191427209c28470990fc92add8d8b8f Mon Sep 17 00:00:00 2001 From: Tom Sitter Date: Mon, 23 Oct 2023 11:53:18 -0400 Subject: [PATCH 2/2] move buffer_size to end of list --- pymediainfo/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymediainfo/__init__.py b/pymediainfo/__init__.py index 672998f..bf34ea7 100644 --- a/pymediainfo/__init__.py +++ b/pymediainfo/__init__.py @@ -362,8 +362,8 @@ def parse( full: bool = True, legacy_stream_display: bool = False, mediainfo_options: Optional[Dict[str, str]] = None, - buffer_size: Optional[int] = 64 * 1024, output: Optional[str] = None, + buffer_size: Optional[int] = 64 * 1024, ) -> Union[str, "MediaInfo"]: """ Analyze a media file using libmediainfo.