def test_parse_no_cover_data(self):
     _, lib_version_str, lib_version = MediaInfo._get_library()
     if lib_version < (18, 3):
         pytest.skip(
             "Cover_Data option not supported by this library version "
             "(v{} detected, v18.03 required)".format(lib_version_str))
     self.assertEqual(self.no_cover_mi.tracks[0].cover_data, None)
Beispiel #2
0
async def media_info(data: SeekableIO) -> PyMediaInfo:
    lib, handle, _str_version, lib_version = PyMediaInfo._get_library()

    xml_option = "OLDXML" if lib_version >= (17, 10) else "XML"
    lib.MediaInfo_Option(handle, "CharSet", "UTF-8")
    lib.MediaInfo_Option(handle, "Inform", xml_option)
    lib.MediaInfo_Option(handle, "Complete", "1")
    lib.MediaInfo_Option(handle, "ParseSpeed", "0.5")

    size = await measure(data)
    lib.MediaInfo_Open_Buffer_Init(handle, size, 0)

    # mediainfo doesn't need to read the entire file, and the read_chunked
    # generator won't rewind on its own if it isn't fully exhausted
    async with rewind(data):
        async for chunk in read_chunked_binary(data):
            lc = len(chunk)
            if lib.MediaInfo_Open_Buffer_Continue(handle, chunk, lc) & 0x08:
                break

            seek = lib.MediaInfo_Open_Buffer_Continue_GoTo_Get(handle)

            if seek != ctypes.c_uint64(-1).value:
                await make_awaitable(data.seek(seek))
                lib.MediaInfo_Open_Buffer_Init(handle, size, seek)

    lib.MediaInfo_Open_Buffer_Finalize(handle)

    info: str = lib.MediaInfo_Inform(handle, 0)
    lib.MediaInfo_Close(handle)
    lib.MediaInfo_Delete(handle)
    return PyMediaInfo(info)
 def setUp(self):
     _, lib_version_str, lib_version = MediaInfo._get_library()
     if lib_version < (19, 9):
         pytest.skip(
             "Reset option not supported by this library version "
             "(v{} detected, v19.09 required)".format(lib_version_str))
     self.raw_language_mi = MediaInfo.parse(
         os.path.join(data_dir, "sample.mkv"),
         mediainfo_options={"Language": "raw"},
     )
     # Parsing the file without the custom options afterwards
     # allows us to check that the "Reset" option worked
     # https://github.com/MediaArea/MediaInfoLib/issues/1128
     self.normal_mi = MediaInfo.parse(os.path.join(data_dir,
                                                   "sample.mkv"), )
Beispiel #4
0
    def create(cls, os_family=None, suggested_path=None):
        """Create the executor instance."""
        for candidate in define_candidate(cls.locations, cls.names, os_family,
                                          suggested_path):
            if MediaInfo.can_parse(candidate):
                lib = MediaInfo._get_library(candidate)
                lib.MediaInfo_Option.argtypes = [
                    c_void_p, c_wchar_p, c_wchar_p
                ]
                lib.MediaInfo_Option.restype = c_wchar_p
                version = MediaInfoExecutor._get_version(
                    lib.MediaInfo_Option(None, "Info_Version", ""))

                logger.debug('MediaInfo library detected: %s (v%s)', candidate,
                             '.'.join(map(str, version)))
                return MediaInfoCTypesExecutor(candidate, version)
Beispiel #5
0
def _get_library_version():
    lib, handle, lib_version_str, lib_version = MediaInfo._get_library()
    lib.MediaInfo_Close(handle)
    lib.MediaInfo_Delete(handle)
    return lib_version_str, lib_version