示例#1
0
文件: _file.py 项目: gerdemb/shashin
    def execute(self):
        with Exif() as et:
            for file in path_file_walk(self.src):
                try:
                    metadata = et.get_metadata(file)
                except Exception as e:
                    print(f"# ERROR rm {qp(file)} # {e}")
                    continue

                hierarchy = self.template.render(metadata).strip()
                dest_path = self.dest / hierarchy / file.name

                # Is the file already in the right place?
                if dest_path != file:
                    if dest_path.exists():
                        if self.verbose:
                            print(
                                f"# WARNING {self.action_name} {qp(file)} {qp(dest_path)} # Destination file already exists"
                            )
                    else:
                        if not dest_path.parent.exists():
                            print(f"mkdir -p {qp(dest_path.parent)}")
                            dest_path.parent.mkdir(parents=True, exist_ok=True)
                        if not self.quiet:
                            print(
                                f"{self.action_name} {qp(file)} {qp(dest_path)}"
                            )
                        if not self.dry_run:
                            self.action(file, dest_path)
示例#2
0
    def create_exif(self, img, coords):
        with open(img, 'rb') as file:
            file = Exif(file)

            file.gps_latitude = coords['lat']
            file.gps_longitude = coords['lon']

            with open(img, 'wb') as new_image_file:
                new_image_file.write(file.get_file())
示例#3
0
    def read_exif(self, img):
        with open(img, 'rb') as file:
            self.img_metas = Exif(file)

        if self.img_metas.has_exif:
            print(f'Exif : {self.img_metas.has_exif}')
            date = self.img_metas.datetime_original
            date = bytes(date, 'utf-8')
            date = date.decode('utf-8')
            print(date)
            return date
        else:
            print(f'Exif : {self.img_metas.has_exif}')
            return False
示例#4
0
 def execute(self):
     with DB(self.cache_dir) as db:
         with Exif() as et:
             for scan_dir in self.scan_dirs:
                 for file in path_file_walk(scan_dir):
                     try:
                         action = self.scan_file(db, et, file)
                     except Exception as e:
                         print(f"# ERROR rm {qp(file)} # {e}")
                         continue
                     if self.verbose and action is None:
                         print(f"# SKIPPED {file}")
                     elif not self.quiet and action:
                         print(f"{action.upper()} {qp(file)}")
         self.scan_db(db)
示例#5
0
    def parse(self, jpeg):
        self.__offset = 2

        result = {}

        while True:
            segment_marker = struct.unpack_from("2c", jpeg, self.__offset)
            self.__offset += 2

            if segment_marker == self.__SOS:
                break

            if segment_marker == self.__EOI:
                break

            segment_length = struct.unpack_from(">H", jpeg, self.__offset)[0]
            for frame_header_marker in self.__SOFs:
                if segment_marker == frame_header_marker:
                    (height, width, channels) = struct.unpack_from(">HHB", jpeg, self.__offset + 3)
                    result["width"] = width
                    result["height"] = height
                    result["mode"] = self.__get_color_mode(channels)
                    break

            if segment_marker == self.__APP1:
                app1_magic = struct.unpack_from("6c", jpeg, self.__offset + 2)
                if app1_magic == (b'\x45', b'\x78', b'\x69', b'\x66', b'\x00', b'\x00'):
                    exif_parser = Exif(jpeg, self.__offset + 8, segment_length)
                    tags = [
                        (271, "maker"),
                        (272, "model"),
                        (2, "latitude"),
                        (4, "longitude"),
                        (36867, "DateTimeOriginal")
                    ]
                    for tag in tags:
                        try:
                            value = exif_parser.search_tag(jpeg, target_tag=tag[0], clear_offset=True)
                            result[tag[1]] = value
                        except ValueError:
                            pass

            self.__offset += segment_length

        return result
示例#6
0
文件: browse.py 项目: gerdemb/shashin
        def index():
            with DB(self.cache_dir) as db:
                with Exif() as et:
                    start = bytes.fromhex(request.args.get('start', ''))
                    rows = db.image_select_duplicate_dhash(start).fetchall()

                    duplicates = get_duplicates(et, rows, predictor)

                    if duplicates:
                        alerts = get_alerts(duplicates)

                        last_dhash = rows[-1]['dhash']
                        # Maximum hash value as a long
                        percentage = (
                            100 * int.from_bytes(last_dhash, "big")
                        ) / 340282366920938463463374607431768211455
                        return render_template('index.html',
                                               duplicates=duplicates,
                                               alerts=alerts,
                                               percentage=percentage,
                                               last_dhash=last_dhash.hex())
                    else:
                        return render_template('empty.html')
示例#7
0
 def execute(self):
     with DB(self.cache_dir) as db:
         with Exif() as et:
             for row in db._execute(self.sql_select, self.sql_params):
                 self.process_row(et, row)
示例#8
0
 def __init__(self, img_path):
     with open(img_path, 'rb') as file:
         self.image = Exif(file)
示例#9
0
 def _read(self):
     self.extra_zero = self._io.ensure_fixed_contents(b"\x00")
     self._raw_data = self._io.read_bytes_full()
     io = KaitaiStream(BytesIO(self._raw_data))
     self.data = Exif(io)