Deal better with missing stream info (e.g. channels)

This commit is contained in:
croneter 2017-10-06 08:41:16 +02:00
parent 38d611aa27
commit f3c71fadf2

View file

@ -1756,61 +1756,56 @@ class API():
subtitlelanguages = [] subtitlelanguages = []
try: try:
# Sometimes, aspectratio is on the "toplevel" # Sometimes, aspectratio is on the "toplevel"
aspectratio = self.item[0].attrib.get('aspectRatio', None) aspect = self.item[0].attrib.get('aspectRatio')
except IndexError: except IndexError:
# There is no stream info at all, returning empty # There is no stream info at all, returning empty
return { return {
'video': videotracks, 'video': videotracks,
'audio': audiotracks, 'audio': audiotracks,
'subtitle': subtitlelanguages 'subtitle': subtitlelanguages
} }
# TODO: what if several Media tags exist?!?
# Loop over parts # Loop over parts
for child in self.item[0]: for child in self.item[0]:
container = child.attrib.get('container', None) container = child.attrib.get('container')
# Loop over Streams # Loop over Streams
for grandchild in child: for grandchild in child:
mediaStream = grandchild.attrib stream = grandchild.attrib
mediaType = int(mediaStream.get('streamType', 999)) media_type = int(stream.get('streamType', 999))
if mediaType == 1: # Video streams track = {}
videotrack = {} if media_type == 1: # Video streams
videotrack['codec'] = mediaStream['codec'].lower() if 'codec' in stream:
if "msmpeg4" in videotrack['codec']: track['codec'] = stream['codec'].lower()
videotrack['codec'] = "divx" if "msmpeg4" in track['codec']:
elif "mpeg4" in videotrack['codec']: track['codec'] = "divx"
# if "simple profile" in profile or profile == "": elif "mpeg4" in track['codec']:
# videotrack['codec'] = "xvid" # if "simple profile" in profile or profile == "":
pass # track['codec'] = "xvid"
elif "h264" in videotrack['codec']: pass
if container in ("mp4", "mov", "m4v"): elif "h264" in track['codec']:
videotrack['codec'] = "avc1" if container in ("mp4", "mov", "m4v"):
videotrack['height'] = mediaStream.get('height', None) track['codec'] = "avc1"
videotrack['width'] = mediaStream.get('width', None) track['height'] = stream.get('height')
# TODO: 3d Movies?!? track['width'] = stream.get('width')
# videotrack['Video3DFormat'] = item.get('Video3DFormat') # track['Video3DFormat'] = item.get('Video3DFormat')
aspectratio = mediaStream.get('aspectRatio', aspectratio) track['aspect'] = stream.get('aspectRatio', aspect)
videotrack['aspect'] = aspectratio track['duration'] = self.getRuntime()[1]
# TODO: Video 3d format track['video3DFormat'] = None
videotrack['video3DFormat'] = None videotracks.append(track)
videotracks.append(videotrack) elif media_type == 2: # Audio streams
if 'codec' in stream:
elif mediaType == 2: # Audio streams track['codec'] = stream['codec'].lower()
audiotrack = {} if ("dca" in track['codec'] and
audiotrack['codec'] = mediaStream['codec'].lower() "ma" in stream.get('profile', '').lower()):
if ("dca" in audiotrack['codec'] and track['codec'] = "dtshd_ma"
"ma" in mediaStream.get('profile', '').lower()): track['channels'] = stream.get('channels')
audiotrack['codec'] = "dtshd_ma"
audiotrack['channels'] = mediaStream.get('channels')
# 'unknown' if we cannot get language # 'unknown' if we cannot get language
audiotrack['language'] = mediaStream.get( track['language'] = stream.get(
'languageCode', lang(39310)).lower() 'languageCode', lang(39310)).lower()
audiotracks.append(audiotrack) audiotracks.append(track)
elif media_type == 3: # Subtitle streams
elif mediaType == 3: # Subtitle streams
# 'unknown' if we cannot get language # 'unknown' if we cannot get language
subtitlelanguages.append( subtitlelanguages.append(
mediaStream.get('languageCode', stream.get('languageCode', lang(39310)).lower())
lang(39310)).lower())
return { return {
'video': videotracks, 'video': videotracks,
'audio': audiotracks, 'audio': audiotracks,
@ -2564,17 +2559,9 @@ class API():
Add media stream information to xbmcgui.ListItem Add media stream information to xbmcgui.ListItem
""" """
mediastreams = self.getMediaStreams() mediastreams = self.getMediaStreams()
videostreamFound = False for key, value in mediastreams.iteritems():
if mediastreams: if value:
for key, value in mediastreams.iteritems(): listItem.addStreamInfo(key, value)
if key == "video" and value:
videostreamFound = True
if value:
listItem.addStreamInfo(key, value)
if not videostreamFound:
# just set empty streamdetails to prevent errors in the logs
listItem.addStreamInfo(
"video", {'duration': self.getRuntime()[1]})
def validatePlayurl(self, path, typus, forceCheck=False, folder=False, def validatePlayurl(self, path, typus, forceCheck=False, folder=False,
omitCheck=False): omitCheck=False):