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

AttributeError: 'NoneType' object has no attribute 'groups' #16

Open
ghost opened this issue May 27, 2021 · 3 comments
Open

AttributeError: 'NoneType' object has no attribute 'groups' #16

ghost opened this issue May 27, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented May 27, 2021

Hey folks,

this lib seems exactly what im looking for but Im unable to properly parse all information using the following snipped:

#!/usr/bin/env python

from ffprobe import FFProbe

# Local file
metadata=FFProbe('/home/mike/Desktop/2 Wie werde ich ein Hase.m4v')

for stream in metadata.streams:
    if stream.is_video():
        print('Stream contains {} frames.'.format(stream.frames()))

I always get back the following error:

File "/home/mike/Documents/PyCharm/Strics.io/strics_app/strics_app/meta_scrape.py", line 6, in <module>
    metadata=FFProbe('/home/mike/Desktop/2 Wie werde ich ein Hase.m4v')
  File "/home/claris/Documents/PyCharm/Strics.io/strics_app/venv/lib/python3.9/site-packages/ffprobe/ffprobe.py", line 75, in __init__
    self.metadata[m.groups()[0]] = m.groups()[1].strip()
AttributeError: 'NoneType' object has no attribute 'groups'

can smb help ?

@ghost
Copy link
Author

ghost commented May 27, 2021

And why does this lib even exists if I can do:

ffprobe -print_format json -show_streams -show_format -loglevel quiet -hide_banner

@miversen33
Copy link

miversen33 commented Aug 27, 2021

It looks like the issue is a regex problem. My exception was raised on this line

' Chapter #0:0: start 0.000000, end 485.902000\n'

In particular, on the string

end 485.902000\n

The regex being used to piece this apart

m = re.search(r'(\w+)\s*:\s*(.*)$', s)

Wont return anything as the string above doesn't match the regex listed. I am not quite sure the best way to go about parsing that out, though to @venomone 's point, this entire script could be redone to simply wrap and ingest the output of -print_format json -show_format

Also probably worth using that -hide_banner flag to ignore parsing out (and ignoring) the banner text displayed by ffprobe.

Both these options appear to be quite old in ffprobe, so they should be safe to use here.
https://github.com/FFmpeg/FFmpeg/blame/master/fftools/ffprobe.c
If I have more time I might look into doing that. For now though I am going to have to abandon this project and inject the output json myself

@jboy
Copy link

jboy commented Aug 13, 2023

If anyone's looking for a longer-term solution, I've implemented the above
ffprobe -print_format json -show_streams -show_format
command-line, plus a bunch of other bug-fixes, features, and improvements, in a fork:
https://github.com/jboy/ffprobe3-python3

(Python3 only, sorry.)

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

2 participants