示例#1
0
	def _parseMediaInfo(self):
		"""
		Invoke the external program MediaInfo and parse its output
		to a dictionary
		"""
		# the program path to MediaInfo should be set otherwise
		env = {'path': env_mediainfo_dir}
		# the command for MediaInfo is a fixed command
		com = [com_mediainfo, '-f', self.name]
		# invoke the external program
		proc = externalProcess(com, env)
		# read the programs output line by line and parse the output to a dictionary, obtaining all information
		info = {}
		state = 'start'
		stream = 0
		for line in proc.execute():
			list = line.split(":")
			# recognize the sections ('General','Video','Audio','Text')
			if len(list) == 1 and list[0] != '':
				state = str(list[0].lstrip().rstrip())
				# print "New state: ", state
			elif len(list) >= 2 and list[0] != '' and list[1] != '':
				# recognize several stream identifier
				if str(list[0].lstrip().rstrip()) == 'Stream identifier':
					stream = int(str(list[1].lstrip().rstrip()))
					continue
				# save the information to the dictionary
				key = state + "_" + str(stream) + "_" + str(list[0].lstrip().rstrip())
				while key in info.keys():
					key += "_"
				info[key] = str(list[1].lstrip().rstrip())
		return info
	def runTest(self):
		self.process = externalProcess(com_1, env)
		assert self.process != None, '  Could not initialize external process'

		count = 0
		for line in self.process.execute():
			count += 1
			print count, line

		assert count == 23, '  external process returned wrong number of lines'