Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress bar for parse_speed=1? #131

Open
pcroland opened this issue Nov 23, 2023 · 4 comments
Open

Progress bar for parse_speed=1? #131

pcroland opened this issue Nov 23, 2023 · 4 comments

Comments

@pcroland
Copy link

Is it possible somehow to access how much of the file is already read so I could hook it up to a rich.Progress?

@sbraz
Copy link
Owner

sbraz commented Nov 23, 2023

Currently, it is not possible. @JeromeMartinez, any idea how we could implement this? Is there some way to connect a callback function?

@JeromeMartinez
Copy link

No callback function (yet), we have a callback function feature but there is no callback for a progress bar yet.
We have MediaInfo::State_Get(), value is between 0 and 10000, but you need a separate thread for probing the value.

@pcroland
Copy link
Author

Could I pipe the file through something that can read how many bytes has been read?

@sbraz
Copy link
Owner

sbraz commented Nov 26, 2023

Yes, the parse method accepts a file-like object so you could create a file-like object that does something every time its read() method is called.
Please take a look at the code if you want to understand how pymediainfo handles file-like objects:

try:
filename.seek(0, 2)
file_size = filename.tell()
filename.seek(0)
except AttributeError: # filename is not a file-like object
file_size = None
if file_size is not None: # We have a file-like object, use the buffer protocol:
# Some file-like objects do not have a mode
if "b" not in getattr(filename, "mode", "b"):
raise ValueError("File should be opened in binary mode")
lib.MediaInfo_Open_Buffer_Init(handle, file_size, 0)
while True:
buffer = filename.read(buffer_size)
if buffer:
# https://github.com/MediaArea/MediaInfoLib/blob/v20.09/Source/MediaInfo/File__Analyze.h#L1429
# 4th bit = finished
if lib.MediaInfo_Open_Buffer_Continue(handle, buffer, len(buffer)) & 0x08:
break
# Ask MediaInfo if we need to seek
seek = lib.MediaInfo_Open_Buffer_Continue_GoTo_Get(handle)
# https://github.com/MediaArea/MediaInfoLib/blob/v20.09/Source/MediaInfoDLL/MediaInfoJNI.cpp#L127
if seek != ctypes.c_uint64(-1).value:
filename.seek(seek)
# Inform MediaInfo we have sought
lib.MediaInfo_Open_Buffer_Init(handle, file_size, filename.tell())
else:
break
lib.MediaInfo_Open_Buffer_Finalize(handle)

On a side note, I just noticed that pymediainfo only seems to support seekable objects, so I created #132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants