def __init__(self, movieclip, episode): WorkerThread.__init__(self) self.filepath = os.path.normpath(movieclip.filepath) self.movieclip = movieclip self.episode = episode self.image_list = [] self.timecode = [] self.description = "Generating thumbnails" self.number_of_thumbnails = settings.get("number_of_thumbnails")
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 assign(self, movieclip_association): """ Here is a list of possibilities that might occur: a) The clip is already in the movieclip dict and in its designated folder b) The clip is already in the movieclip dict, but not in its designated folder c) The clip is not in the movieclip dict but already in the folder d) The clip is not in the movieclip dict and not in the folder """ filename = os.path.basename(movieclip_association.filepath) episode, score = movieclip_association.get_associated_episode_score() # Calculate hypothetical filepath destination = settings.calculate_filepath(episode, filename) directory = os.path.dirname(destination) if movieclip_association.movieclip in movieclips[episode.get_identifier()]: if os.path.isfile(destination): # a) self.already_exists.emit(episode, movieclip_association.filepath) move_to_folder = False add_to_movieclips = False else: # b) move_to_folder = True add_to_movieclips = False else: if os.path.isfile(destination): # c) move_to_folder = True add_to_movieclips = True else: # d) move_to_folder = True add_to_movieclips = True if move_to_folder and (movieclip_association.placement_policy != PlacementPolicy.DONT_TOUCH): # Check if there is already a file with the same name, normalizes file name if set to do so filename = settings.get_unique_filename(destination, episode) # Move the file to the actual folder copy_move = "Moving" if settings.get("placement_policy") == PlacementPolicy.COPY: copy_move = "Copying" self.additional_descriptions["moving"] = "%s movie clip to destination" % copy_move settings.move_file_to_folder_structure(episode, movieclip_association.filepath, movieclip_association.placement_policy, new_filename=filename) self.additional_descriptions["moving"] = "" # Set the old file path to the current one movieclip_association.movieclip.old_filepath = movieclip_association.movieclip.filepath # Update the filepath of the clip movieclip_association.movieclip.filepath = os.path.join(directory, filename) if add_to_movieclips: # Add the clips to the movie clips manager movieclips.add(movieclip_association.movieclip) self.load_information.emit(episode)
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()
def update_movie(self, movie): if isinstance(movie, Series): self.update_series(movie, merge_policy=settings.get("merge_policy_series")) else: self.update_episode(movie, merge_policy=settings.get("merge_policy_episode"))