I've been searching for several days on how to incorporate the '-show_format_entry' into my Python script that uses ffprobe to extract the metadata from all the audio and visual files in a directory. However, I don't want everything that format gives back.
My current script:
#! usr/bin/python
import os, sys, subprocess, shlex, re, fnmatch
from subprocess import call
def probe_file(filename):
cmnd = ['ffprobe', '-show_format', ,'-pretty', '-loglevel' filename]
p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out
mp3box=[]
for root, dirs, files in os.walk('/home/username/Music'):
for fname in files:
name,ext=os.path.splitext(fname)
if fname.lower().endswith('.mp3'):
mp3box.append(fname)
probe_file(fname)
The output is something like:
[FORMAT]
filename=test.mp3
nb_streams=1
format_name=mp3
format_long_name=MPEG audio layer 2/3
start_time=0:00:00.000000
duration=0:03:32.943917
size=2.437 Mibyte
bit_rate=95.999 Kbit/s
TAG:album=compliments of grimriper2u@yahoo.com
TAG:artist=Charley Barnet, V=Trudy Richard
TAG:disc=sound changed and copyright for public Domain. not for resale.
TAG:genre=Jazz
TAG:TLEN=000000212342
TAG:title= Ill Wind
TAG:date=1949
[/FORMAT]
[FORMAT]
filename=barnet.mp3
nb_streams=1
format_name=mp3
format_long_name=MPEG audio layer 2/3
start_time=0:00:00.000000
duration=0:03:32.943917
size=2.437 Mibyte
bit_rate=95.999 Kbit/s
TAG:album=compliments of grimriper2u@yahoo.com
TAG:artist=Charley Barnet, V=Trudy Richard
TAG:disc=sound changed and copyright for public Domain. not for resale.
TAG:genre=Jazz
TAG:TLEN=000000212342
TAG:title= Ill Wind
TAG:date=1949
[/FORMAT]
What I want, is to be able to use the generic ffprobe option, '-show_format_entry' and specify '-show_format_entry filename', '-show_format_entry duration', '-show_format_entry size' to get only the filename, duration and size in the output.
I've also tried grep|duration after 'filename' in the cmnd to isolate those values in the output but it doesn't work. Also, if I could, I would like to get rid of the [FORMAT][/FORMAT] tags in the ouput but that is not totally necessary. Any feedback is greatly appreciated.