Use the OLDXML output type for the new version of mediainfo

Fixes: https://launchpad.net/bugs/1732348
This commit is contained in:
Phill Ridout 2017-11-15 21:58:19 +00:00
parent 35e13022a6
commit 3560b27bfb
2 changed files with 16 additions and 6 deletions

View File

@ -25,10 +25,10 @@ information related to the rwquested media.
"""
import json
import os
from subprocess import Popen
import re
from subprocess import Popen, check_output
from tempfile import mkstemp
import six
from bs4 import BeautifulSoup, NavigableString
ENV_DICT = os.environ
@ -80,7 +80,7 @@ class Track(object):
def to_data(self):
data = {}
for k, v in six.iteritems(self.__dict__):
for k, v in self.__dict__.items():
if k != 'xml_dom_fragment':
data[k] = v
return data
@ -100,7 +100,11 @@ class MediaInfoWrapper(object):
@staticmethod
def parse(filename, environment=ENV_DICT):
command = ["mediainfo", "-f", "--Output=XML", filename]
if MediaInfoWrapper._version():
format = 'OLDXML'
else:
format = 'XML'
command = ["mediainfo", "-f", "--Output={format}".format(format=format), filename]
fileno_out, fname_out = mkstemp(suffix=".xml", prefix="media-")
fileno_err, fname_err = mkstemp(suffix=".err", prefix="media-")
fp_out = os.fdopen(fileno_out, 'r+b')
@ -116,6 +120,14 @@ class MediaInfoWrapper(object):
os.unlink(fname_err)
return MediaInfoWrapper(xml_dom)
@staticmethod
def _version():
# For now we're only intrested in knowing the new style version (yy.mm)
version_str = check_output(['mediainfo', '--version'])
return re.search(b'\d\d\.\d\d', version_str)
def _populate_tracks(self):
if self.xml_dom is None:
return

View File

@ -19,8 +19,6 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import os
import logging
import re
from subprocess import check_output, CalledProcessError