def audioChannels(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "audio": data = int(stream.getAttribute("channels")) if data == 0: raise NoDataException( "Cannot find any audio channels for " + self.file_name) return data
def audioBitRateH(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "audio": data = self.__sizeofHuman(int(stream.getAttribute("bit_rate"))) if data is None or data == "": raise NoDataException("Cannot find a bit rate for " + self.file_name) return data
def audioBitDepth(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "audio": data = int(AUDIO_BIT_DEPTHS[stream.getAttribute("sample_fmt")]) if data == 0: raise NoDataException("cannot find the bit depth for " + self.file_name) return data
def totalSeconds(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "audio": duration = float(stream.getAttribute("duration")) if duration is None or duration == "": raise NoDataException("Could not calculate the number of total seconds for " + self.file_name) return duration pass
def audioSampleRate(self): # TODO Make audioSampleRate Method for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "audio": data = int(stream.getAttribute("sample_rate")) if data == 0 or data is None: raise NoDataException("Cannot find a sample rate for " + self.file_name) return data
def audioCodecLongName(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "audio": data = str(stream.getAttribute("codec_long_name")) if data is None or data == "": raise NoDataException( "Cannot find any audio codec long name for " + self.file_name) return data
def videoBitRate(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "video": data = int(stream.getAttribute("bit_rate")) if data == 0: raise NoDataException( "Cannot calculate the video bit rate for " + self.file_name) return data
def videoAspectRatio(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "video": data = str(stream.getAttribute("display_aspect_ratio")) if data is None: raise NoDataException( "Cannot calculate the video aspect ratio for " + self.file_name) return data
def videoResolutionWidth(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "video": data = int(stream.getAttribute("width")) if data == 0: raise NoDataException( "Cannot calculate the video width resolution for " + self.file_name) return data
def videoResolution(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "video": height = stream.getAttribute("height") width = stream.getAttribute("width") if height is None or height == "" or width is None or width == "": raise NoDataException( "Cannot calculate the video resolution for " + self.file_name) return width + " x " + height
def totalRunningTimeRaw(self): for stream in self.xmlDom.getElementsByTagName('stream'): if stream.getAttribute("codec_type") == "audio": duration = float(stream.getAttribute("duration")) if duration is None or duration == "": raise NoDataException("Could not calculate a duration for " + self.file_name) return duration # print self.fileXML # return self.___totalRunningTimeRaw pass
def MD5_hash(self): if self._MD5: return self._MD5 elif self._calculation.isAlive: self._calculation.join() # self._MD5 = self.calculation return self._MD5 else: raise NoDataException("MD5 not calculated yet for " + self.___source)
def calculate_MD5(self, progress=False, threaded=False): if self.___source is None or self.___source == "": raise NoDataException("No file not set") if threaded: self._calculation = threading.Thread(target=self._calculate_MD5, args=(progress, )) self._calculation.daemon = True self._calculation.start() else: MD5 = self._calculate_MD5(progress) self._MD5 = MD5 return MD5
def calculate_SHA1(self, verbose=False): if self.___source is None or self.___source == "": raise NoDataException("No file not set") sha1 = hashlib.sha1() total = self.file_size with open(self.___source, 'rb') as f: i = float(0) for chunk in iter(lambda: f.read(BUFFER), b''): if verbose: i += BUFFER completed = int((i / total) * 100) print((str(completed) + "%")) sha1.update(chunk) return sha1.hexdigest()
def totalRunningTimeSMPTE(self): # for stream in self.xmlDom.getElementsByTagName('stream'): # if stream.getAttribute("codec_type") == "audio": # seconds = float(stream.getAttribute("duration"))#TODO create SMPTE TRT return # break # # m, s = divmod(seconds, 60) # h, m = divmod(m, 60) # return str(int(h)).zfill(2) + ":" + str(int(m)).zfill(2) + ":" + str(int(s)).zfill(2) REGEX_DURATION_PATTERN = '(?<=(Duration: ))\d\d:\d\d:\d\d.\d\d(?=,)' # print self.raw_stderr results = search(REGEX_DURATION_PATTERN, self.raw_stderr).group(0) # print if results is None or results == "": raise NoDataException("Could not calculate the total Running Time in SMPTE for " + self.file_name) return results pass
def file_size(self): if self.___source is None or self.___source == "": raise NoDataException("No file not set") return getsize(self.___source)
def date_last_modified(self): if self.___source is None or self.___source == "": raise NoDataException("No file not set") return ctime(getmtime(self.___source))
def file_size_human(self): if self.___source is None or self.___source == "": raise NoDataException("No file not set") return self.__sizeofHuman(self.file_size)