def _search_video(self, titles, episode): best_candidate = (None, 0) matcher = difflib.SequenceMatcher() # Check over video files and propose our best candidate for (fullpath, filename) in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']): # Use our analyze function to see what's the title and episode of the file (candidate_title, candidate_episode) = utils.analyze(filename) # Skip this file if we couldn't analyze it or it isn't the episode we want if not candidate_title or candidate_episode != episode: continue matcher.set_seq1(candidate_title.lower()) # We remember to compare all titles (aliases and whatnot) for requested_title in titles: matcher.set_seq2(requested_title.lower()) ratio = matcher.ratio() # Propose as our new candidate if its ratio is # better than threshold and it's better than # what we've seen yet if ratio > 0.7 and ratio > best_candidate[1]: best_candidate = (fullpath, ratio) return best_candidate[0]
def _search_video(self, titles, episode): best_candidate = (None, 0, None) matcher = difflib.SequenceMatcher() # Check over video files and propose our best candidate for (fullpath, filename) in utils.regex_find_videos("mkv|mp4|avi", self.config["searchdir"]): # Analyze what's the title and episode of the file aie = extras.AnimeInfoExtractor.AnimeInfoExtractor(filename) candidate_title = aie.getName() candidate_episode_start, candidate_episode_end = aie.getEpisodeNumbers() # Skip this file if we couldn't analyze it or it isn't the episode we want if ( not candidate_title or not (episode >= candidate_episode_start and episode <= candidate_episode_end) or (candidate_episode_end == "" and episode != candidate_episode_start) ): continue matcher.set_seq1(candidate_title.lower()) # We remember to compare all titles (aliases and whatnot) for requested_title in titles: matcher.set_seq2(requested_title.lower()) ratio = matcher.ratio() # Propose as our new candidate if its ratio is # better than threshold and it's better than # what we've seen yet if ratio > 0.7 and ratio > best_candidate[1]: best_candidate = (fullpath, ratio, aie.getEpisode()) return best_candidate[0], best_candidate[2]
def _search_video(self, titles, episode): best_candidate = (None, 0) matcher = difflib.SequenceMatcher() # Check over video files and propose our best candidate for (fullpath, filename) in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']): # Analyze what's the title and episode of the file aie = tracker.AnimeInfoExtractor(filename) (candidate_title, candidate_episode) = (aie.getName(), aie.getEpisode()) # Skip this file if we couldn't analyze it or it isn't the episode we want if not candidate_title or candidate_episode != episode: continue matcher.set_seq1(candidate_title.lower()) # We remember to compare all titles (aliases and whatnot) for requested_title in titles: matcher.set_seq2(requested_title.lower()) ratio = matcher.ratio() # Propose as our new candidate if its ratio is # better than threshold and it's better than # what we've seen yet if ratio > 0.7 and ratio > best_candidate[1]: best_candidate = (fullpath, ratio) return best_candidate[0]
def scan_library(self, my_status=None, ignorecache=False): # Check if operation is supported by the API if not self.mediainfo.get("can_play"): raise utils.EngineError("Operation not supported by current site or mediatype.") if not self.config["searchdir"]: raise utils.EngineError("Media directory is not set.") if not utils.dir_exists(self.config["searchdir"]): raise utils.EngineError("The set media directory doesn't exist.") t = time.time() library = {} library_cache = self.data_handler.library_cache_get() if not my_status: my_status = self.mediainfo["status_start"] self.msg.info(self.name, "Scanning local library...") tracker_list = self._get_tracker_list(my_status) # Do a full listing of the media directory for fullpath, filename in utils.regex_find_videos("mkv|mp4|avi", self.config["searchdir"]): show_id = None if not ignorecache and filename in library_cache.keys(): # If the filename was already seen before # use the cached information, if there's no information (None) # then it means it doesn't correspond to any show in the list # and can be safely skipped. if library_cache[filename]: show_id = library_cache[filename][0] show_ep = library_cache[filename][1] else: continue else: # If the filename has not been seen, extract # the information from the filename and do a fuzzy search # on the user's list. Cache the information. # If it fails, cache it as None. aie = extras.AnimeInfoExtractor.AnimeInfoExtractor(filename) (show_title, show_ep) = (aie.getName(), aie.getEpisode()) if show_title: show = utils.guess_show(show_title, tracker_list) if show: show_id = show["id"] library_cache[filename] = (show["id"], show_ep) else: library_cache[filename] = None else: library_cache[filename] = None # After we got our information, add it to our library if show_id: if show_id not in library.keys(): library[show_id] = {} library[show_id][show_ep] = fullpath self.msg.debug(self.name, "Time: %s" % (time.time() - t)) self.data_handler.library_save(library) self.data_handler.library_cache_save(library_cache) return library
def scan_library(self, my_status=None, ignorecache=False): # Check if operation is supported by the API if not self.mediainfo.get('can_play'): raise utils.EngineError( 'Operation not supported by current site or mediatype.') if not self.config['searchdir']: raise utils.EngineError('Media directory is not set.') if not utils.dir_exists(self.config['searchdir']): raise utils.EngineError('The set media directory doesn\'t exist.') t = time.time() library = {} library_cache = self.data_handler.library_cache_get() if not my_status: my_status = self.mediainfo['status_start'] self.msg.info(self.name, "Scanning local library...") tracker_list = self._get_tracker_list(my_status) # Do a full listing of the media directory for fullpath, filename in utils.regex_find_videos( 'mkv|mp4|avi', self.config['searchdir']): show_id = None if not ignorecache and filename in library_cache.keys(): # If the filename was already seen before # use the cached information, if there's no information (None) # then it means it doesn't correspond to any show in the list # and can be safely skipped. if library_cache[filename]: show_id = library_cache[filename][0] show_ep = library_cache[filename][1] else: continue else: # If the filename has not been seen, extract # the information from the filename and do a fuzzy search # on the user's list. Cache the information. # If it fails, cache it as None. aie = extras.AnimeInfoExtractor.AnimeInfoExtractor(filename) (show_title, show_ep) = (aie.getName(), aie.getEpisode()) if show_title: show = utils.guess_show(show_title, tracker_list) if show: show_id = show['id'] library_cache[filename] = (show['id'], show_ep) else: library_cache[filename] = None else: library_cache[filename] = None # After we got our information, add it to our library if show_id: if show_id not in library.keys(): library[show_id] = {} library[show_id][show_ep] = fullpath self.msg.debug(self.name, "Time: %s" % (time.time() - t)) self.data_handler.library_save(library) self.data_handler.library_cache_save(library_cache) return library