def useHeader(self, gzip): self.compression = gzip["compression"].display if gzip["mtime"]: self.last_modification = gzip["mtime"].value self.os = gzip["os"].display if gzip["has_filename"].value: self.filename = getValue(gzip, "filename") if gzip["has_comment"].value: self.comment = getValue(gzip, "comment") self.compr_size = gzip["file"].size // 8 self.file_size = gzip["size"].value
def useStreamProp(self, stream, index): meta = Metadata(self) meta.comment = "Start: %s" % stream["stream_start"].value if getValue(stream, "mime_type") == "logical-fileinfo": for prop in stream.array("file_info/prop"): self.useFileInfoProp(prop) else: meta.bit_rate = stream["avg_bit_rate"].value meta.duration = timedelta(milliseconds=stream["duration"].value) meta.mime_type = getValue(stream, "mime_type") meta.title = getValue(stream, "desc") self.addGroup("stream[%u]" % index, meta, "Stream #%u" % (1 + index))
def useAviHeader(self, header): microsec = header["microsec_per_frame"].value if microsec: self.frame_rate = 1000000.0 / microsec total_frame = getValue(header, "total_frame") if total_frame and not self.has("duration"): self.duration = timedelta(microseconds=total_frame * microsec) self.width = header["width"].value self.height = header["height"].value
def readVorbisComment(metadata, comment): metadata.producer = getValue(comment, "vendor") for item in comment.array("metadata"): if "=" in item.value: key, value = item.value.split("=", 1) key = key.upper() if key in VORBIS_KEY_TO_ATTR: key = VORBIS_KEY_TO_ATTR[key] setattr(metadata, key, value) elif value: metadata.warning("Skip Vorbis comment %s: %s" % (key, value))
def useCommon(self, info): self.nb_channel = info["nb_channel"].value self.bits_per_sample = info["sample_size"].value self.sample_rate = getValue(info, "sample_rate") if self.has("sample_rate"): rate = self.get("sample_rate") if rate: sec = float(info["nb_sample"].value) / rate self.duration = timedelta(seconds=sec) if "codec" in info: self.compression = info["codec"].display
def extractPE(self, exe): # Read information from headers if "pe_header" in exe: self.usePE_Header(exe["pe_header"]) if "pe_opt_header" in exe: self.usePE_OptHeader(exe["pe_opt_header"]) # Use PE resource resource = exe.getResource() if resource and "version_info/node[0]" in resource: for node in resource.array("version_info/node[0]/node"): if getValue(node, "name") == "StringFileInfo" \ and "node[0]" in node: self.readVersionInfo(node["node[0]"])
def useRoot(self, real): self.bits_per_sample = 16 # FIXME: Is that correct? if real["version"].value != 3: self.sample_rate = real["sample_rate"].value self.nb_channel = real["channels"].value else: self.sample_rate = 8000 self.nb_channel = 1 fourcc = getValue(real, "FourCC") if fourcc: self.compression = fourcc try: self.bit_rate = self.FOURCC_TO_BITRATE[fourcc] except LookupError: pass
def extract(self, riff, **kwargs): type = riff["type"].value if type == "WAVE": self.extractWAVE(riff) size = getValue(riff, "audio_data/size") if size: computeAudioComprRate(self, size * 8) elif type == "AVI ": if "headers" in riff: if 'scan_index' in kwargs: self.extractAVI(riff["headers"], scan_index=kwargs['scan_index']) else: self.extractAVI(riff["headers"]) self.extractInfo(riff["headers"]) elif type == "ACON": self.extractAnim(riff) if "info" in riff: self.extractInfo(riff["info"])
def extract(self, real): version = real["version"].value if "metadata" in real: self.useMetadata(real["metadata"]) self.useRoot(real) self.format_version = "Real audio version %s" % version if version == 3: size = getValue(real, "data_size") elif "filesize" in real and "headersize" in real: size = (real["filesize"].value + 40) - (real["headersize"].value + 16) else: size = None if size: size *= 8 if self.has("bit_rate"): sec = float(size) / self.get('bit_rate') self.duration = timedelta(seconds=sec) computeComprRate(self, size)