def run(self): self.waiting.emit() movieclip_associations_length = len(self.movieclip_associations) for index, movieclip_association in enumerate(self.movieclip_associations): assert not movieclip_association.skip filepath = movieclip_association.filepath if os.path.isdir(filepath): self.filesystem_error.emit(filepath) else: self.additional_descriptions["progress"] = "%s from %s" % (index+1, movieclip_associations_length) episode = movieclip_association.get_associated_episode_score()[0] if movieclip_association.movieclip is None: checksum = None if settings.get("hash_movieclips"): self.additional_descriptions["hash"] = "Calculating hash" checksum = self.calculate_checksum(filepath) self.additional_descriptions["hash"] = "" movieclip_association.movieclip = MovieClip(filepath, checksum=checksum) movieclip_association.movieclip.identifier = episode.identifier if not os.path.isfile(filepath) or not settings.is_valid_file_extension(filepath): self.filesystem_error.emit(filepath) elif settings.get("hash_movieclips") and not movieclips.check_unique(movieclip_association.movieclip, episode.get_identifier()): self.already_exists_in_another.emit() else: self.assign(movieclip_association) self.generate_thumbnails.emit(episode, movieclip_association.movieclip) self.finished.emit(episode, movieclip_association.movieclip)
def run(self): self.waiting.emit() self.filepath_list = self.create_filepath_list(self.filepath_dir_list) ''' Algorithm description: for each file do: a) see if file is valid: b) generate hash of file and look if an association exists, remember result c) if no association exists, generate levenshtein, remember result emit result into appropiate editor ''' movieclip_associations = [] filepath_list_length = len(self.filepath_list) for index, filepath in enumerate(self.filepath_list): self.progress.emit(index, filepath_list_length) movieclip_association = MovieClipAssociation(filepath) movieclip_associations.append(movieclip_association) self.additional_descriptions["progress"] = "%s from %s" % (index+1, filepath_list_length) filename, ext = os.path.splitext(os.path.basename(filepath)) if not os.path.isfile(filepath) or not settings.is_valid_file_extension(filepath): # a) movieclip_association.message = movieclip_association.INVALID_FILE movieclip_association.skip = True else: # b) checksum = None if settings.get("hash_movieclips"): self.additional_descriptions["hash"] = "Calculating hash" checksum = self.calculate_checksum(filepath) self.additional_descriptions["hash"] = "" movieclip = MovieClip(filepath, checksum = checksum) if settings.get("hash_movieclips"): episode_dict = movieclips.get_episode_dict_with_matching_checksums(movieclip.checksum) if not (not settings.get("hash_movieclips") or len(episode_dict.items()) == 0 or episode_dict.items()[0][0] is None): episode = episode_dict.items()[0][0] found_movieclip = episode_dict.items()[0][1] movieclip_association.episode_scores_list = [(episode, 0)] movieclip_association.movieclip = found_movieclip movieclip_association.message = movieclip_association.ASSOCIATION_FOUND else: # c) self.additional_descriptions["guess"] = "Guessing episode" episode_list = self.create_episode_list(self.series, filename) result = self.pool.map_async(generate_episode_score_list, episode_list) episode_score_list = result.get(timeout=100) episode_score_list.sort(key=itemgetter(1)) total_score = sum([score for episode, score in episode_score_list]) counter = len(episode_score_list) movieclip_association.movieclip = movieclip movieclip_association.episode_scores_list = episode_score_list movieclip_association.message = movieclip_association.ASSOCIATION_GUESSED movieclip_association.episode_score_information["mean"] = float(total_score) / float(counter) movieclip_association.episode_score_information["median"] = self.get_median([score for episode, score in episode_score_list]) self.additional_descriptions["guess"] = "" self.result.emit(movieclip_associations) self.finished.emit()