def extract_contents(self, tmp_dir): try: total = len(execute(["identify", self.get_filename()]).split("\n")) basename, _, ext = self.get_basename().rpartition(".") tmp_root = os.path.join(tmp_dir, "%s_%%04d.%s" % (basename, ext)) # http://www.imagemagick.org/Usage/anim_basics/#coalesce child = pexpect.spawn("convert", ["-verbose", self.get_filename(), "-coalesce", tmp_root]) index = 0 while True: try: child.expect(self.get_filename() + "\=\>") index += 1 except pexpect.TIMEOUT: pass yield float(index) / total except pexpect.EOF: pass except Exception as e: print("Warning:", e)
def get_metadata(self): info = [("Property", "Value")] output = execute(["pdfinfo", self.get_filename()], check_retcode=False) for line in filter(lambda x: x, output.split("\n")): tokens = map(string.strip, line.split(":")) info.append((tokens[0], string.join(tokens[1:], ""))) return info
def get_metadata(self): ret = [("Filename", "Size", "Date", "Time")] output = execute(["unzip", "-l", self.filename], check_retcode=False) lines = output.split("\n") for line in lines[3:-3]: tokens = map(string.strip, filter(lambda x: x, line.split(" "))) ret.append((string.join(tokens[3:], " "), Size(int(tokens[0])), tokens[1], tokens[2])) return ret
def get_pixbuf(self): tmp_root = os.path.join(tempfile.gettempdir(), "%s" % self.get_basename()) execute(["pdfimages", "-f", "1", "-l", "1", "-j", self.get_filename(), tmp_root]) for ext in ["jpg", "pbm", "ppm"]: try: tmp_img = "%s-000.%s" % (tmp_root, ext) pixbuf = gtk.gdk.pixbuf_new_from_file(tmp_img) for filename in glob.glob(tmp_root + "*"): os.unlink(filename) return pixbuf except: continue print "Warning: unable to preview PDF file '%s'" % self.get_basename() return GTKIconImage(gtk.STOCK_MISSING_IMAGE, 256).get_pixbuf()
def get_metadata(self): info = [("Property", "Value")] output = execute(["avconv", "-i", self.get_filename()], check_retcode=False) for line in filter(lambda x: x, output.split("\n"))[4:]: tokens = map(string.strip, line.split(":")) if tokens[0].startswith("Stream"): break # Stop when avconv starts to dump streams metadata info.append((tokens[0], string.join(tokens[1:], ":"))) return info
def get_metadata(self): ret = [("Filename", "Original Size", "Packed Size", "Ratio", "Date", "Time", "Attr")] output = execute(["unrar", "l", "-c-", self.filename], check_retcode=False) lines = output.split("\n") for line in lines[7:-4]: # 0 1 2 3 4 5 6 7 8 9 # Name Size Packed Ratio Date Time Attr CRC Meth Ver # -9 -8 -7 -6 -5 -4 -3 -2 -1 tokens = list(map(string.strip, [x for x in line.split(" ") if x])) ret.append((string.join(tokens[0:-9], " "), Size(int(tokens[-9])), Size(int(tokens[-8])), tokens[-7], tokens[-6], tokens[-5], tokens[-4])) return ret
def extract_frame_at(self, second, output): execute(["avconv", "-ss", str(second), "-i", self.get_filename(), "-vframes", "1", "-an", output])
def on_open_nautilus(self, widget): execute(["nautilus", self.curdir])