pythonmediainfo

Extracting Movie name using mediainfo within python


I can get the Movie name from my avi files with the command line

mediainfo --Inform="General;%Movie%" file.avi

In python I have access to the mediainfo structure

mediainfo = MediaInfo.parse(filename)

But nowhere can I find out how the command line matches to the data structure. The sparse documentation and all examples talk about track structures, when my item is in General

NO IDEA WHY THIS SITE ONLY ALLOWS VERY SHORT COMMENTS, BELOW IS A COMMENT

I am confused. The code I'm looking at is nemo-media-columns.py (https://github.com/linuxmint/nemo-extensions/blob/master/nemo-media-columns/nemo-media-columns.py) has

from pymediainfo import MediaInfo ... mediainfo = MediaInfo.parse(filename)

            duration = 0

            for trackobj in mediainfo.tracks:
                track = trackobj.to_data()

                if track["track_type"] == "Video":
                    try:
                        info.pixeldimensions = "%dx%d" % (track["width"], track["height"])
                    except:
                        pass

Which is entirely different syntax from your suggestion, and the example talks about DLLs which don't exist in my Linux world. I'm baffled with it all, and as the code is buried within the application diagnostics are hard.


Solution

  • I ended up with:

    #!/usr/bin/python3
    
    from pymediainfo import MediaInfo
    
    mediainfo = MediaInfo.parse('1.avi')
    
    for trackobj in mediainfo.tracks:
        track = trackobj.to_data()
    
        if track["track_type"] == "General":
            try:
                title = (track['title'])
            except:
                title = 'Unknown'
    
    print(title)