                                 "index: %s", frame_name, str(idx))
                  del_count += 1
          return del_count
  
      def rename_faces(self):
          """ Rename the aligned faces to match their "
              new index in alignments file """
          current_frame = ""
          current_index = 0
          rename_count = 0
          for face in tqdm(self.items.file_list_sorted,
                           desc="Renaming aligned faces",
                           total=self.items.count):
  
              if face["frame_name"] not in self.removed:
                  continue
              current_index, current_frame = self.set_image_index(
                  current_index,
                  current_frame,
                  face["frame_name"])
              if current_index != face["face_index"]:
                  rename_count += self.rename_file(face,
                                                   current_frame,
                                                   current_index)
  
              current_index += 1
          if rename_count == 0:
              logger.info("No files were renamed. Exiting")
              return
          logger.info("%s face(s) were renamed to match with alignments file", rename_count)
  
      @staticmethod
      def set_image_index(index, current, original):
          """ Set the current processing image and index """
          idx = 0 if current != original else index
          return idx, original
  
      def rename_file(self, face, frame_name, index):
          """ Rename the selected file """
          old_file = face["face_name"] + face["face_extension"]
          new_file = "{}_{}{}".format(frame_name,
                                      str(index),
                                      face["face_extension"])
          src = os.path.join(self.items.folder, old_file)
          dst = os.path.join(self.items.folder, new_file)
          os.rename(src, dst)
          logger.verbose("Renamed '%s' to '%s'", src, dst)
          return 1
  
  
  class Legacy():
      """ Update legacy alignments:
  
          - Add frame dimensions
 
</s> remove                 logger.verbose("Removed alignment data for image: '%s'"
                               "index: %s", frame_name, str(idx))
 </s> add                 logger.verbose("Removed alignment data for image: '%s' index: %s",
                               frame_name, str(idx)) </s> remove 
    def map_face_names(self, alignments, sorted_alignments, frame):
        """ Map the old and new indexes for face renaming """
        map_faces = list()
        if not self.faces:
            return map_faces
        for idx, alignment in enumerate(alignments):
            idx_new = sorted_alignments.index(alignment)
            mapping = [{"old_name": face["face_fullname"],
                        "new_name": "{}_{}{}".format(frame,
                                                     idx_new,
                                                     face["face_extension"])}
                       for face in self.faces.file_list_sorted
                       if face["frame_name"] == frame
                       and face["face_index"] == idx]
            if not mapping:
                logger.warning("No face image found for frame '%s' at index %s", frame, idx)
            map_faces.extend(mapping)
        return map_faces

    def rename_faces(self, map_faces):
        """ Rename faces
            Done in 2 iterations as two files cannot share the same name """
        temp_ext = ".temp_move"
        for action in ("temp", "final"):
            for face in map_faces:
                old = face["old_name"]
                new = face["new_name"]
                if old == new:
                    continue
                old_file = old if action == "temp" else old + temp_ext
                new_file = old + temp_ext if action == "temp" else new
                src = os.path.join(self.faces.folder, old_file)
                dst = os.path.join(self.faces.folder, new_file)
                os.rename(src, dst)
                if action == "final":
                    logger.verbose("Renamed '%s' to '%s'", old, new)
 </s> add         return reindexed </s> remove         return self.remove_alignment(item)

    def faces_count_matches(self, item):
        """ Check the selected face exits """
        frame_name, number_alignments = item[0], item[2]
        number_faces = len(self.items.items.get(frame_name, list()))
        return bool(number_alignments in(0, number_faces))
 </s> add         pre_face_count = self.alignments.faces_count
        self.alignments.filter_hashes(face_hashes, filter_out=False)
        post_face_count = self.alignments.faces_count
        return pre_face_count - post_face_count </s> remove             iterator = list(item[3] for item in iterator())

        for item in tqdm(iterator() if self.type == "faces" else iterator,
                         desc="Processing alignments file",
                         total=self.alignments.frames_count):
            task = getattr(self, "remove_{}".format(self.type))
            del_count += task(item)
 </s> add             logger.debug("Removing Frames")
            for frame in tqdm(list(item[3] for item in self.alignments.yield_faces()),
                              desc="Removing Frames",
                              total=self.alignments.frames_count):
                del_count += task(frame)
        else:
            logger.debug("Removing Faces")
            del_count = task() </s> remove     def check_skipface(self, filename, face_idx):
        """ Check whether face is to be skipped """
        if self.faces_to_swap is None:
            return False
        face_name = "{}_{}{}".format(Path(filename).stem,
                                     face_idx,
                                     Path(filename).suffix)
        face_file = Path(self.args.input_aligned_dir) / Path(face_name)
        skip_face = face_file not in self.faces_to_swap
        if skip_face:
            logger.info("face %s for frame '%s' was deleted, skipping",
                        face_idx, os.path.basename(filename))
        return skip_face

 </s> add 
                                 "index: %s", frame_name, str(idx))
                  del_count += 1
          return del_count
  













































  
  class Legacy():
      """ Update legacy alignments:
  
          - Add frame dimensions
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Add Face Hashes to Alignments (#550)

* Convert main scripts to use face hashes

* Alignment tool: Use hashes, add logging, add face rename function

* More logging. Update Manual tool to work with hashing 
tools/lib_alignments/jobs.py